ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilBcryptPhpPasswordEncoderTest Class Reference
+ Inheritance diagram for ilBcryptPhpPasswordEncoderTest:
+ Collaboration diagram for ilBcryptPhpPasswordEncoderTest:

Public Member Functions

 costsProvider ()
 
 testInstanceCanBeCreated ()
 
 testCostsCanBeRetrievedWhenCostsAreSet (ilBcryptPhpPasswordEncoder $encoder)
 @depends testInstanceCanBeCreated More...
 
 testCostsCannotBeSetAboveRange (ilBcryptPhpPasswordEncoder $encoder)
 @depends testInstanceCanBeCreated @expectedException ilPasswordException More...
 
 testCostsCannotBeSetBelowRange (ilBcryptPhpPasswordEncoder $encoder)
 @depends testInstanceCanBeCreated @expectedException ilPasswordException More...
 
 testCostsCanBeSetInRange ($costs, ilBcryptPhpPasswordEncoder $encoder)
 @depends testInstanceCanBeCreated @dataProvider costsProvider More...
 
 testPasswordShouldBeCorrectlyEncodedAndVerified (ilBcryptPhpPasswordEncoder $encoder)
 @depends testInstanceCanBeCreated More...
 
 testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding (ilBcryptPhpPasswordEncoder $encoder)
 @depends testInstanceCanBeCreated @expectedException ilPasswordException More...
 
 testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength (ilBcryptPhpPasswordEncoder $encoder)
 @depends testInstanceCanBeCreated More...
 
 testNameShouldBeBcryptPhp (ilBcryptPhpPasswordEncoder $encoder)
 @depends testInstanceCanBeCreated More...
 
 testCostsCanBeDeterminedDynamically (ilBcryptPhpPasswordEncoder $encoder)
 @depends testInstanceCanBeCreated More...
 
 testEncoderDoesNotRelyOnSalts (ilBcryptPhpPasswordEncoder $encoder)
 @depends testInstanceCanBeCreated More...
 
 testReencodingIsDetectedWhenNecessary (ilBcryptPhpPasswordEncoder $encoder)
 @depends testInstanceCanBeCreated More...
 

Data Fields

const VALID_COSTS = '08'
 
const PASSWORD = 'password'
 
const WRONG_PASSWORD = 'wrong_password'
 

Protected Member Functions

 setUp ()
 Setup. More...
 
- Protected Member Functions inherited from ilPasswordBaseTest
 assertException ($exception_class)
 

Private Member Functions

 skipIfPhpVersionIsNotSupported ()
 

Detailed Description

Definition at line 12 of file ilBcryptPhpPasswordEncoderTest.php.

Member Function Documentation

◆ costsProvider()

ilBcryptPhpPasswordEncoderTest::costsProvider ( )
Returns
array

Definition at line 50 of file ilBcryptPhpPasswordEncoderTest.php.

51 {
52 $data = array();
53 for($i = 4; $i <= 31; $i++)
54 {
55 $data[] = array($i);
56 }
57 return $data;
58 }

References $data.

◆ setUp()

ilBcryptPhpPasswordEncoderTest::setUp ( )
protected

Setup.

Definition at line 32 of file ilBcryptPhpPasswordEncoderTest.php.

33 {
34 }

◆ skipIfPhpVersionIsNotSupported()

ilBcryptPhpPasswordEncoderTest::skipIfPhpVersionIsNotSupported ( )
private

Definition at line 39 of file ilBcryptPhpPasswordEncoderTest.php.

40 {
41 if(version_compare(phpversion(), '5.5.0', '<'))
42 {
43 $this->markTestSkipped('Requires PHP >= 5.5.0');
44 }
45 }

Referenced by testInstanceCanBeCreated().

+ Here is the caller graph for this function:

◆ testCostsCanBeDeterminedDynamically()

ilBcryptPhpPasswordEncoderTest::testCostsCanBeDeterminedDynamically ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Definition at line 159 of file ilBcryptPhpPasswordEncoderTest.php.

