Path: blob/master/src/infrastructure/util/__tests__/PhabricatorHMACTestCase.php
12242 views
<?php12final class PhabricatorHMACTestCase extends PhabricatorTestCase {34protected function getPhabricatorTestCaseConfiguration() {5return array(6self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,7);8}910public function testHMACKeyGeneration() {11$input = 'quack';1213$hash_1 = PhabricatorHash::digestWithNamedKey($input, 'test');14$hash_2 = PhabricatorHash::digestWithNamedKey($input, 'test');1516$this->assertEqual($hash_1, $hash_2);17}1819public function testSHA256Hashing() {20$input = 'quack';21$key = 'duck';22$expect =23'5274473dc34fc61bd7a6a5ff258e6505'.24'4b26644fb7a272d74f276ab677361b9a';2526$hash = PhabricatorHash::digestHMACSHA256($input, $key);27$this->assertEqual($expect, $hash);2829$input = 'The quick brown fox jumps over the lazy dog';30$key = 'key';31$expect =32'f7bc83f430538424b13298e6aa6fb143'.33'ef4d59a14946175997479dbc2d1a3cd8';3435$hash = PhabricatorHash::digestHMACSHA256($input, $key);36$this->assertEqual($expect, $hash);37}3839}404142