ILIAS  release_8 Revision v8.24
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...
 

Private Attributes

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

Detailed Description

Definition at line 26 of file ilBcryptPhpPasswordEncoderTest.php.

Member Function Documentation

◆ costsProvider()

ilBcryptPhpPasswordEncoderTest::costsProvider ( )
Returns
array<string, string[]>

Definition at line 40 of file ilBcryptPhpPasswordEncoderTest.php.

40 : array
41 {
42 $data = [];
43 for ($i = 4; $i <= 31; ++$i) {
44 $data[sprintf('Costs: %s', $i)] = [(string) $i];
45 }
46
47 return $data;
48 }
$i
Definition: metadata.php:41

References $data, and $i.

◆ testCostsCanBeDeterminedDynamically()

ilBcryptPhpPasswordEncoderTest::testCostsCanBeDeterminedDynamically ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Exceptions
ilPasswordException

Definition at line 157 of file ilBcryptPhpPasswordEncoderTest.php.

157 : void
158 {
159 $costs_default = $encoder->benchmarkCost();
160 $costs_target = $encoder->benchmarkCost(0.5);
161
162 $this->assertTrue($costs_default > 4 && $costs_default < 32);
163 $this->assertTrue($costs_target > 4 && $costs_target < 32);
164 $this->assertIsInt($costs_default);
165 $this->assertIsInt($costs_target);
166 $this->assertNotEquals($costs_default, $costs_target);
167 }

References ilBcryptPhpPasswordEncoder\benchmarkCost().

+ Here is the call graph for this function:

◆ testCostsCanBeRetrievedWhenCostsAreSet()

ilBcryptPhpPasswordEncoderTest::testCostsCanBeRetrievedWhenCostsAreSet ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Exceptions
ilPasswordException

Definition at line 68 of file ilBcryptPhpPasswordEncoderTest.php.

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

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

Exceptions
ilPasswordException

Definition at line 102 of file ilBcryptPhpPasswordEncoderTest.php.

102 : void
103 {
104 $encoder->setCosts($costs);
105 }

References ilBcryptPhpPasswordEncoder\setCosts().

+ Here is the call graph for this function:

◆ testCostsCannotBeSetAboveRange()

ilBcryptPhpPasswordEncoderTest::testCostsCannotBeSetAboveRange ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Exceptions
ilPasswordException

Definition at line 80 of file ilBcryptPhpPasswordEncoderTest.php.

80 : void
81 {
82 $this->expectException(ilPasswordException::class);
83 $encoder->setCosts('32');
84 }

References ilBcryptPhpPasswordEncoder\setCosts().

+ Here is the call graph for this function:

◆ testCostsCannotBeSetBelowRange()

ilBcryptPhpPasswordEncoderTest::testCostsCannotBeSetBelowRange ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Exceptions
ilPasswordException

Definition at line 90 of file ilBcryptPhpPasswordEncoderTest.php.

90 : void
91 {
92 $this->expectException(ilPasswordException::class);
93 $encoder->setCosts('3');
94 }

References ilBcryptPhpPasswordEncoder\setCosts().

+ Here is the call graph for this function:

◆ testEncoderDoesNotRelyOnSalts()

ilBcryptPhpPasswordEncoderTest::testEncoderDoesNotRelyOnSalts ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Definition at line 172 of file ilBcryptPhpPasswordEncoderTest.php.

172 : void
173 {
174 $this->assertFalse($encoder->requiresSalt());
175 }
requiresSalt()
Returns whether the encoder requires a salt.

References ilBasePasswordEncoder\requiresSalt().

+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding()

ilBcryptPhpPasswordEncoderTest::testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Exceptions
ilPasswordException

Definition at line 126 of file ilBcryptPhpPasswordEncoderTest.php.

128 : void {
129 $this->expectException(ilPasswordException::class);
130 $encoder->setCosts(self::VALID_COSTS);
131 $encoder->encodePassword(str_repeat('a', 5000), '');
132 }
encodePassword(string $raw, string $salt)
Encodes the raw password.

◆ testInstanceCanBeCreated()

ilBcryptPhpPasswordEncoderTest::testInstanceCanBeCreated ( )

Definition at line 50 of file ilBcryptPhpPasswordEncoderTest.php.

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

◆ testNameShouldBeBcryptPhp()

ilBcryptPhpPasswordEncoderTest::testNameShouldBeBcryptPhp ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Definition at line 148 of file ilBcryptPhpPasswordEncoderTest.php.

148 : void
149 {
150 $this->assertSame('bcryptphp', $encoder->getName());
151 }
getName()
Returns a unique name/id of the concrete password encoder.

References ilBcryptPhpPasswordEncoder\getName().

+ Here is the call graph for this function:

◆ testPasswordShouldBeCorrectlyEncodedAndVerified()

ilBcryptPhpPasswordEncoderTest::testPasswordShouldBeCorrectlyEncodedAndVerified ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Exceptions
ilPasswordException

Definition at line 111 of file ilBcryptPhpPasswordEncoderTest.php.

114 $encoder->setCosts(self::VALID_COSTS);
115 $encoded_password = $encoder->encodePassword(self::PASSWORD, '');
116 $this->assertTrue($encoder->isPasswordValid($encoded_password, self::PASSWORD, ''));
117 $this->assertFalse($encoder->isPasswordValid($encoded_password, self::WRONG_PASSWORD, ''));
118
119 return $encoder;
120 }
isPasswordValid(string $encoded, string $raw, string $salt)
Checks a raw password against an encoded password.

◆ testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength()

ilBcryptPhpPasswordEncoderTest::testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Exceptions
ilPasswordException

Definition at line 138 of file ilBcryptPhpPasswordEncoderTest.php.

140 : void {
141 $encoder->setCosts(self::VALID_COSTS);
142 $this->assertFalse($encoder->isPasswordValid('encoded', str_repeat('a', 5000), ''));
143 }

◆ testReencodingIsDetectedWhenNecessary()

ilBcryptPhpPasswordEncoderTest::testReencodingIsDetectedWhenNecessary ( ilBcryptPhpPasswordEncoder  $encoder)

@depends testInstanceCanBeCreated

Exceptions
ilPasswordException

Definition at line 181 of file ilBcryptPhpPasswordEncoderTest.php.

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

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

+ Here is the call graph for this function:

Field Documentation

◆ PASSWORD

const ilBcryptPhpPasswordEncoderTest::PASSWORD = 'password'
private

Definition at line 32 of file ilBcryptPhpPasswordEncoderTest.php.

◆ VALID_COSTS

const ilBcryptPhpPasswordEncoderTest::VALID_COSTS = '08'
private

Definition at line 29 of file ilBcryptPhpPasswordEncoderTest.php.

◆ WRONG_PASSWORD

const ilBcryptPhpPasswordEncoderTest::WRONG_PASSWORD = 'wrong_password'
private

Definition at line 35 of file ilBcryptPhpPasswordEncoderTest.php.


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