160 {
161 $costs_default = $encoder->benchmarkCost();
162 $costs_target = $encoder->benchmarkCost(0.5);
163
164 $this->assertTrue($costs_default > 4 && $costs_default < 32);
165 $this->assertTrue($costs_target > 4 && $costs_target < 32);
166 $this->assertInternalType('int', $costs_default);
167 $this->assertInternalType('int', $costs_target);
168 $this->assertNotEquals($costs_default, $costs_target);
169 }

References ilBcryptPhpPasswordEncoder\benchmarkCost().

+ Here is the call graph for this function:

◆ testCostsCanBeRetrievedWhenCostsAreSet()

ilBcryptPhpPasswordEncoderTest::testCostsCanBeRetrievedWhenCostsAreSet ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Definition at line 81 of file ilBcryptPhpPasswordEncoderTest.php.

82 {
83 $encoder->setCosts(4);
84 $this->assertEquals(4, $encoder->getCosts());
85 }

References ilBcryptPhpPasswordEncoder\getCosts(), and ilBcryptPhpPasswordEncoder\setCosts().

+ Here is the call graph for this function:

◆ testCostsCanBeSetInRange()

ilBcryptPhpPasswordEncoderTest::testCostsCanBeSetInRange (   $costs,
ilBcryptPhpPasswordEncoder  $encoder 
)

@depends testInstanceCanBeCreated @dataProvider costsProvider

Definition at line 111 of file ilBcryptPhpPasswordEncoderTest.php.

112 {
113 $encoder->setCosts($costs);
114 }

References ilBcryptPhpPasswordEncoder\setCosts().

+ Here is the call graph for this function:

◆ testCostsCannotBeSetAboveRange()

ilBcryptPhpPasswordEncoderTest::testCostsCannotBeSetAboveRange ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated @expectedException ilPasswordException

Definition at line 91 of file ilBcryptPhpPasswordEncoderTest.php.

92 {
93 $this->assertException(ilPasswordException::class);
94 $encoder->setCosts(32);
95 }
assertException($exception_class)

References ilPasswordBaseTest\assertException(), and ilBcryptPhpPasswordEncoder\setCosts().

+ Here is the call graph for this function:

◆ testCostsCannotBeSetBelowRange()

ilBcryptPhpPasswordEncoderTest::testCostsCannotBeSetBelowRange ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated @expectedException ilPasswordException

Definition at line 101 of file ilBcryptPhpPasswordEncoderTest.php.

102 {
103 $this->assertException(ilPasswordException::class);
104 $encoder->setCosts(3);
105 }

References ilPasswordBaseTest\assertException(), and ilBcryptPhpPasswordEncoder\setCosts().

+ Here is the call graph for this function:

◆ testEncoderDoesNotRelyOnSalts()

ilBcryptPhpPasswordEncoderTest::testEncoderDoesNotRelyOnSalts ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Definition at line 174 of file ilBcryptPhpPasswordEncoderTest.php.

175 {
176 $this->assertFalse($encoder->requiresSalt());
177 }
requiresSalt()
{Returns whether or not the encoder requires a salt.boolean}

References ilBasePasswordEncoder\requiresSalt().

+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding()

ilBcryptPhpPasswordEncoderTest::testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated @expectedException ilPasswordException

Definition at line 132 of file ilBcryptPhpPasswordEncoderTest.php.

133 {
134 $this->assertException(ilPasswordException::class);
135 $encoder->setCosts(self::VALID_COSTS);
136 $encoder->encodePassword(str_repeat('a', 5000), '');
137 }
encodePassword($raw, $salt)
{Encodes the raw password.string The encoded password}

References ilPasswordBaseTest\assertException(), ilBcryptPhpPasswordEncoder\encodePassword(), and ilBcryptPhpPasswordEncoder\setCosts().

+ Here is the call graph for this function:

◆ testInstanceCanBeCreated()

ilBcryptPhpPasswordEncoderTest::testInstanceCanBeCreated ( )
Returns
ilBcryptPhpPasswordEncoder

Definition at line 63 of file ilBcryptPhpPasswordEncoderTest.php.

