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