ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilBcryptPhpPasswordEncoderTest Class Reference
+ Inheritance diagram for ilBcryptPhpPasswordEncoderTest:
+ Collaboration diagram for ilBcryptPhpPasswordEncoderTest:

Public Member Functions

 testInstanceCanBeCreated ()
 
 testCostsCanBeRetrievedWhenCostsAreSet (ilBcryptPhpPasswordEncoder $encoder)
 
 testCostsCannotBeSetAboveRange (ilBcryptPhpPasswordEncoder $encoder)
 
 testCostsCannotBeSetBelowRange (ilBcryptPhpPasswordEncoder $encoder)
 
 testCostsCanBeSetInRange (string $costs, ilBcryptPhpPasswordEncoder $encoder)
 
 testPasswordShouldBeCorrectlyEncodedAndVerified (ilBcryptPhpPasswordEncoder $encoder)
 
 testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding (ilBcryptPhpPasswordEncoder $encoder)
 
 testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength (ilBcryptPhpPasswordEncoder $encoder)
 
 testNameShouldBeBcryptPhp (ilBcryptPhpPasswordEncoder $encoder)
 
 testCostsCanBeDeterminedDynamically (ilBcryptPhpPasswordEncoder $encoder)
 
 testEncoderDoesNotRelyOnSalts (ilBcryptPhpPasswordEncoder $encoder)
 
 testReencodingIsDetectedWhenNecessary (ilBcryptPhpPasswordEncoder $encoder)
 

Static Public Member Functions

static costsProvider ()
 

Private Attributes

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

Detailed Description

Definition at line 25 of file ilBcryptPhpPasswordEncoderTest.php.

Member Function Documentation

◆ costsProvider()

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

Definition at line 34 of file ilBcryptPhpPasswordEncoderTest.php.

34 : array
35 {
36 $data = [];
37 for ($i = 4; $i <= 31; ++$i) {
38 $data[sprintf('Costs: %s', $i)] = [(string) $i];
39 }
40
41 return $data;
42 }

References $data.

◆ testCostsCanBeDeterminedDynamically()

ilBcryptPhpPasswordEncoderTest::testCostsCanBeDeterminedDynamically ( ilBcryptPhpPasswordEncoder  $encoder)

Definition at line 125 of file ilBcryptPhpPasswordEncoderTest.php.

125 : void
126 {
127 $costs_default = $encoder->benchmarkCost();
128 $costs_target = $encoder->benchmarkCost(0.5);
129
130 $this->assertTrue($costs_default > 4 && $costs_default < 32);
131 $this->assertTrue($costs_target > 4 && $costs_target < 32);
132 $this->assertIsInt($costs_default);
133 $this->assertIsInt($costs_target);
134 $this->assertNotEquals($costs_default, $costs_target);
135 }

References ilBcryptPhpPasswordEncoder\benchmarkCost().

+ Here is the call graph for this function:

◆ testCostsCanBeRetrievedWhenCostsAreSet()

ilBcryptPhpPasswordEncoderTest::testCostsCanBeRetrievedWhenCostsAreSet ( ilBcryptPhpPasswordEncoder  $encoder)

Definition at line 59 of file ilBcryptPhpPasswordEncoderTest.php.

59 : void
60 {
61 $expected = '04';
62
63 $encoder->setCosts($expected);
64 $this->assertSame($expected, $encoder->getCosts());
65 }

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

+ Here is the call graph for this function:

◆ testCostsCanBeSetInRange()

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

Definition at line 84 of file ilBcryptPhpPasswordEncoderTest.php.

84 : void
85 {
86 $encoder->setCosts($costs);
87 }

References ilBcryptPhpPasswordEncoder\setCosts().

+ Here is the call graph for this function:

◆ testCostsCannotBeSetAboveRange()

ilBcryptPhpPasswordEncoderTest::testCostsCannotBeSetAboveRange ( ilBcryptPhpPasswordEncoder  $encoder)

Definition at line 68 of file ilBcryptPhpPasswordEncoderTest.php.

68 : void
69 {
70 $this->expectException(ilPasswordException::class);
71 $encoder->setCosts('32');
72 }

References ilBcryptPhpPasswordEncoder\setCosts().

+ Here is the call graph for this function:

◆ testCostsCannotBeSetBelowRange()

ilBcryptPhpPasswordEncoderTest::testCostsCannotBeSetBelowRange ( ilBcryptPhpPasswordEncoder  $encoder)

Definition at line 75 of file ilBcryptPhpPasswordEncoderTest.php.

75 : void
76 {
77 $this->expectException(ilPasswordException::class);
78 $encoder->setCosts('3');
79 }