64 {
66
67 $default_costs_encoder = new ilBcryptPhpPasswordEncoder();
68 $this->assertTrue((int)$default_costs_encoder->getCosts() > 4 && (int)$default_costs_encoder->getCosts() < 32);
69
70 $encoder = new ilBcryptPhpPasswordEncoder(array(
71 'cost' => self::VALID_COSTS
72 ));
73 $this->assertInstanceOf('ilBcryptPhpPasswordEncoder', $encoder);
74 $this->assertEquals(self::VALID_COSTS, $encoder->getCosts());
75 return $encoder;
76 }

References skipIfPhpVersionIsNotSupported().

+ Here is the call graph for this function:

◆ testNameShouldBeBcryptPhp()

ilBcryptPhpPasswordEncoderTest::testNameShouldBeBcryptPhp ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Definition at line 151 of file ilBcryptPhpPasswordEncoderTest.php.

152 {
153 $this->assertEquals('bcryptphp', $encoder->getName());
154 }

References ilBcryptPhpPasswordEncoder\getName().

+ Here is the call graph for this function:

◆ testPasswordShouldBeCorrectlyEncodedAndVerified()

ilBcryptPhpPasswordEncoderTest::testPasswordShouldBeCorrectlyEncodedAndVerified ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Definition at line 119 of file ilBcryptPhpPasswordEncoderTest.php.

120 {
121 $encoder->setCosts(self::VALID_COSTS);
122 $encoded_password = $encoder->encodePassword(self::PASSWORD, '');
123 $this->assertTrue($encoder->isPasswordValid($encoded_password, self::PASSWORD, ''));
124 $this->assertFalse($encoder->isPasswordValid($encoded_password, self::WRONG_PASSWORD, ''));
125 return $encoder;
126 }
isPasswordValid($encoded, $raw, $salt)
{Checks a raw password against an encoded password.The raw password has to be injected into the encod...

References ilBcryptPhpPasswordEncoder\encodePassword(), ilBcryptPhpPasswordEncoder\isPasswordValid(), and ilBcryptPhpPasswordEncoder\setCosts().

+ Here is the call graph for this function:

◆ testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength()

ilBcryptPhpPasswordEncoderTest::testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Definition at line 142 of file ilBcryptPhpPasswordEncoderTest.php.

143 {
144 $encoder->setCosts(self::VALID_COSTS);
145 $this->assertFalse($encoder->isPasswordValid('encoded', str_repeat('a', 5000), ''));
146 }

References ilBcryptPhpPasswordEncoder\isPasswordValid(), and ilBcryptPhpPasswordEncoder\setCosts().

+ Here is the call graph for this function:

◆ testReencodingIsDetectedWhenNecessary()

ilBcryptPhpPasswordEncoderTest::testReencodingIsDetectedWhenNecessary ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Definition at line 182 of file ilBcryptPhpPasswordEncoderTest.php.

183 {
184 $raw = self::PASSWORD;
185
186 $encoder->setCosts(8);
187 $encoded = $encoder->encodePassword($raw, '');
188 $encoder->setCosts(8);
189 $this->assertFalse($encoder->requiresReencoding($encoded));
190
191 $encoder->setCosts(9);
192 $this->assertTrue($encoder->requiresReencoding($encoded));
193 }
requiresReencoding($encoded)
{{Returns whether or not the a encoded password needs to be re-encoded.boolean}}

References ilBcryptPhpPasswordEncoder\encodePassword(), PASSWORD, ilBcryptPhpPasswordEncoder\requiresReencoding(), and ilBcryptPhpPasswordEncoder\setCosts().

+ Here is the call graph for this function:

Field Documentation

◆ PASSWORD

const ilBcryptPhpPasswordEncoderTest::PASSWORD = 'password'

◆ VALID_COSTS

const ilBcryptPhpPasswordEncoderTest::VALID_COSTS = '08'

Definition at line 17 of file ilBcryptPhpPasswordEncoderTest.php.

◆ WRONG_PASSWORD

const ilBcryptPhpPasswordEncoderTest::WRONG_PASSWORD = 'wrong_password'

Definition at line 27 of file ilBcryptPhpPasswordEncoderTest.php.


The documentation for this class was generated from the following file: