4 require_once
'Services/Password/classes/encoders/class.ilBcryptPasswordEncoder.php';
64 return @include_once(
'vfsStream.php');
75 $this->
setTestDirectory(vfsStream::newDirectory(
'tests')->at(vfsStreamWrapper::getRoot()));
76 if(!defined(
'CLIENT_DATA_DIR'))
78 define(
'CLIENT_DATA_DIR', vfsStream::url(
'root/tests'));
81 else if(!defined(
'CLIENT_DATA_DIR'))
83 define(
'CLIENT_DATA_DIR',
'/tmp');
95 'ignore_security_flaw' =>
true 97 $this->assertTrue($security_flaw_ignoring_encoder->isSecurityFlawIgnored());
100 'ignore_security_flaw' =>
false 102 $this->assertFalse($security_flaw_respecting_encoder->isSecurityFlawIgnored());
105 'cost' => self::VALID_COSTS
107 $this->assertInstanceOf(
'ilBcryptPasswordEncoder', $encoder);
108 $this->assertEquals(self::VALID_COSTS, $encoder->getCosts());
109 $this->assertFalse($encoder->isSecurityFlawIgnored());
110 $encoder->setClientSalt(self::CLIENT_SALT);
120 $this->assertEquals(4, $encoder->
getCosts());
156 for($i = 4; $i <= 31; $i++)
168 $encoder->
setCosts(self::VALID_COSTS);
169 $encoded_password = $encoder->
encodePassword(self::PASSWORD, self::PASSWORD_SALT);
170 $this->assertTrue($encoder->
isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
171 $this->assertFalse($encoder->
isPasswordValid($encoded_password, self::WRONG_PASSWORD, self::PASSWORD_SALT));
181 $encoder->
setCosts(self::VALID_COSTS);
182 $encoder->
encodePassword(str_repeat(
'a', 5000), self::PASSWORD_SALT);
190 $encoder->
setCosts(self::VALID_COSTS);
191 $this->assertFalse($encoder->
isPasswordValid(
'encoded', str_repeat(
'a', 5000), self::PASSWORD_SALT));
200 $encoder->setClientSalt(null);
201 $encoder->setCosts(self::VALID_COSTS);
202 $encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
211 $encoder->setClientSalt(null);
212 $encoder->setCosts(self::VALID_COSTS);
213 $encoder->isPasswordValid(
'12121212', self::PASSWORD, self::PASSWORD_SALT);
227 $this->assertEquals(self::CLIENT_SALT, $encoder->getClientSalt());
236 $encoder->setBackwardCompatibility(
true);
237 $this->assertTrue($encoder->isBackwardCompatibilityEnabled());
238 $encoder->setBackwardCompatibility(
false);
239 $this->assertFalse($encoder->isBackwardCompatibilityEnabled());
250 $encoder->setClientSalt(self::CLIENT_SALT);
251 $encoder->setBackwardCompatibility(
true);
252 $encoded_password = $encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
253 $this->assertTrue($encoder->isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
254 $this->assertEquals(
'$2a$', substr($encoded_password, 0, 4));
257 $another_encoder->setClientSalt(self::CLIENT_SALT);
258 $another_encoder->setBackwardCompatibility(
false);
259 $another_encoded_password = $another_encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
260 $this->assertEquals(
'$2y$', substr($another_encoded_password, 0, 4));
261 $this->assertTrue($another_encoder->isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
269 if(version_compare(phpversion(),
'5.3.7',
'<'))
271 $this->markTestSkipped(
'Requires PHP >= 5.3.7');
282 $this->markTestSkipped(
'Requires vfsStream (http://vfs.bovigo.org)');
292 $encoder->setClientSalt(self::CLIENT_SALT);
293 $encoder->setBackwardCompatibility(
true);
294 $encoder->encodePassword(self::PASSWORD . chr(195), self::PASSWORD_SALT);
303 $encoder->setClientSalt(self::CLIENT_SALT);
304 $encoder->setBackwardCompatibility(
true);
305 $encoder->setIsSecurityFlawIgnored(
true);
306 $encoder->encodePassword(self::PASSWORD . chr(195), self::PASSWORD_SALT);
315 $this->assertEquals(
'bcrypt', $encoder->getName());
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} ...
testCostsCanBeRetrievedWhenCostsAreSet(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated
skipIfvfsStreamNotSupported()
setTestDirectory($test_directory)
testCostsCanBeSetInRange($costs, ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated costsProvider
testExceptionIsNotRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabledWithIgnoredSecurityFlaw()
testPasswordShouldBeCorrectlyEncodedAndVerified(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated
testInstanceCanBeCreatedAndInitializedWithClientSalt()
testExceptionIsRaisedIfSaltIsMissingIsOnEncoding()
ilPasswordException
testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated ilPasswordException
testBackwardCompatibility()
testExceptionIsRaisedIfSaltIsMissingIsOnVerification()
ilPasswordException
testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated
testBackwardCompatibilityCanBeRetrievedWhenBackwardCompatibilityIsSet()
testInstanceCanBeCreated()
skipIfPhpVersionIsNotSupported()
testExceptionIsRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabled()
ilPasswordException
testCostsCannotBeSetBelowRange(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated ilPasswordException
isPasswordValid($encoded, $raw, $salt)
{Checks a raw password against an encoded password.The raw password has to be injected into the encod...