Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/infrastructure/util/__tests__/PhabricatorHMACTestCase.php
12242 views
1
<?php
2
3
final class PhabricatorHMACTestCase extends PhabricatorTestCase {
4
5
protected function getPhabricatorTestCaseConfiguration() {
6
return array(
7
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
8
);
9
}
10
11
public function testHMACKeyGeneration() {
12
$input = 'quack';
13
14
$hash_1 = PhabricatorHash::digestWithNamedKey($input, 'test');
15
$hash_2 = PhabricatorHash::digestWithNamedKey($input, 'test');
16
17
$this->assertEqual($hash_1, $hash_2);
18
}
19
20
public function testSHA256Hashing() {
21
$input = 'quack';
22
$key = 'duck';
23
$expect =
24
'5274473dc34fc61bd7a6a5ff258e6505'.
25
'4b26644fb7a272d74f276ab677361b9a';
26
27
$hash = PhabricatorHash::digestHMACSHA256($input, $key);
28
$this->assertEqual($expect, $hash);
29
30
$input = 'The quick brown fox jumps over the lazy dog';
31
$key = 'key';
32
$expect =
33
'f7bc83f430538424b13298e6aa6fb143'.
34
'ef4d59a14946175997479dbc2d1a3cd8';
35
36
$hash = PhabricatorHash::digestHMACSHA256($input, $key);
37
$this->assertEqual($expect, $hash);
38
}
39
40
}
41
42