References ilBcryptPhpPasswordEncoder\setCosts().

+ Here is the call graph for this function:

◆ testEncoderDoesNotRelyOnSalts()

ilBcryptPhpPasswordEncoderTest::testEncoderDoesNotRelyOnSalts ( ilBcryptPhpPasswordEncoder  $encoder)

Definition at line 138 of file ilBcryptPhpPasswordEncoderTest.php.

138 : void
139 {
140 $this->assertFalse($encoder->requiresSalt());
141 }
requiresSalt()
Returns whether the encoder requires a salt.

References ilBasePasswordEncoder\requiresSalt().

+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding()

ilBcryptPhpPasswordEncoderTest::testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding ( ilBcryptPhpPasswordEncoder  $encoder)

Definition at line 102 of file ilBcryptPhpPasswordEncoderTest.php.

104 : void {
105 $this->expectException(ilPasswordException::class);
106 $encoder->setCosts(self::VALID_COSTS);
107 $encoder->encodePassword(str_repeat('a', 5000), '');
108 }
encodePassword(string $raw, string $salt)
Encodes the raw password.

◆ testInstanceCanBeCreated()

ilBcryptPhpPasswordEncoderTest::testInstanceCanBeCreated ( )

Definition at line 44 of file ilBcryptPhpPasswordEncoderTest.php.

45 {
46 $default_costs_encoder = new ilBcryptPhpPasswordEncoder();
47 $this->assertTrue((int) $default_costs_encoder->getCosts() > 4 && (int) $default_costs_encoder->getCosts() < 32);
48
49 $encoder = new ilBcryptPhpPasswordEncoder([
50 'cost' => self::VALID_COSTS
51 ]);
52 $this->assertInstanceOf(ilBcryptPhpPasswordEncoder::class, $encoder);
53 $this->assertSame(self::VALID_COSTS, $encoder->getCosts());
54
55 return $encoder;
56 }

◆ testNameShouldBeBcryptPhp()

ilBcryptPhpPasswordEncoderTest::testNameShouldBeBcryptPhp ( ilBcryptPhpPasswordEncoder  $encoder)

Definition at line 119 of file ilBcryptPhpPasswordEncoderTest.php.

119 : void
120 {
121 $this->assertSame('bcryptphp', $encoder->getName());
122 }
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)

Definition at line 90 of file ilBcryptPhpPasswordEncoderTest.php.

93 $encoder->setCosts(self::VALID_COSTS);
94 $encoded_password = $encoder->encodePassword(self::PASSWORD, '');
95 $this->assertTrue($encoder->isPasswordValid($encoded_password, self::PASSWORD, ''));
96 $this->assertFalse($encoder->isPasswordValid($encoded_password, self::WRONG_PASSWORD, ''));
97
98 return $encoder;
99 }
isPasswordValid(string $encoded, string $raw, string $salt)
Checks a raw password against an encoded password.

◆ testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength()

ilBcryptPhpPasswordEncoderTest::testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength ( ilBcryptPhpPasswordEncoder  $encoder)

Definition at line 111 of file ilBcryptPhpPasswordEncoderTest.php.

113 : void {
114 $encoder->setCosts(self::VALID_COSTS);
115 $this->assertFalse($encoder->isPasswordValid('encoded', str_repeat('a', 5000), ''));
116 }

◆ testReencodingIsDetectedWhenNecessary()

ilBcryptPhpPasswordEncoderTest::testReencodingIsDetectedWhenNecessary ( ilBcryptPhpPasswordEncoder  $encoder)

Definition at line 144 of file ilBcryptPhpPasswordEncoderTest.php.

144 : void
145 {
146 $raw = self::PASSWORD;
147
148 $encoder->setCosts('8');
149 $encoded = $encoder->encodePassword($raw, '');
150 $encoder->setCosts('8');
151 $this->assertFalse($encoder->requiresReencoding($encoded));
152
153 $encoder->setCosts('9');
154 $this->assertTrue($encoder->requiresReencoding($encoded));
155 }
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 string ilBcryptPhpPasswordEncoderTest::PASSWORD = 'password'
private

Definition at line 28 of file ilBcryptPhpPasswordEncoderTest.php.

◆ VALID_COSTS

const string ilBcryptPhpPasswordEncoderTest::VALID_COSTS = '08'
private

Definition at line 27 of file ilBcryptPhpPasswordEncoderTest.php.

◆ WRONG_PASSWORD

const string ilBcryptPhpPasswordEncoderTest::WRONG_PASSWORD = 'wrong_password'
private

Definition at line 29 of file ilBcryptPhpPasswordEncoderTest.php.


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