ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilBcryptPasswordEncoderTest Class Reference
+ Inheritance diagram for ilBcryptPasswordEncoderTest:
+ Collaboration diagram for ilBcryptPasswordEncoderTest:

Public Member Functions

 getTestDirectory ()
 
 setTestDirectory ($test_directory)
 
 getTestDirectoryUrl ()
 
 setTestDirectoryUrl ($test_directory_url)
 
 costsProvider ()
 
 testInstanceCanBeCreated ()
 
 testCostsCanBeRetrievedWhenCostsAreSet (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testCostsCannotBeSetAboveRange (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated ilPasswordException More...
 
 testCostsCannotBeSetBelowRange (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated ilPasswordException More...
 
 testCostsCanBeSetInRange ($costs, ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated costsProvider More...
 
 testPasswordShouldBeCorrectlyEncodedAndVerified (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated ilPasswordException More...
 
 testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testEncoderReliesOnSalts (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testEncoderDoesNotSupportReencoding (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testNameShouldBeBcrypt (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testExceptionIsRaisedIfSaltIsMissingIsOnEncoding ()
 ilPasswordException More...
 
 testExceptionIsRaisedIfSaltIsMissingIsOnVerification ()
 ilPasswordException More...
 
 testInstanceCanBeCreatedAndInitializedWithClientSalt ()
 
 testClientSaltIsGeneratedWhenNoClientSaltExistsYet ()
 
 testExceptionIsRaisedWhenClientSaltCouldNotBeGeneratedInCaseNoClientSaltExistsYet ()
 ilPasswordException More...
 
 testBackwardCompatibilityCanBeRetrievedWhenBackwardCompatibilityIsSet ()
 
 testBackwardCompatibility ()
 
 testExceptionIsRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabled ()
 ilPasswordException More...
 
 testExceptionIsNotRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabledWithIgnoredSecurityFlaw ()
 

Data Fields

const VALID_COSTS = '08'
 
const PASSWORD = 'password'
 
const WRONG_PASSWORD = 'wrong_password'
 
const CLIENT_SALT = 'homer!12345_/'
 
const PASSWORD_SALT = 'salt'
 

Protected Member Functions

 setUp ()
 Setup. More...
 
- Protected Member Functions inherited from ilPasswordBaseTest
 assertException ($exception_class)
 

Protected Attributes

 $test_directory
 
 $test_directory_url
 

Private Member Functions

 skipIfPhpVersionIsNotSupported ()
 
 getInstanceWithConfiguredDataDirectory ()
 

Detailed Description

Definition at line 14 of file ilBcryptPasswordEncoderTest.php.

Member Function Documentation

◆ costsProvider()

ilBcryptPasswordEncoderTest::costsProvider ( )
Returns
array

Definition at line 108 of file ilBcryptPasswordEncoderTest.php.

References $data, and $i.

109  {
110  $data = array();
111  for ($i = 4; $i <= 31; $i++) {
112  $data[] = array($i);
113  }
114  return $data;
115  }
$i
Definition: disco.tpl.php:19
$data
Definition: bench.php:6

◆ getInstanceWithConfiguredDataDirectory()

◆ getTestDirectory()

ilBcryptPasswordEncoderTest::getTestDirectory ( )

◆ getTestDirectoryUrl()

ilBcryptPasswordEncoderTest::getTestDirectoryUrl ( )
Returns
string

Definition at line 70 of file ilBcryptPasswordEncoderTest.php.

References $test_directory_url.

Referenced by getInstanceWithConfiguredDataDirectory(), and testInstanceCanBeCreated().

+ Here is the caller graph for this function:

◆ setTestDirectory()

ilBcryptPasswordEncoderTest::setTestDirectory (   $test_directory)
Parameters
vfs\vfsStreamDirectory$test_directory

Definition at line 62 of file ilBcryptPasswordEncoderTest.php.

References $test_directory.

Referenced by setUp().

63  {
64  $this->test_directory = $test_directory;
65  }
+ Here is the caller graph for this function:

◆ setTestDirectoryUrl()

ilBcryptPasswordEncoderTest::setTestDirectoryUrl (   $test_directory_url)
Parameters
string$test_directory_url

Definition at line 78 of file ilBcryptPasswordEncoderTest.php.

References $test_directory_url.

Referenced by setUp().

79  {
80  $this->test_directory_url = $test_directory_url;
81  }
+ Here is the caller graph for this function:

◆ setUp()

ilBcryptPasswordEncoderTest::setUp ( )
protected

Setup.

Definition at line 86 of file ilBcryptPasswordEncoderTest.php.

References setTestDirectory(), and setTestDirectoryUrl().

87  {
88  vfs\vfsStream::setup();
89  $this->setTestDirectory(vfs\vfsStream::newDirectory('tests')->at(vfs\vfsStreamWrapper::getRoot()));
90  $this->setTestDirectoryUrl(vfs\vfsStream::url('root/tests'));
91 
92  parent::setUp();
93  }
+ Here is the call graph for this function:

◆ skipIfPhpVersionIsNotSupported()

ilBcryptPasswordEncoderTest::skipIfPhpVersionIsNotSupported ( )
private

Definition at line 98 of file ilBcryptPasswordEncoderTest.php.

Referenced by testBackwardCompatibility().

99  {
100  if (version_compare(phpversion(), '5.3.7', '<')) {
101  $this->markTestSkipped('Requires PHP >= 5.3.7');
102  }
103  }
+ Here is the caller graph for this function:

◆ testBackwardCompatibility()

ilBcryptPasswordEncoderTest::testBackwardCompatibility ( )

Definition at line 325 of file ilBcryptPasswordEncoderTest.php.

References getInstanceWithConfiguredDataDirectory(), and skipIfPhpVersionIsNotSupported().

326  {
328 
329  $encoder = $this->getInstanceWithConfiguredDataDirectory();
330  $encoder->setClientSalt(self::CLIENT_SALT);
331  $encoder->setBackwardCompatibility(true);
332  $encoded_password = $encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
333  $this->assertTrue($encoder->isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
334  $this->assertEquals('$2a$', substr($encoded_password, 0, 4));
335 
336  $another_encoder = $this->getInstanceWithConfiguredDataDirectory();
337  $another_encoder->setClientSalt(self::CLIENT_SALT);
338  $another_encoder->setBackwardCompatibility(false);
339  $another_encoded_password = $another_encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
340  $this->assertEquals('$2y$', substr($another_encoded_password, 0, 4));
341  $this->assertTrue($another_encoder->isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
342  }
+ Here is the call graph for this function:

◆ testBackwardCompatibilityCanBeRetrievedWhenBackwardCompatibilityIsSet()

ilBcryptPasswordEncoderTest::testBackwardCompatibilityCanBeRetrievedWhenBackwardCompatibilityIsSet ( )

Definition at line 313 of file ilBcryptPasswordEncoderTest.php.

References getInstanceWithConfiguredDataDirectory().

314  {
315  $encoder = $this->getInstanceWithConfiguredDataDirectory();
316  $encoder->setBackwardCompatibility(true);
317  $this->assertTrue($encoder->isBackwardCompatibilityEnabled());
318  $encoder->setBackwardCompatibility(false);
319  $this->assertFalse($encoder->isBackwardCompatibilityEnabled());
320  }
+ Here is the call graph for this function:

◆ testClientSaltIsGeneratedWhenNoClientSaltExistsYet()

ilBcryptPasswordEncoderTest::testClientSaltIsGeneratedWhenNoClientSaltExistsYet ( )

Definition at line 291 of file ilBcryptPasswordEncoderTest.php.

References getInstanceWithConfiguredDataDirectory(), and getTestDirectory().

292  {
293  $this->getTestDirectory()->chmod(0777);
294 
295  $encoder = $this->getInstanceWithConfiguredDataDirectory();
296  $this->assertNotNull($encoder->getClientSalt());
297  }
+ Here is the call graph for this function:

◆ testCostsCanBeRetrievedWhenCostsAreSet()

ilBcryptPasswordEncoderTest::testCostsCanBeRetrievedWhenCostsAreSet ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 161 of file ilBcryptPasswordEncoderTest.php.

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

162  {
163  $encoder->setCosts(4);
164  $this->assertEquals(4, $encoder->getCosts());
165  }
+ Here is the call graph for this function:

◆ testCostsCanBeSetInRange()

ilBcryptPasswordEncoderTest::testCostsCanBeSetInRange (   $costs,
ilBcryptPasswordEncoder  $encoder 
)

testInstanceCanBeCreated costsProvider

Definition at line 191 of file ilBcryptPasswordEncoderTest.php.

References ilBcryptPhpPasswordEncoder\setCosts().

192  {
193  $encoder->setCosts($costs);
194  }
+ Here is the call graph for this function:

◆ testCostsCannotBeSetAboveRange()

ilBcryptPasswordEncoderTest::testCostsCannotBeSetAboveRange ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated ilPasswordException

Definition at line 171 of file ilBcryptPasswordEncoderTest.php.

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

172  {
173  $this->assertException(ilPasswordException::class);
174  $encoder->setCosts(32);
175  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testCostsCannotBeSetBelowRange()

ilBcryptPasswordEncoderTest::testCostsCannotBeSetBelowRange ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated ilPasswordException

Definition at line 181 of file ilBcryptPasswordEncoderTest.php.

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

182  {
183  $this->assertException(ilPasswordException::class);
184  $encoder->setCosts(3);
185  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testEncoderDoesNotSupportReencoding()

ilBcryptPasswordEncoderTest::testEncoderDoesNotSupportReencoding ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 239 of file ilBcryptPasswordEncoderTest.php.

References ilBcryptPasswordEncoder\requiresReencoding().

240  {
241  $this->assertFalse($encoder->requiresReencoding('hello'));
242  }
requiresReencoding($encoded)
{Returns whether or not the a encoded password needs to be re-encoded.string boolean} ...
+ Here is the call graph for this function:

◆ testEncoderReliesOnSalts()

ilBcryptPasswordEncoderTest::testEncoderReliesOnSalts ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 231 of file ilBcryptPasswordEncoderTest.php.

References ilBcryptPasswordEncoder\requiresSalt().

232  {
233  $this->assertTrue($encoder->requiresSalt());
234  }
requiresSalt()
{Returns whether or not the encoder requires a salt.boolean}
+ Here is the call graph for this function:

◆ testExceptionIsNotRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabledWithIgnoredSecurityFlaw()

ilBcryptPasswordEncoderTest::testExceptionIsNotRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabledWithIgnoredSecurityFlaw ( )

Definition at line 359 of file ilBcryptPasswordEncoderTest.php.

References getInstanceWithConfiguredDataDirectory().

360  {
361  $encoder = $this->getInstanceWithConfiguredDataDirectory();
362  $encoder->setClientSalt(self::CLIENT_SALT);
363  $encoder->setBackwardCompatibility(true);
364  $encoder->setIsSecurityFlawIgnored(true);
365  $encoder->encodePassword(self::PASSWORD . chr(195), self::PASSWORD_SALT);
366  }
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfSaltIsMissingIsOnEncoding()

ilBcryptPasswordEncoderTest::testExceptionIsRaisedIfSaltIsMissingIsOnEncoding ( )

ilPasswordException

Definition at line 255 of file ilBcryptPasswordEncoderTest.php.

References ilPasswordBaseTest\assertException(), and getInstanceWithConfiguredDataDirectory().

256  {
257  $this->assertException(ilPasswordException::class);
258  $encoder = $this->getInstanceWithConfiguredDataDirectory();
259  $encoder->setClientSalt(null);
260  $encoder->setCosts(self::VALID_COSTS);
261  $encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
262  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfSaltIsMissingIsOnVerification()

ilBcryptPasswordEncoderTest::testExceptionIsRaisedIfSaltIsMissingIsOnVerification ( )

ilPasswordException

Definition at line 267 of file ilBcryptPasswordEncoderTest.php.

References ilPasswordBaseTest\assertException(), and getInstanceWithConfiguredDataDirectory().

268  {
269  $this->assertException(ilPasswordException::class);
270  $encoder = $this->getInstanceWithConfiguredDataDirectory();
271  $encoder->setClientSalt(null);
272  $encoder->setCosts(self::VALID_COSTS);
273  $encoder->isPasswordValid('12121212', self::PASSWORD, self::PASSWORD_SALT);
274  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding()

ilBcryptPasswordEncoderTest::testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated ilPasswordException

Definition at line 212 of file ilBcryptPasswordEncoderTest.php.

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

213  {
214  $this->assertException(ilPasswordException::class);
215  $encoder->setCosts(self::VALID_COSTS);
216  $encoder->encodePassword(str_repeat('a', 5000), self::PASSWORD_SALT);
217  }
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:

◆ testExceptionIsRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabled()

ilBcryptPasswordEncoderTest::testExceptionIsRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabled ( )

ilPasswordException

Definition at line 347 of file ilBcryptPasswordEncoderTest.php.

References ilPasswordBaseTest\assertException(), and getInstanceWithConfiguredDataDirectory().

348  {
349  $this->assertException(ilPasswordException::class);
350  $encoder = $this->getInstanceWithConfiguredDataDirectory();
351  $encoder->setClientSalt(self::CLIENT_SALT);
352  $encoder->setBackwardCompatibility(true);
353  $encoder->encodePassword(self::PASSWORD . chr(195), self::PASSWORD_SALT);
354  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testExceptionIsRaisedWhenClientSaltCouldNotBeGeneratedInCaseNoClientSaltExistsYet()

ilBcryptPasswordEncoderTest::testExceptionIsRaisedWhenClientSaltCouldNotBeGeneratedInCaseNoClientSaltExistsYet ( )

ilPasswordException

Definition at line 302 of file ilBcryptPasswordEncoderTest.php.

References ilPasswordBaseTest\assertException(), getInstanceWithConfiguredDataDirectory(), and getTestDirectory().

303  {
304  $this->assertException(ilPasswordException::class);
305  $this->getTestDirectory()->chmod(0000);
306 
307  $encoder = $this->getInstanceWithConfiguredDataDirectory();
308  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testInstanceCanBeCreated()

ilBcryptPasswordEncoderTest::testInstanceCanBeCreated ( )
Returns
ilBcryptPasswordEncoder

Definition at line 132 of file ilBcryptPasswordEncoderTest.php.

References getTestDirectoryUrl().

133  {
134  $security_flaw_ignoring_encoder = new ilBcryptPasswordEncoder(array(
135  'ignore_security_flaw' => true,
136  'data_directory' => $this->getTestDirectoryUrl()
137  ));
138  $this->assertTrue($security_flaw_ignoring_encoder->isSecurityFlawIgnored());
139 
140  $security_flaw_respecting_encoder = new ilBcryptPasswordEncoder(array(
141  'ignore_security_flaw' => false,
142  'data_directory' => $this->getTestDirectoryUrl()
143  ));
144  $this->assertFalse($security_flaw_respecting_encoder->isSecurityFlawIgnored());
145 
146  $encoder = new ilBcryptPasswordEncoder(array(
147  'cost' => self::VALID_COSTS,
148  'data_directory' => $this->getTestDirectoryUrl()
149  ));
150  $this->assertInstanceOf('ilBcryptPasswordEncoder', $encoder);
151  $this->assertEquals(self::VALID_COSTS, $encoder->getCosts());
152  $this->assertFalse($encoder->isSecurityFlawIgnored());
153  $encoder->setClientSalt(self::CLIENT_SALT);
154 
155  return $encoder;
156  }
+ Here is the call graph for this function:

◆ testInstanceCanBeCreatedAndInitializedWithClientSalt()

ilBcryptPasswordEncoderTest::testInstanceCanBeCreatedAndInitializedWithClientSalt ( )

Definition at line 279 of file ilBcryptPasswordEncoderTest.php.

References getInstanceWithConfiguredDataDirectory(), getTestDirectory(), and ilBcryptPasswordEncoder\SALT_STORAGE_FILENAME.

280  {
281  $this->getTestDirectory()->chmod(0777);
282  vfs\vfsStream::newFile(ilBcryptPasswordEncoder::SALT_STORAGE_FILENAME)->withContent(self::CLIENT_SALT)->at($this->getTestDirectory());
283 
284  $encoder = $this->getInstanceWithConfiguredDataDirectory();
285  $this->assertEquals(self::CLIENT_SALT, $encoder->getClientSalt());
286  }
+ Here is the call graph for this function:

◆ testNameShouldBeBcrypt()

ilBcryptPasswordEncoderTest::testNameShouldBeBcrypt ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 247 of file ilBcryptPasswordEncoderTest.php.

References ilBcryptPasswordEncoder\getName().

248  {
249  $this->assertEquals('bcrypt', $encoder->getName());
250  }
getName()
{Returns a unique name/id of the concrete password encoder.string}
+ Here is the call graph for this function:

◆ testPasswordShouldBeCorrectlyEncodedAndVerified()

ilBcryptPasswordEncoderTest::testPasswordShouldBeCorrectlyEncodedAndVerified ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 199 of file ilBcryptPasswordEncoderTest.php.

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

200  {
201  $encoder->setCosts(self::VALID_COSTS);
202  $encoded_password = $encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
203  $this->assertTrue($encoder->isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
204  $this->assertFalse($encoder->isPasswordValid($encoded_password, self::WRONG_PASSWORD, self::PASSWORD_SALT));
205  return $encoder;
206  }
encodePassword($raw, $salt)
{Encodes the raw password.The password to encode The salt string The encoded password} ...
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:

◆ testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength()

ilBcryptPasswordEncoderTest::testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 222 of file ilBcryptPasswordEncoderTest.php.

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

223  {
224  $encoder->setCosts(self::VALID_COSTS);
225  $this->assertFalse($encoder->isPasswordValid('encoded', str_repeat('a', 5000), self::PASSWORD_SALT));
226  }
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:

Field Documentation

◆ $test_directory

ilBcryptPasswordEncoderTest::$test_directory
protected

Definition at line 44 of file ilBcryptPasswordEncoderTest.php.

Referenced by getTestDirectory(), and setTestDirectory().

◆ $test_directory_url

ilBcryptPasswordEncoderTest::$test_directory_url
protected

Definition at line 49 of file ilBcryptPasswordEncoderTest.php.

Referenced by getTestDirectoryUrl(), and setTestDirectoryUrl().

◆ CLIENT_SALT

const ilBcryptPasswordEncoderTest::CLIENT_SALT = 'homer!12345_/'

Definition at line 34 of file ilBcryptPasswordEncoderTest.php.

◆ PASSWORD

const ilBcryptPasswordEncoderTest::PASSWORD = 'password'

Definition at line 24 of file ilBcryptPasswordEncoderTest.php.

◆ PASSWORD_SALT

const ilBcryptPasswordEncoderTest::PASSWORD_SALT = 'salt'

Definition at line 39 of file ilBcryptPasswordEncoderTest.php.

◆ VALID_COSTS

const ilBcryptPasswordEncoderTest::VALID_COSTS = '08'

Definition at line 19 of file ilBcryptPasswordEncoderTest.php.

◆ WRONG_PASSWORD

const ilBcryptPasswordEncoderTest::WRONG_PASSWORD = 'wrong_password'

Definition at line 29 of file ilBcryptPasswordEncoderTest.php.


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