4require_once
'Services/Password/classes/encoders/class.ilBcryptPasswordEncoder.php';
5require_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);
An exception for terminatinating execution or to throw for unit testing.
testClientSaltIsGeneratedWhenNoClientSaltExistsYet()
testInstanceCanBeCreatedAndInitializedWithClientSalt()
testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength(ilBcryptPasswordEncoder $encoder)
@depends testInstanceCanBeCreated
skipIfPhpVersionIsNotSupported()
testPasswordShouldBeCorrectlyEncodedAndVerified(ilBcryptPasswordEncoder $encoder)
@depends testInstanceCanBeCreated
setTestDirectory($test_directory)
testCostsCanBeRetrievedWhenCostsAreSet(ilBcryptPasswordEncoder $encoder)
@depends testInstanceCanBeCreated
testBackwardCompatibilityCanBeRetrievedWhenBackwardCompatibilityIsSet()
testCostsCannotBeSetBelowRange(ilBcryptPasswordEncoder $encoder)
@depends testInstanceCanBeCreated @expectedException ilPasswordException
testCostsCanBeSetInRange($costs, ilBcryptPasswordEncoder $encoder)
@depends testInstanceCanBeCreated @dataProvider costsProvider
testExceptionIsRaisedIfSaltIsMissingIsOnEncoding()
@expectedException ilPasswordException
testExceptionIsRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabled()
@expectedException ilPasswordException
testInstanceCanBeCreated()
testExceptionIsRaisedIfSaltIsMissingIsOnVerification()
@expectedException ilPasswordException
testExceptionIsNotRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabledWithIgnoredSecurityFlaw()
testEncoderReliesOnSalts(ilBcryptPasswordEncoder $encoder)
@depends testInstanceCanBeCreated
testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding(ilBcryptPasswordEncoder $encoder)
@depends testInstanceCanBeCreated @expectedException ilPasswordException
testBackwardCompatibility()
testEncoderDoesNotSupportReencoding(ilBcryptPasswordEncoder $encoder)
@depends testInstanceCanBeCreated
testCostsCannotBeSetAboveRange(ilBcryptPasswordEncoder $encoder)
@depends testInstanceCanBeCreated @expectedException ilPasswordException
testNameShouldBeBcrypt(ilBcryptPasswordEncoder $encoder)
@depends testInstanceCanBeCreated
testExceptionIsRaisedWhenClientSaltCouldNotBeGeneratedInCaseNoClientSaltExistsYet()
@expectedException ilPasswordException
const SALT_STORAGE_FILENAME
encodePassword($raw, $salt)
{{Encodes the raw password.string The encoded password}}
requiresReencoding($encoded)
{{{Returns whether or not the a encoded password needs to be re-encoded.boolean}}}
isPasswordValid($encoded, $raw, $salt)
{{Checks a raw password against an encoded password.The raw password has to be injected into the enco...
requiresSalt()
{{Returns whether or not the encoder requires a salt.boolean}}
assertException($exception_class)
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'