ILIAS  release_7 Revision v7.30-3-g800a261c036
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 More...
 
 testCostsCannotBeSetBelowRange (ilBcryptPhpPasswordEncoder $encoder)
 @depends testInstanceCanBeCreated More...
 
 testCostsCanBeSetInRange (string $costs, ilBcryptPhpPasswordEncoder $encoder)
 @depends testInstanceCanBeCreated @dataProvider costsProvider @doesNotPerformAssertions More...
 
 testPasswordShouldBeCorrectlyEncodedAndVerified (ilBcryptPhpPasswordEncoder $encoder)
 @depends testInstanceCanBeCreated More...
 
 testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding (ilBcryptPhpPasswordEncoder $encoder)
 @depends testInstanceCanBeCreated 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'
 

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 36 of file ilBcryptPhpPasswordEncoderTest.php.

36 : array
37 {
38 $data = [];
39 for ($i = 4; $i <= 31; $i++) {
40 $data[sprintf("Costs: %s", (string) $i)] = [(string) $i];
41 }
42
43 return $data;
44 }
$i
Definition: metadata.php:24
$data
Definition: storeScorm.php:23

References $data, and $i.

◆ skipIfPhpVersionIsNotSupported()

ilBcryptPhpPasswordEncoderTest::skipIfPhpVersionIsNotSupported ( )
private

Definition at line 26 of file ilBcryptPhpPasswordEncoderTest.php.

26 : void
27 {
28 if (version_compare(phpversion(), '5.5.0', '<')) {
29 $this->markTestSkipped('Requires PHP >= 5.5.0');
30 }
31 }

Referenced by testInstanceCanBeCreated().

+ Here is the caller graph for this function:

◆ testCostsCanBeDeterminedDynamically()

ilBcryptPhpPasswordEncoderTest::testCostsCanBeDeterminedDynamically ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Parameters
ilBcryptPhpPasswordEncoder$encoder
Exceptions
ilPasswordException

Definition at line 168 of file ilBcryptPhpPasswordEncoderTest.php.

168 : void
169 {
170 $costs_default = $encoder->benchmarkCost();
171 $costs_target = $encoder->benchmarkCost(0.5);
172
173 $this->assertTrue($costs_default > 4 && $costs_default < 32);
174 $this->assertTrue($costs_target > 4 && $costs_target < 32);
175 $this->assertIsInt($costs_default);
176 $this->assertIsInt($costs_target);
177 $this->assertNotEquals($costs_default, $costs_target);
178 }

References ilBcryptPhpPasswordEncoder\benchmarkCost().

+ Here is the call graph for this function:

◆ testCostsCanBeRetrievedWhenCostsAreSet()

ilBcryptPhpPasswordEncoderTest::testCostsCanBeRetrievedWhenCostsAreSet ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Parameters
ilBcryptPhpPasswordEncoder$encoder
Exceptions
ilPasswordException

Definition at line 70 of file ilBcryptPhpPasswordEncoderTest.php.

70 : void
71 {
72 $expected = '04';
73
74 $encoder->setCosts($expected);
75 $this->assertEquals($expected, $encoder->getCosts());
76 }

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

+ Here is the call graph for this function:

◆ testCostsCanBeSetInRange()

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

@depends testInstanceCanBeCreated @dataProvider costsProvider @doesNotPerformAssertions

Parameters
string$costs
ilBcryptPhpPasswordEncoder$encoder
Exceptions
ilPasswordException

Definition at line 108 of file ilBcryptPhpPasswordEncoderTest.php.

108 : void
109 {
110 $encoder->setCosts($costs);
111 }

References ilBcryptPhpPasswordEncoder\setCosts().

+ Here is the call graph for this function:

◆ testCostsCannotBeSetAboveRange()

ilBcryptPhpPasswordEncoderTest::testCostsCannotBeSetAboveRange ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Parameters
ilBcryptPhpPasswordEncoder$encoder
Exceptions
ilPasswordException

Definition at line 83 of file ilBcryptPhpPasswordEncoderTest.php.

83 : void
84 {
85 $this->expectException(ilPasswordException::class);
86 $encoder->setCosts('32');
87 }

References ilBcryptPhpPasswordEncoder\setCosts().

+ Here is the call graph for this function:

◆ testCostsCannotBeSetBelowRange()

ilBcryptPhpPasswordEncoderTest::testCostsCannotBeSetBelowRange ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Parameters
ilBcryptPhpPasswordEncoder$encoder
Exceptions
ilPasswordException

Definition at line 94 of file ilBcryptPhpPasswordEncoderTest.php.

94 : void
95 {
96 $this->expectException(ilPasswordException::class);
97 $encoder->setCosts('3');
98 }

References ilBcryptPhpPasswordEncoder\setCosts().

+ Here is the call graph for this function:

◆ testEncoderDoesNotRelyOnSalts()

ilBcryptPhpPasswordEncoderTest::testEncoderDoesNotRelyOnSalts ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Parameters
ilBcryptPhpPasswordEncoder$encoder

