4 require_once
'Services/Password/classes/encoders/class.ilBcryptPasswordEncoder.php';
5 require_once
'Services/Password/test/ilPasswordBaseTest.php';
67 vfs\vfsStream::setup();
68 $this->
setTestDirectory(vfs\vfsStream::newDirectory(
'tests')->at(vfs\vfsStreamWrapper::getRoot()));
72 define(
'CLIENT_DATA_DIR', vfs\vfsStream::url(
'root/tests'));
83 if(version_compare(phpversion(),
'5.3.7',
'<'))
85 $this->markTestSkipped(
'Requires PHP >= 5.3.7');
95 for($i = 4; $i <= 31; $i++)
108 'ignore_security_flaw' =>
true 110 $this->assertTrue($security_flaw_ignoring_encoder->isSecurityFlawIgnored());
113 'ignore_security_flaw' =>
false 115 $this->assertFalse($security_flaw_respecting_encoder->isSecurityFlawIgnored());
118 'cost' => self::VALID_COSTS
120 $this->assertInstanceOf(
'ilBcryptPasswordEncoder', $encoder);
121 $this->assertEquals(self::VALID_COSTS, $encoder->getCosts());
122 $this->assertFalse($encoder->isSecurityFlawIgnored());
123 $encoder->setClientSalt(self::CLIENT_SALT);
133 $this->assertEquals(4, $encoder->
getCosts());
170 $encoder->
setCosts(self::VALID_COSTS);
171 $encoded_password = $encoder->
encodePassword(self::PASSWORD, self::PASSWORD_SALT);
172 $this->assertTrue($encoder->
isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
173 $this->assertFalse($encoder->
isPasswordValid($encoded_password, self::WRONG_PASSWORD, self::PASSWORD_SALT));
184 $encoder->
setCosts(self::VALID_COSTS);
185 $encoder->
encodePassword(str_repeat(
'a', 5000), self::PASSWORD_SALT);
193 $encoder->
setCosts(self::VALID_COSTS);
194 $this->assertFalse($encoder->
isPasswordValid(
'encoded', str_repeat(
'a', 5000), self::PASSWORD_SALT));
218 $this->assertEquals(
'bcrypt', $encoder->
getName());
228 $encoder->setClientSalt(null);
229 $encoder->setCosts(self::VALID_COSTS);
230 $encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
240 $encoder->setClientSalt(null);
241 $encoder->setCosts(self::VALID_COSTS);
242 $encoder->isPasswordValid(
'12121212', self::PASSWORD, self::PASSWORD_SALT);
254 $this->assertEquals(self::CLIENT_SALT, $encoder->getClientSalt());
265 $this->assertNotNull($encoder->getClientSalt());
285 $encoder->setBackwardCompatibility(
true);
286 $this->assertTrue($encoder->isBackwardCompatibilityEnabled());
287 $encoder->setBackwardCompatibility(
false);
288 $this->assertFalse($encoder->isBackwardCompatibilityEnabled());
299 $encoder->setClientSalt(self::CLIENT_SALT);
300 $encoder->setBackwardCompatibility(
true);
301 $encoded_password = $encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
302 $this->assertTrue($encoder->isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
303 $this->assertEquals(
'$2a$', substr($encoded_password, 0, 4));
306 $another_encoder->setClientSalt(self::CLIENT_SALT);
307 $another_encoder->setBackwardCompatibility(
false);
308 $another_encoded_password = $another_encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
309 $this->assertEquals(
'$2y$', substr($another_encoded_password, 0, 4));
310 $this->assertTrue($another_encoder->isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
320 $encoder->setClientSalt(self::CLIENT_SALT);
321 $encoder->setBackwardCompatibility(
true);
322 $encoder->encodePassword(self::PASSWORD . chr(195), self::PASSWORD_SALT);
331 $encoder->setClientSalt(self::CLIENT_SALT);
332 $encoder->setBackwardCompatibility(
true);
333 $encoder->setIsSecurityFlawIgnored(
true);
334 $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
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} ...
testExceptionIsNotRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabledWithIgnoredSecurityFlaw()
testPasswordShouldBeCorrectlyEncodedAndVerified(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated
testInstanceCanBeCreatedAndInitializedWithClientSalt()
testExceptionIsRaisedIfSaltIsMissingIsOnEncoding()
ilPasswordException
testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated ilPasswordException
testBackwardCompatibility()
testExceptionIsRaisedIfSaltIsMissingIsOnVerification()
ilPasswordException
testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated
Create styles array
The data for the language used.
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...
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
assertException($exception_class)