ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilBcryptPhpPasswordEncoderTest Class Reference
+ Inheritance diagram for ilBcryptPhpPasswordEncoderTest:
+ Collaboration diagram for ilBcryptPhpPasswordEncoderTest:

Public Member Functions

 costsProvider ()
 
 testInstanceCanBeCreated ()
 
 testCostsCanBeRetrievedWhenCostsAreSet (ilBcryptPhpPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testCostsCannotBeSetAboveRange (ilBcryptPhpPasswordEncoder $encoder)
 testInstanceCanBeCreated ilPasswordException More...
 
 testCostsCannotBeSetBelowRange (ilBcryptPhpPasswordEncoder $encoder)
 testInstanceCanBeCreated ilPasswordException More...
 
 testCostsCanBeSetInRange ($costs, ilBcryptPhpPasswordEncoder $encoder)
 testInstanceCanBeCreated costsProvider More...
 
 testPasswordShouldBeCorrectlyEncodedAndVerified (ilBcryptPhpPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding (ilBcryptPhpPasswordEncoder $encoder)
 testInstanceCanBeCreated ilPasswordException More...
 
 testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength (ilBcryptPhpPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testNameShouldBeBcryptPhp (ilBcryptPhpPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testCostsCanBeDeterminedDynamically (ilBcryptPhpPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testEncoderDoesNotRelyOnSalts (ilBcryptPhpPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testReencodingIsDetectedWhenNecessary (ilBcryptPhpPasswordEncoder $encoder)
 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 49 of file ilBcryptPhpPasswordEncoderTest.php.

References $data, $i, and array.

50  {
51  $data = array();
52  for ($i = 4; $i <= 31; $i++) {
53  $data[] = array($i);
54  }
55  return $data;
56  }
Create styles array
The data for the language used.
$i
Definition: disco.tpl.php:19

◆ 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.

Referenced by testInstanceCanBeCreated().

40  {
41  if (version_compare(phpversion(), '5.5.0', '<')) {
42  $this->markTestSkipped('Requires PHP >= 5.5.0');
43  }
44  }
+ Here is the caller graph for this function:

◆ testCostsCanBeDeterminedDynamically()

ilBcryptPhpPasswordEncoderTest::testCostsCanBeDeterminedDynamically ( ilBcryptPhpPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 157 of file ilBcryptPhpPasswordEncoderTest.php.

References ilBcryptPhpPasswordEncoder\benchmarkCost().

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->assertInternalType('int', $costs_default);
165  $this->assertInternalType('int', $costs_target);
166  $this->assertNotEquals($costs_default, $costs_target);
167  }
+ Here is the call graph for this function:

◆ testCostsCanBeRetrievedWhenCostsAreSet()

ilBcryptPhpPasswordEncoderTest::testCostsCanBeRetrievedWhenCostsAreSet ( ilBcryptPhpPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 79 of file ilBcryptPhpPasswordEncoderTest.php.

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

80  {
81  $encoder->setCosts(4);
82  $this->assertEquals(4, $encoder->getCosts());
83  }
+ Here is the call graph for this function:

◆ testCostsCanBeSetInRange()

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

testInstanceCanBeCreated costsProvider

Definition at line 109 of file ilBcryptPhpPasswordEncoderTest.php.

References ilBcryptPhpPasswordEncoder\setCosts().

110  {
111  $encoder->setCosts($costs);
112  }
+ Here is the call graph for this function:

◆ testCostsCannotBeSetAboveRange()

ilBcryptPhpPasswordEncoderTest::testCostsCannotBeSetAboveRange ( ilBcryptPhpPasswordEncoder  $encoder)

testInstanceCanBeCreated ilPasswordException

Definition at line 89 of file ilBcryptPhpPasswordEncoderTest.php.

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

90  {
91  $this->assertException(ilPasswordException::class);
92  $encoder->setCosts(32);
93  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testCostsCannotBeSetBelowRange()

ilBcryptPhpPasswordEncoderTest::testCostsCannotBeSetBelowRange ( ilBcryptPhpPasswordEncoder  $encoder)

testInstanceCanBeCreated ilPasswordException

Definition at line 99 of file ilBcryptPhpPasswordEncoderTest.php.

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

100  {
101  $this->assertException(ilPasswordException::class);
102  $encoder->setCosts(3);
103  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testEncoderDoesNotRelyOnSalts()

ilBcryptPhpPasswordEncoderTest::testEncoderDoesNotRelyOnSalts ( ilBcryptPhpPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 172 of file ilBcryptPhpPasswordEncoderTest.php.

References ilBasePasswordEncoder\requiresSalt().

173  {
174  $this->assertFalse($encoder->requiresSalt());
175  }
requiresSalt()
{Returns whether or not the encoder requires a salt.boolean}
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding()

ilBcryptPhpPasswordEncoderTest::testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding ( ilBcryptPhpPasswordEncoder  $encoder)

testInstanceCanBeCreated ilPasswordException

Definition at line 130 of file ilBcryptPhpPasswordEncoderTest.php.

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

131  {
132  $this->assertException(ilPasswordException::class);
133  $encoder->setCosts(self::VALID_COSTS);
134  $encoder->encodePassword(str_repeat('a', 5000), '');
135  }
encodePassword($raw, $salt)
{Encodes the raw password.The password to encode The salt string The encoded password} ...
assertException($exception_class)
+ Here is the call graph for this function:

◆ testInstanceCanBeCreated()

ilBcryptPhpPasswordEncoderTest::testInstanceCanBeCreated ( )
Returns
ilBcryptPhpPasswordEncoder

Definition at line 61 of file ilBcryptPhpPasswordEncoderTest.php.

References array, and skipIfPhpVersionIsNotSupported().

62  {
64 
65  $default_costs_encoder = new ilBcryptPhpPasswordEncoder();
66  $this->assertTrue((int) $default_costs_encoder->getCosts() > 4 && (int) $default_costs_encoder->getCosts() < 32);
67 
68  $encoder = new ilBcryptPhpPasswordEncoder(array(
69  'cost' => self::VALID_COSTS
70  ));
71  $this->assertInstanceOf('ilBcryptPhpPasswordEncoder', $encoder);
72  $this->assertEquals(self::VALID_COSTS, $encoder->getCosts());
73  return $encoder;
74  }
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ testNameShouldBeBcryptPhp()

ilBcryptPhpPasswordEncoderTest::testNameShouldBeBcryptPhp ( ilBcryptPhpPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 149 of file ilBcryptPhpPasswordEncoderTest.php.

References ilBcryptPhpPasswordEncoder\getName().

150  {
151  $this->assertEquals('bcryptphp', $encoder->getName());
152  }
+ Here is the call graph for this function:

◆ testPasswordShouldBeCorrectlyEncodedAndVerified()

ilBcryptPhpPasswordEncoderTest::testPasswordShouldBeCorrectlyEncodedAndVerified ( ilBcryptPhpPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 117 of file ilBcryptPhpPasswordEncoderTest.php.

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

118  {
119  $encoder->setCosts(self::VALID_COSTS);
120  $encoded_password = $encoder->encodePassword(self::PASSWORD, '');
121  $this->assertTrue($encoder->isPasswordValid($encoded_password, self::PASSWORD, ''));
122  $this->assertFalse($encoder->isPasswordValid($encoded_password, self::WRONG_PASSWORD, ''));
123  return $encoder;
124  }
isPasswordValid($encoded, $raw, $salt)
{Checks a raw password against an encoded password.The raw password has to be injected into the encod...
encodePassword($raw, $salt)
{Encodes the raw password.The password to encode The salt string The encoded password} ...
+ Here is the call graph for this function:

◆ testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength()

ilBcryptPhpPasswordEncoderTest::testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength ( ilBcryptPhpPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 140 of file ilBcryptPhpPasswordEncoderTest.php.

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

141  {
142  $encoder->setCosts(self::VALID_COSTS);
143  $this->assertFalse($encoder->isPasswordValid('encoded', str_repeat('a', 5000), ''));
144  }
isPasswordValid($encoded, $raw, $salt)
{Checks a raw password against an encoded password.The raw password has to be injected into the encod...
+ Here is the call graph for this function:

◆ testReencodingIsDetectedWhenNecessary()

ilBcryptPhpPasswordEncoderTest::testReencodingIsDetectedWhenNecessary ( ilBcryptPhpPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 180 of file ilBcryptPhpPasswordEncoderTest.php.

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

181  {
182  $raw = self::PASSWORD;
183 
184  $encoder->setCosts(8);
185  $encoded = $encoder->encodePassword($raw, '');
186  $encoder->setCosts(8);
187  $this->assertFalse($encoder->requiresReencoding($encoded));
188 
189  $encoder->setCosts(9);
190  $this->assertTrue($encoder->requiresReencoding($encoded));
191  }
requiresReencoding($encoded)
{Returns whether or not the a encoded password needs to be re-encoded.string boolean} ...
encodePassword($raw, $salt)
{Encodes the raw password.The password to encode The salt string The encoded password} ...
+ Here is the call graph for this function:

Field Documentation

◆ PASSWORD

const ilBcryptPhpPasswordEncoderTest::PASSWORD = 'password'

Definition at line 22 of file ilBcryptPhpPasswordEncoderTest.php.

◆ 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: