Overview

Namespaces

  • PHP
  • PHPassLib
    • Application
    • Exception
    • Hash
    • Test
      • Application
      • Hash

Classes

  • BCryptTest
  • BSDiCryptTest
  • DESCryptTest
  • MD5CryptTest
  • PBKDF2Test
  • PortableTest
  • SHA1CryptTest
  • SHA256CryptTest
  • SHA512CryptTest
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * PHP Password Library
  4:  *
  5:  * @package PHPassLib\Tests
  6:  * @author Ryan Chouinard <rchouinard@gmail.com>
  7:  * @copyright Copyright (c) 2012, Ryan Chouinard
  8:  * @license MIT License - http://www.opensource.org/licenses/mit-license.php
  9:  * @version 3.0.0-dev
 10:  */
 11: 
 12: namespace PHPassLib\Test\Hash;
 13: 
 14: use PHPassLib\Hash\DESCrypt;
 15: 
 16: /**
 17:  * DES Crypt Module Tests
 18:  *
 19:  * @package PHPassLib\Tests
 20:  * @author Ryan Chouinard <rchouinard@gmail.com>
 21:  * @copyright Copyright (c) 2012, Ryan Chouinard
 22:  * @license MIT License - http://www.opensource.org/licenses/mit-license.php
 23:  */
 24: class DESCryptTest extends \PHPUnit_Framework_TestCase
 25: {
 26: 
 27:     /**
 28:      * Provide valid test vectors.
 29:      *
 30:      * @return array
 31:      */
 32:     public function validTestVectorProvider()
 33:     {
 34:         $vectors = array (
 35:             // From John the Ripper 1.7.9
 36:             array ("U*U*U*U*", 'CCNf8Sbh3HDfQ'),
 37:             array ("U*U***U", 'CCX.K.MFy4Ois'),
 38:             array ("U*U***U*", 'CC4rMpbg9AMZ.'),
 39:             array ("*U*U*U*U", 'XXxzOu6maQKqQ'),
 40:             array ("", 'SDbsugeBiC58A'),
 41:         );
 42: 
 43:         return $vectors;
 44:     }
 45: 
 46:     /**
 47:      * Provide invalid test vectors.
 48:      *
 49:      * @return array
 50:      */
 51:     public function invalidTestVectorProvider()
 52:     {
 53:         $vectors = array (
 54:             array ("", '!gAwTx2l6NADI', '*0'),
 55:             array ("", '*0', '*1'),
 56:             array ("", '*1', '*0'),
 57:         );
 58: 
 59:         return $vectors;
 60:     }
 61: 
 62:     /**
 63:      * Verify that the class produces correct results with valid test vectors.
 64:      *
 65:      * @test
 66:      * @dataProvider validTestVectorProvider
 67:      * @param string $password
 68:      * @param string $hash
 69:      */
 70:     public function validTestVectorsProduceExpectedResults($password, $hash)
 71:     {
 72:         $config = substr($hash, 0, 29);
 73:         $this->assertEquals($hash, DESCrypt::hash($password, $config));
 74:         $this->assertTrue(DESCrypt::verify($password, $hash));
 75:     }
 76: 
 77:     /**
 78:      * Verify that the class produces correct results with invalid test vectors.
 79:      *
 80:      * @test
 81:      * @dataProvider invalidTestVectorProvider
 82:      * @param string $password
 83:      * @param string $hash
 84:      */
 85:     public function invalidTestVectorsProduceExpectedResults($password, $hash, $errorString)
 86:     {
 87:         $config = substr($hash, 0, 29);
 88:         $this->assertEquals($errorString, DESCrypt::hash($password, $config));
 89:         $this->assertFalse(DESCrypt::verify($password, $hash));
 90:     }
 91: 
 92:     /**
 93:      * @test
 94:      */
 95:     public function genconfigAndParseconfigProduceMatchingResults()
 96:     {
 97:         $options = array (
 98:             'salt' => 'C.',
 99:         );
100:         $config = DESCrypt::genConfig($options);
101: 
102:         $this->assertEquals('C.', $config);
103:         $this->assertSame($options, DESCrypt::parseConfig($config));
104:     }
105: 
106: }
107: 
PHP Password Library API documentation generated by ApiGen 2.8.0