Merge "Added release notes for 'ContentHandler::runLegacyHooks' removal"
[mediawiki.git] / tests / phpunit / includes / utils / MWCryptHashTest.php
blob905d14ca09349ba51b9818d634ea48c068cd5266
1 <?php
2 /**
4 * @group Hash
5 */
7 class MWCryptHashTest extends PHPUnit_Framework_TestCase {
9 public function testHashLength() {
10 if ( MWCryptHash::hashAlgo() !== 'whirlpool' ) {
11 $this->markTestSkipped( 'Hash algorithm isn\'t whirlpool' );
14 $this->assertEquals( 64, MWCryptHash::hashLength(), 'Raw hash length' );
15 $this->assertEquals( 128, MWCryptHash::hashLength( false ), 'Hex hash length' );
18 public function testHash() {
19 if ( MWCryptHash::hashAlgo() !== 'whirlpool' ) {
20 $this->markTestSkipped( 'Hash algorithm isn\'t whirlpool' );
23 $data = 'foobar';
24 // @codingStandardsIgnoreStart Generic.Files.LineLength
25 $hash = '9923afaec3a86f865bb231a588f453f84e8151a2deb4109aebc6de4284be5bebcff4fab82a7e51d920237340a043736e9d13bab196006dcca0fe65314d68eab9';
26 // @codingStandardsIgnoreEnd
28 $this->assertEquals(
29 hex2bin( $hash ),
30 MWCryptHash::hash( $data ),
31 'Raw hash'
33 $this->assertEquals(
34 $hash,
35 MWCryptHash::hash( $data, false ),
36 'Hex hash'
40 public function testHmac() {
41 if ( MWCryptHash::hashAlgo() !== 'whirlpool' ) {
42 $this->markTestSkipped( 'Hash algorithm isn\'t whirlpool' );
45 $data = 'foobar';
46 $key = 'secret';
47 // @codingStandardsIgnoreStart Generic.Files.LineLength
48 $hash = 'ddc94177b2020e55ce2049199fd9cc6327f416ff6dc621cc34cb43d9bec61d73372b4790c0e24957f565ecaf2d42821e6303619093e99cbe14a3b9250bda5f81';
49 // @codingStandardsIgnoreEnd
51 $this->assertEquals(
52 hex2bin( $hash ),
53 MWCryptHash::hmac( $data, $key ),
54 'Raw hmac'
56 $this->assertEquals(
57 $hash,
58 MWCryptHash::hmac( $data, $key, false ),
59 'Hex hmac'