ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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.

References $data.

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  }

◆ testCostsCanBeDeterminedDynamically()

ilBcryptPhpPasswordEncoderTest::testCostsCanBeDeterminedDynamically ( ilBcryptPhpPasswordEncoder  $encoder)

Definition at line 125 of file ilBcryptPhpPasswordEncoderTest.php.

References ilBcryptPhpPasswordEncoder\benchmarkCost().

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  }
+ Here is the call graph for this function:

◆ testCostsCanBeRetrievedWhenCostsAreSet()

ilBcryptPhpPasswordEncoderTest::testCostsCanBeRetrievedWhenCostsAreSet ( ilBcryptPhpPasswordEncoder  $encoder)

Definition at line 59 of file ilBcryptPhpPasswordEncoderTest.php.

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

59  : void
60  {
61  $expected = '04';
62 
63  $encoder->setCosts($expected);
64  $this->assertSame($expected, $encoder->getCosts());
65  }
+ Here is the call graph for this function:

◆ testCostsCanBeSetInRange()

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

Definition at line 84 of file ilBcryptPhpPasswordEncoderTest.php.

References ilBcryptPhpPasswordEncoder\setCosts().

84  : void
85  {
86  $encoder->setCosts($costs);
87  }
+ Here is the call graph for this function:

◆ testCostsCannotBeSetAboveRange()

ilBcryptPhpPasswordEncoderTest::testCostsCannotBeSetAboveRange ( ilBcryptPhpPasswordEncoder  $encoder)

Definition at line 68 of file ilBcryptPhpPasswordEncoderTest.php.

References ilBcryptPhpPasswordEncoder\setCosts().

68  : void
69  {
70  $this->expectException(ilPasswordException::class);
71  $encoder->setCosts('32');
72  }
+ Here is the call graph for this function:

◆ testCostsCannotBeSetBelowRange()

ilBcryptPhpPasswordEncoderTest::testCostsCannotBeSetBelowRange ( ilBcryptPhpPasswordEncoder  $encoder)

Definition at line 75 of file ilBcryptPhpPasswordEncoderTest.php.

References ilBcryptPhpPasswordEncoder\setCosts().

75  : void
76  {
77  $this->expectException(ilPasswordException::class);
78  $encoder->setCosts('3');
79  }
+ Here is the call graph for this function:

◆ testEncoderDoesNotRelyOnSalts()

ilBcryptPhpPasswordEncoderTest::testEncoderDoesNotRelyOnSalts ( ilBcryptPhpPasswordEncoder  $encoder)

Definition at line 138 of file ilBcryptPhpPasswordEncoderTest.php.

References ilBasePasswordEncoder\requiresSalt().

138  : void
139  {
140  $this->assertFalse($encoder->requiresSalt());
141  }
requiresSalt()
Returns whether the encoder requires a salt.
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding()

ilBcryptPhpPasswordEncoderTest::testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding ( ilBcryptPhpPasswordEncoder  $encoder)

Definition at line 102 of file ilBcryptPhpPasswordEncoderTest.php.

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

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.
+ Here is the call graph for this function:

◆ testInstanceCanBeCreated()

ilBcryptPhpPasswordEncoderTest::testInstanceCanBeCreated ( )

Definition at line 44 of file ilBcryptPhpPasswordEncoderTest.php.

References ILIAS\Repository\int().

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  }
+ Here is the call graph for this function:

◆ testNameShouldBeBcryptPhp()

ilBcryptPhpPasswordEncoderTest::testNameShouldBeBcryptPhp ( ilBcryptPhpPasswordEncoder  $encoder)

Definition at line 119 of file ilBcryptPhpPasswordEncoderTest.php.

References ilBcryptPhpPasswordEncoder\getName().

119  : void
120  {
121  $this->assertSame('bcryptphp', $encoder->getName());
122  }
getName()
Returns a unique name/id of the concrete password encoder.
+ Here is the call graph for this function:

◆ testPasswordShouldBeCorrectlyEncodedAndVerified()

ilBcryptPhpPasswordEncoderTest::testPasswordShouldBeCorrectlyEncodedAndVerified ( ilBcryptPhpPasswordEncoder  $encoder)

Definition at line 90 of file ilBcryptPhpPasswordEncoderTest.php.

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

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  }
encodePassword(string $raw, string $salt)
Encodes the raw password.
isPasswordValid(string $encoded, string $raw, string $salt)
Checks a raw password against an encoded password.
+ Here is the call graph for this function:

◆ testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength()

ilBcryptPhpPasswordEncoderTest::testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength ( ilBcryptPhpPasswordEncoder  $encoder)

Definition at line 111 of file ilBcryptPhpPasswordEncoderTest.php.

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

113  : void {
114  $encoder->setCosts(self::VALID_COSTS);
115  $this->assertFalse($encoder->isPasswordValid('encoded', str_repeat('a', 5000), ''));
116  }
isPasswordValid(string $encoded, string $raw, string $salt)
Checks a raw password against an encoded password.
+ Here is the call graph for this function:

◆ testReencodingIsDetectedWhenNecessary()

ilBcryptPhpPasswordEncoderTest::testReencodingIsDetectedWhenNecessary ( ilBcryptPhpPasswordEncoder  $encoder)

Definition at line 144 of file ilBcryptPhpPasswordEncoderTest.php.

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

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  }
encodePassword(string $raw, string $salt)
Encodes the raw password.
requiresReencoding(string $encoded)
Returns whether the encoded password needs to be re-encoded.
+ 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: