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\SHA1Crypt;
 15: 
 16: /**
 17:  * SHA-1 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 SHA1CryptTest 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:             array ("password", '$sha1$40000$jtNX3nZ2$hBNaIXkt4wBI2o5rsi8KejSjNqIq'),
 36:             array ("password", '$sha1$19703$iVdJqfSE$v4qYKl1zqYThwpjJAoKX6UvlHq/a'),
 37:             array ("password", '$sha1$21773$uV7PTeux$I9oHnvwPZHMO0Nq6/WgyGV/tDJIH'),
 38:             array ("test", '$sha1$1$Wq3GL2Vp$C8U25GvfHS8qGHimExLaiSFlGkAe'),
 39:         );
 40: 
 41:         return $vectors;
 42:     }
 43: 
 44:     /**
 45:      * Provide invalid test vectors.
 46:      *
 47:      * @return array
 48:      */
 49:     public function invalidTestVectorProvider()
 50:     {
 51:         $vectors = array (
 52:             array ("", '*0', '*1'),
 53:             array ("", '*1', '*0'),
 54:         );
 55: 
 56:         return $vectors;
 57:     }
 58: 
 59:     /**
 60:      * Verify that the class produces correct results with valid test vectors.
 61:      *
 62:      * @test
 63:      * @dataProvider validTestVectorProvider
 64:      * @param string $password
 65:      * @param string $hash
 66:      */
 67:     public function validTestVectorsProduceExpectedResults($password, $hash)
 68:     {
 69:         $this->assertEquals($hash, SHA1Crypt::hash($password, $hash));
 70:         $this->assertTrue(SHA1Crypt::verify($password, $hash));
 71:     }
 72: 
 73:     /**
 74:      * Verify that the class produces correct results with invalid test vectors.
 75:      *
 76:      * @test
 77:      * @dataProvider invalidTestVectorProvider
 78:      * @param string $password
 79:      * @param string $hash
 80:      */
 81:     public function invalidTestVectorsProduceExpectedResults($password, $hash, $errorString)
 82:     {
 83:         $this->assertEquals($errorString, SHA1Crypt::hash($password, $hash));
 84:         $this->assertFalse(SHA1Crypt::verify($password, $hash));
 85:     }
 86: 
 87:     /**
 88:      * @test
 89:      */
 90:     public function genconfigAndParseconfigProduceMatchingResults()
 91:     {
 92:         $options = array (
 93:             'rounds' => 5000,
 94:             'salt' => 'CCCCCCC.',
 95:         );
 96:         $config = SHA1Crypt::genConfig($options);
 97: 
 98:         $this->assertEquals('$sha1$5000$CCCCCCC.', $config);
 99:         $this->assertSame($options, SHA1Crypt::parseConfig($config));
100:     }
101: 
102: }
103: 
PHP Password Library API documentation generated by ApiGen 2.8.0