ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
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 50 of file ilBcryptPhpPasswordEncoderTest.php.

References $data, and array.

51  {
52  $data = array();
53  for($i = 4; $i <= 31; $i++)
54  {
55  $data[] = array($i);
56  }
57  return $data;
58  }
Create styles array
The data for the language used.

◆ 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  {
43  $this->markTestSkipped('Requires PHP >= 5.5.0');
44  }
45  }
+ Here is the caller graph for this function:

◆ testCostsCanBeDeterminedDynamically()

ilBcryptPhpPasswordEncoderTest::testCostsCanBeDeterminedDynamically ( ilBcryptPhpPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 159 of file ilBcryptPhpPasswordEncoderTest.php.

References ilBcryptPhpPasswordEncoder\benchmarkCost().

160  {
161  $costs_default = $encoder->benchmarkCost();
162  $costs_target = $encoder->benchmarkCost(0.5);
163 
164  $this->assertTrue($costs_default > 4 && $costs_default < 32);
165  $this->assertTrue($costs_target > 4 && $costs_target < 32);
166  $this->assertInternalType('int', $costs_default);
167  $this->assertInternalType('int', $costs_target);
168  $this->assertNotEquals($costs_default, $costs_target);
169  }
+ Here is the call graph for this function:

◆ testCostsCanBeRetrievedWhenCostsAreSet()

ilBcryptPhpPasswordEncoderTest::testCostsCanBeRetrievedWhenCostsAreSet ( ilBcryptPhpPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 81 of file ilBcryptPhpPasswordEncoderTest.php.

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

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

◆ testCostsCanBeSetInRange()

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

testInstanceCanBeCreated costsProvider

Definition at line 111 of file ilBcryptPhpPasswordEncoderTest.php.

References ilBcryptPhpPasswordEncoder\setCosts().

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

◆ testCostsCannotBeSetAboveRange()

ilBcryptPhpPasswordEncoderTest::testCostsCannotBeSetAboveRange ( ilBcryptPhpPasswordEncoder  $encoder)

testInstanceCanBeCreated ilPasswordException

Definition at line 91 of file ilBcryptPhpPasswordEncoderTest.php.

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

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

◆ testCostsCannotBeSetBelowRange()

ilBcryptPhpPasswordEncoderTest::testCostsCannotBeSetBelowRange ( ilBcryptPhpPasswordEncoder  $encoder)

testInstanceCanBeCreated ilPasswordException

Definition at line 101 of file ilBcryptPhpPasswordEncoderTest.php.

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

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

◆ testEncoderDoesNotRelyOnSalts()

ilBcryptPhpPasswordEncoderTest::testEncoderDoesNotRelyOnSalts ( ilBcryptPhpPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 174 of file ilBcryptPhpPasswordEncoderTest.php.

References ilBasePasswordEncoder\requiresSalt().

175  {
176  $this->assertFalse($encoder->requiresSalt());
177  }
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 132 of file ilBcryptPhpPasswordEncoderTest.php.

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

133  {
134  $this->assertException(ilPasswordException::class);
135  $encoder->setCosts(self::VALID_COSTS);
136  $encoder->encodePassword(str_repeat('a', 5000), '');
137  }
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 63 of file ilBcryptPhpPasswordEncoderTest.php.

References array, and skipIfPhpVersionIsNotSupported().

64  {
66 
67  $default_costs_encoder = new ilBcryptPhpPasswordEncoder();
68  $this->assertTrue((int)$default_costs_encoder->getCosts() > 4 && (int)$default_costs_encoder->getCosts() < 32);
69 
70  $encoder = new ilBcryptPhpPasswordEncoder(array(
71  'cost' => self::VALID_COSTS
72  ));
73  $this->assertInstanceOf('ilBcryptPhpPasswordEncoder', $encoder);
74  $this->assertEquals(self::VALID_COSTS, $encoder->getCosts());
75  return $encoder;
76  }
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 151 of file ilBcryptPhpPasswordEncoderTest.php.

References ilBcryptPhpPasswordEncoder\getName().

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

◆ testPasswordShouldBeCorrectlyEncodedAndVerified()

ilBcryptPhpPasswordEncoderTest::testPasswordShouldBeCorrectlyEncodedAndVerified ( ilBcryptPhpPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 119 of file ilBcryptPhpPasswordEncoderTest.php.

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

120  {
121  $encoder->setCosts(self::VALID_COSTS);
122  $encoded_password = $encoder->encodePassword(self::PASSWORD, '');
123  $this->assertTrue($encoder->isPasswordValid($encoded_password, self::PASSWORD, ''));
124  $this->assertFalse($encoder->isPasswordValid($encoded_password, self::WRONG_PASSWORD, ''));
125  return $encoder;
126  }
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 142 of file ilBcryptPhpPasswordEncoderTest.php.

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

143  {
144  $encoder->setCosts(self::VALID_COSTS);
145  $this->assertFalse($encoder->isPasswordValid('encoded', str_repeat('a', 5000), ''));
146  }
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 182 of file ilBcryptPhpPasswordEncoderTest.php.

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

183  {
184  $raw = self::PASSWORD;
185 
186  $encoder->setCosts(8);
187  $encoded = $encoder->encodePassword($raw, '');
188  $encoder->setCosts(8);
189  $this->assertFalse($encoder->requiresReencoding($encoded));
190 
191  $encoder->setCosts(9);
192  $this->assertTrue($encoder->requiresReencoding($encoded));
193  }
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: