1<?php 2 3require_once DOKU_INC.'inc/init.php'; 4require_once DOKU_INC.'inc/auth.php'; 5 6class auth_password_test extends PHPUnit_Framework_TestCase { 7 8 // hashes for the password foo$method, using abcdefgh as salt 9 var $passes = array( 10 'smd5' => '$1$abcdefgh$SYbjm2AEvSoHG7Xapi8so.', 11 'apr1' => '$apr1$abcdefgh$C/GzYTF4kOVByYLEoD5X4.', 12 'md5' => '8fa22d62408e5351553acdd91c6b7003', 13 'sha1' => 'b456d3b0efd105d613744ffd549514ecafcfc7e1', 14 'ssha' => '{SSHA}QMHG+uC7bHNYKkmoLbNsNI38/dJhYmNk', 15 'lsmd5' => '{SMD5}HGbkPrkWgy9KgcRGWlrsUWFiY2RlZmdo', 16 'crypt' => 'ablvoGr1hvZ5k', 17 'mysql' => '4a1fa3780bd6fd55', 18 'my411' => '*e5929347e25f82e19e4ebe92f1dc6b6e7c2dbd29', 19 'kmd5' => 'a579299436d7969791189acadd86fcb716', 20 'djangomd5' => 'md5$abcde$d0fdddeda8cd92725d2b54148ac09158', 21 'djangosha1' => 'sha1$abcde$c8e65a7f0acc9158843048a53dcc5a6bc4d17678', 22 ); 23 24 25 function test_cryptPassword(){ 26 foreach($this->passes as $method => $hash){ 27 $info = "testing method $method"; 28 $this->assertEquals(auth_cryptPassword('foo'.$method, $method,'abcdefgh12345678912345678912345678'), 29 $hash, $info); 30 } 31 } 32 33 function test_verifyPassword(){ 34 foreach($this->passes as $method => $hash){ 35 $info = "testing method $method"; 36 $this->assertTrue(auth_verifyPassword('foo'.$method, $hash), $info); 37 $this->assertFalse(auth_verifyPassword('bar'.$method, $hash), $info); 38 } 39 } 40 41 function test_verifySelf(){ 42 foreach($this->passes as $method => $hash){ 43 $info = "testing method $method"; 44 $hash = auth_cryptPassword('foo'.$method,$method); 45 $this->assertTrue(auth_verifyPassword('foo'.$method, $hash), $info); 46 } 47 } 48 49 function test_bcrypt_self(){ 50 $hash = auth_cryptPassword('foobcrypt','bcrypt'); 51 $this->assertTrue(auth_verifyPassword('foobcrypt',$hash)); 52 } 53 54 function test_verifyPassword_fixedbcrypt(){ 55 $this->assertTrue(auth_verifyPassword('foobcrypt','$2a$12$uTWercxbq4sjp2xAzv3we.ZOxk51m5V/Bv5bp2H27oVFJl5neFQoC')); 56 } 57 58 function test_verifyPassword_nohash(){ 59 $this->assertTrue(auth_verifyPassword('foo','$1$$n1rTiFE0nRifwV/43bVon/')); 60 } 61 62 function test_verifyPassword_fixedpmd5(){ 63 $this->assertTrue(auth_verifyPassword('test12345','$P$9IQRaTwmfeRo7ud9Fh4E2PdI0S3r.L0')); 64 $this->assertTrue(auth_verifyPassword('test12345','$H$9IQRaTwmfeRo7ud9Fh4E2PdI0S3r.L0')); 65 } 66 67 /** 68 * pmd5 checking should throw an exception when a hash with a too high 69 * iteration count is passed 70 */ 71 function test_verifyPassword_pmd5Exception(){ 72 $except = false; 73 try{ 74 auth_verifyPassword('foopmd5', '$H$abcdefgh1ZbJodHxmeXVAhEzTG7IAp.'); 75 }catch (Exception $e){ 76 $except = true; 77 } 78 $this->assertTrue($except); 79 } 80 81} 82 83//Setup VIM: ex: et ts=4 : 84