4 require_once
'Services/Password/classes/encoders/class.ilBcryptPasswordEncoder.php';
5 require_once
'Services/Password/test/ilPasswordBaseTest.php';
88 vfs\vfsStream::setup();
89 $this->
setTestDirectory(vfs\vfsStream::newDirectory(
'tests')->at(vfs\vfsStreamWrapper::getRoot()));
100 if (version_compare(phpversion(),
'5.3.7',
'<')) {
101 $this->markTestSkipped(
'Requires PHP >= 5.3.7');
111 for (
$i = 4;
$i <= 31;
$i++) {
135 'ignore_security_flaw' =>
true,
138 $this->assertTrue($security_flaw_ignoring_encoder->isSecurityFlawIgnored());
141 'ignore_security_flaw' =>
false,
144 $this->assertFalse($security_flaw_respecting_encoder->isSecurityFlawIgnored());
147 'cost' => self::VALID_COSTS,
150 $this->assertInstanceOf(
'ilBcryptPasswordEncoder', $encoder);
151 $this->assertEquals(self::VALID_COSTS, $encoder->getCosts());
152 $this->assertFalse($encoder->isSecurityFlawIgnored());
153 $encoder->setClientSalt(self::CLIENT_SALT);
164 $this->assertEquals(4, $encoder->
getCosts());
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));
215 $encoder->
setCosts(self::VALID_COSTS);
216 $encoder->
encodePassword(str_repeat(
'a', 5000), self::PASSWORD_SALT);
224 $encoder->
setCosts(self::VALID_COSTS);
225 $this->assertFalse($encoder->
isPasswordValid(
'encoded', str_repeat(
'a', 5000), self::PASSWORD_SALT));
249 $this->assertEquals(
'bcrypt', $encoder->
getName());
259 $encoder->setClientSalt(null);
260 $encoder->setCosts(self::VALID_COSTS);
261 $encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
271 $encoder->setClientSalt(null);
272 $encoder->setCosts(self::VALID_COSTS);
273 $encoder->isPasswordValid(
'12121212', self::PASSWORD, self::PASSWORD_SALT);
285 $this->assertEquals(self::CLIENT_SALT, $encoder->getClientSalt());
296 $this->assertNotNull($encoder->getClientSalt());
316 $encoder->setBackwardCompatibility(
true);
317 $this->assertTrue($encoder->isBackwardCompatibilityEnabled());
318 $encoder->setBackwardCompatibility(
false);
319 $this->assertFalse($encoder->isBackwardCompatibilityEnabled());
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));
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));
351 $encoder->setClientSalt(self::CLIENT_SALT);
352 $encoder->setBackwardCompatibility(
true);
353 $encoder->encodePassword(self::PASSWORD . chr(195), self::PASSWORD_SALT);
362 $encoder->setClientSalt(self::CLIENT_SALT);
363 $encoder->setBackwardCompatibility(
true);
364 $encoder->setIsSecurityFlawIgnored(
true);
365 $encoder->encodePassword(self::PASSWORD . chr(195), self::PASSWORD_SALT);
const SALT_STORAGE_FILENAME
testCostsCannotBeSetAboveRange(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated ilPasswordException
encodePassword($raw, $salt)
{Encodes the raw password.The password to encode The salt string The encoded password} ...
requiresSalt()
{Returns whether or not the encoder requires a salt.boolean}
testCostsCanBeRetrievedWhenCostsAreSet(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated
getInstanceWithConfiguredDataDirectory()
testClientSaltIsGeneratedWhenNoClientSaltExistsYet()
testEncoderDoesNotSupportReencoding(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated
setTestDirectory($test_directory)
testCostsCanBeSetInRange($costs, ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated costsProvider
requiresReencoding($encoded)
{Returns whether or not the a encoded password needs to be re-encoded.string boolean} ...
setTestDirectoryUrl($test_directory_url)
testExceptionIsNotRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabledWithIgnoredSecurityFlaw()
testPasswordShouldBeCorrectlyEncodedAndVerified(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated
testInstanceCanBeCreatedAndInitializedWithClientSalt()
testExceptionIsRaisedIfSaltIsMissingIsOnEncoding()
ilPasswordException
testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated ilPasswordException
testBackwardCompatibility()
testExceptionIsRaisedIfSaltIsMissingIsOnVerification()
ilPasswordException
testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated
testBackwardCompatibilityCanBeRetrievedWhenBackwardCompatibilityIsSet()
testInstanceCanBeCreated()
getName()
{Returns a unique name/id of the concrete password encoder.string}
skipIfPhpVersionIsNotSupported()
testExceptionIsRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabled()
ilPasswordException
testExceptionIsRaisedWhenClientSaltCouldNotBeGeneratedInCaseNoClientSaltExistsYet()
ilPasswordException
testCostsCannotBeSetBelowRange(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated ilPasswordException
testNameShouldBeBcrypt(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated
testEncoderReliesOnSalts(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated
isPasswordValid($encoded, $raw, $salt)
{Checks a raw password against an encoded password.The raw password has to be injected into the encod...
assertException($exception_class)