Merge "Do not split parser cache if limitation is reached."
[lhc/web/wiklou.git] / tests / phpunit / includes / utils / MWCryptHashTest.php
1 <?php
2 /**
3 *
4 * @group Hash
5 */
6
7 class MWCryptHashTest extends MediaWikiTestCase {
8
9 public function testHashLength() {
10 if ( MWCryptHash::hashAlgo() !== 'whirlpool' ) {
11 $this->markTestSkipped( 'Hash algorithm isn\'t whirlpool' );
12 }
13
14 $this->assertEquals( 64, MWCryptHash::hashLength(), 'Raw hash length' );
15 $this->assertEquals( 128, MWCryptHash::hashLength( false ), 'Hex hash length' );
16 }
17
18 public function testHash() {
19 if ( MWCryptHash::hashAlgo() !== 'whirlpool' ) {
20 $this->markTestSkipped( 'Hash algorithm isn\'t whirlpool' );
21 }
22
23 $data = 'foobar';
24 $hash = '9923afaec3a86f865bb231a588f453f84e8151a2deb4109aebc6de4284be5bebcff4fab82a7e51d920237340a043736e9d13bab196006dcca0fe65314d68eab9';
25
26 $this->assertEquals(
27 pack( 'H*', $hash ),
28 MWCryptHash::hash( $data ),
29 'Raw hash'
30 );
31 $this->assertEquals(
32 $hash,
33 MWCryptHash::hash( $data, false ),
34 'Hex hash'
35 );
36 }
37
38 public function testHmac() {
39 if ( MWCryptHash::hashAlgo() !== 'whirlpool' ) {
40 $this->markTestSkipped( 'Hash algorithm isn\'t whirlpool' );
41 }
42
43 $data = 'foobar';
44 $key = 'secret';
45 $hash = 'ddc94177b2020e55ce2049199fd9cc6327f416ff6dc621cc34cb43d9bec61d73372b4790c0e24957f565ecaf2d42821e6303619093e99cbe14a3b9250bda5f81';
46
47 $this->assertEquals(
48 pack( 'H*', $hash ),
49 MWCryptHash::hmac( $data, $key ),
50 'Raw hmac'
51 );
52 $this->assertEquals(
53 $hash,
54 MWCryptHash::hmac( $data, $key, false ),
55 'Hex hmac'
56 );
57 }
58
59 }