Definition at line 184 of file ilBcryptPhpPasswordEncoderTest.php.

184 : void
185 {
186 $this->assertFalse($encoder->requiresSalt());
187 }

References ilBasePasswordEncoder\requiresSalt().

+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding()

ilBcryptPhpPasswordEncoderTest::testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Parameters
ilBcryptPhpPasswordEncoder$encoder
Exceptions
ilPasswordException

Definition at line 134 of file ilBcryptPhpPasswordEncoderTest.php.

136 : void {
137 $this->expectException(ilPasswordException::class);
138 $encoder->setCosts(self::VALID_COSTS);
139 $encoder->encodePassword(str_repeat('a', 5000), '');
140 }
encodePassword(string $raw, string $salt)
@inheritDoc

◆ testInstanceCanBeCreated()

ilBcryptPhpPasswordEncoderTest::testInstanceCanBeCreated ( )
Returns
ilBcryptPhpPasswordEncoder
Exceptions
ilPasswordException

Definition at line 50 of file ilBcryptPhpPasswordEncoderTest.php.

51 {
53
54 $default_costs_encoder = new ilBcryptPhpPasswordEncoder();
55 $this->assertTrue((int) $default_costs_encoder->getCosts() > 4 && (int) $default_costs_encoder->getCosts() < 32);
56
57 $encoder = new ilBcryptPhpPasswordEncoder([
58 'cost' => self::VALID_COSTS
59 ]);
60 $this->assertInstanceOf('ilBcryptPhpPasswordEncoder', $encoder);
61 $this->assertEquals(self::VALID_COSTS, $encoder->getCosts());
62 return $encoder;
63 }

References skipIfPhpVersionIsNotSupported().

+ Here is the call graph for this function:

◆ testNameShouldBeBcryptPhp()

ilBcryptPhpPasswordEncoderTest::testNameShouldBeBcryptPhp ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Parameters
ilBcryptPhpPasswordEncoder$encoder

Definition at line 158 of file ilBcryptPhpPasswordEncoderTest.php.

158 : void
159 {
160 $this->assertEquals('bcryptphp', $encoder->getName());
161 }

References ilBcryptPhpPasswordEncoder\getName().

+ Here is the call graph for this function:

◆ testPasswordShouldBeCorrectlyEncodedAndVerified()

ilBcryptPhpPasswordEncoderTest::testPasswordShouldBeCorrectlyEncodedAndVerified ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Parameters
ilBcryptPhpPasswordEncoder$encoder
Returns
ilBcryptPhpPasswordEncoder
Exceptions
ilPasswordException

Definition at line 119 of file ilBcryptPhpPasswordEncoderTest.php.

122 $encoder->setCosts(self::VALID_COSTS);
123 $encoded_password = $encoder->encodePassword(self::PASSWORD, '');
124 $this->assertTrue($encoder->isPasswordValid($encoded_password, self::PASSWORD, ''));
125 $this->assertFalse($encoder->isPasswordValid($encoded_password, self::WRONG_PASSWORD, ''));
126 return $encoder;
127 }
isPasswordValid(string $encoded, string $raw, string $salt)
@inheritDoc

◆ testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength()

ilBcryptPhpPasswordEncoderTest::testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Parameters
ilBcryptPhpPasswordEncoder$encoder
Exceptions
ilPasswordException

Definition at line 147 of file ilBcryptPhpPasswordEncoderTest.php.

149 : void {
150 $encoder->setCosts(self::VALID_COSTS);
151 $this->assertFalse($encoder->isPasswordValid('encoded', str_repeat('a', 5000), ''));
152 }

◆ testReencodingIsDetectedWhenNecessary()

ilBcryptPhpPasswordEncoderTest::testReencodingIsDetectedWhenNecessary ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Parameters
ilBcryptPhpPasswordEncoder$encoder
Exceptions
ilPasswordException

Definition at line 194 of file ilBcryptPhpPasswordEncoderTest.php.

194 : void
195 {
196 $raw = self::PASSWORD;
197
198 $encoder->setCosts('8');
199 $encoded = $encoder->encodePassword($raw, '');
200 $encoder->setCosts('8');
201 $this->assertFalse($encoder->requiresReencoding($encoded));
202
203 $encoder->setCosts('9');
204 $this->assertTrue($encoder->requiresReencoding($encoded));
205 }
requiresReencoding(string $encoded)
@inheritDoc

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

+ Here is the call graph for this function:

Field Documentation

◆ PASSWORD

const ilBcryptPhpPasswordEncoderTest::PASSWORD = 'password'

Definition at line 18 of file ilBcryptPhpPasswordEncoderTest.php.

◆ VALID_COSTS

const ilBcryptPhpPasswordEncoderTest::VALID_COSTS = '08'

Definition at line 15 of file ilBcryptPhpPasswordEncoderTest.php.

◆ WRONG_PASSWORD

const ilBcryptPhpPasswordEncoderTest::WRONG_PASSWORD = 'wrong_password'

Definition at line 21 of file ilBcryptPhpPasswordEncoderTest.php.


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