19 declare(strict_types=1);
    70         return class_exists(
'org\bovigo\vfs\vfsStreamWrapper');
    76             $this->markTestSkipped(
'Skipped test, vfsStream (https://github.com/bovigo/vfsStream) required');
    78             vfs\vfsStream::setup();
    79             $this->
setTestDirectory(vfs\vfsStream::newDirectory(
'tests')->at(vfs\vfsStreamWrapper::getRoot()));
    90         for ($i = 4; $i <= 31; ++$i) {
    91             $data[sprintf(
'Costs: %s', $i)] = [(string) $i];
   100             'data_directory' => $this->testDirectoryUrl
   109             'ignore_security_flaw' => 
true,
   110             'data_directory' => $this->testDirectoryUrl
   112         $this->assertTrue($security_flaw_ignoring_encoder->isSecurityFlawIgnored());
   115             'ignore_security_flaw' => 
false,
   116             'data_directory' => $this->testDirectoryUrl
   118         $this->assertFalse($security_flaw_respecting_encoder->isSecurityFlawIgnored());
   121             'cost' => self::VALID_COSTS,
   122             'data_directory' => $this->testDirectoryUrl
   124         $this->assertInstanceOf(ilBcryptPasswordEncoder::class, $encoder);
   125         $this->assertSame(self::VALID_COSTS, $encoder->getCosts());
   126         $this->assertFalse($encoder->isSecurityFlawIgnored());
   127         $encoder->setClientSalt(self::CLIENT_SALT);
   141         $this->assertSame($expected, $encoder->
getCosts());
   150         $this->expectException(ilPasswordException::class);
   160         $this->expectException(ilPasswordException::class);
   182         $encoder->
setCosts(self::VALID_COSTS);
   183         $encoded_password = $encoder->
encodePassword(self::PASSWORD, self::PASSWORD_SALT);
   184         $this->assertTrue($encoder->
isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
   185         $this->assertFalse($encoder->
isPasswordValid($encoded_password, self::WRONG_PASSWORD, self::PASSWORD_SALT));
   197         $this->expectException(ilPasswordException::class);
   198         $encoder->
setCosts(self::VALID_COSTS);
   199         $encoder->
encodePassword(str_repeat(
'a', 5000), self::PASSWORD_SALT);
   209         $encoder->
setCosts(self::VALID_COSTS);
   210         $this->assertFalse($encoder->
isPasswordValid(
'encoded', str_repeat(
'a', 5000), self::PASSWORD_SALT));
   234         $this->assertSame(
'bcrypt', $encoder->
getName());
   241         $this->expectException(ilPasswordException::class);
   243         $encoder->setClientSalt(null);
   244         $encoder->setCosts(self::VALID_COSTS);
   245         $encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
   252         $this->expectException(ilPasswordException::class);
   254         $encoder->setClientSalt(null);
   255         $encoder->setCosts(self::VALID_COSTS);
   256         $encoder->isPasswordValid(
'12121212', self::PASSWORD, self::PASSWORD_SALT);
   263         $this->testDirectory->chmod(0777);
   267         $this->assertSame(self::CLIENT_SALT, $encoder->getClientSalt());
   274         $this->testDirectory->chmod(0777);
   277         $this->assertNotNull($encoder->getClientSalt());
   284         $this->expectException(ilPasswordException::class);
   285         $this->testDirectory->chmod(0000);
   295         $encoder->setBackwardCompatibility(
true);
   296         $this->assertTrue($encoder->isBackwardCompatibilityEnabled());
   297         $encoder->setBackwardCompatibility(
false);
   298         $this->assertFalse($encoder->isBackwardCompatibilityEnabled());
   306         $encoder->setClientSalt(self::CLIENT_SALT);
   307         $encoder->setBackwardCompatibility(
true);
   309         $encoded_password = $encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
   310         $this->assertTrue($encoder->isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
   311         $this->assertSame(
'$2a$', substr($encoded_password, 0, 4));
   314         $another_encoder->setClientSalt(self::CLIENT_SALT);
   316         $another_encoder->setBackwardCompatibility(
false);
   317         $another_encoded_password = $another_encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
   318         $this->assertSame(
'$2y$', substr($another_encoded_password, 0, 4));
   319         $this->assertTrue($another_encoder->isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
   326         $this->expectException(ilPasswordException::class);
   328         $encoder->setClientSalt(self::CLIENT_SALT);
   329         $encoder->setBackwardCompatibility(
true);
   330         $encoder->encodePassword(self::PASSWORD . chr(195), self::PASSWORD_SALT);
   342         $encoder->setClientSalt(self::CLIENT_SALT);
   343         $encoder->setBackwardCompatibility(
true);
   344         $encoder->setIsSecurityFlawIgnored(
true);
   345         $encoder->encodePassword(self::PASSWORD . chr(195), self::PASSWORD_SALT);
 const SALT_STORAGE_FILENAME
 
testExceptionIfPasswordsContainA8BitCharacterAndBackwardCompatibilityIsEnabled()
 
testCostsCannotBeSetAboveRange(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated 
 
requiresSalt()
Returns whether the encoder requires a salt. 
 
testCostsCanBeRetrievedWhenCostsAreSet(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated 
 
skipIfvfsStreamNotSupported()
 
getInstanceWithConfiguredDataDirectory()
 
testClientSaltIsGeneratedWhenNoClientSaltExistsYet()
 
encodePassword(string $raw, string $salt)
Encodes the raw password. 
 
testEncoderDoesNotSupportReencoding(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated 
 
setTestDirectory(vfs\vfsStreamDirectory $testDirectory)
 
testPasswordShouldBeCorrectlyEncodedAndVerified(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated 
 
testInstanceCanBeCreatedAndInitializedWithClientSalt()
 
testExceptionIsRaisedIfSaltIsMissingIsOnEncoding()
 
vfs vfsStreamDirectory $testDirectory
 
testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated 
 
requiresReencoding(string $encoded)
Returns whether the encoded password needs to be re-encoded. 
 
testBackwardCompatibility()
 
testExceptionIsRaisedIfSaltIsMissingIsOnVerification()
 
testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated 
 
testBackwardCompatibilityCanBeRetrievedWhenBackwardCompatibilityIsSet()
 
testCostsCanBeSetInRange(string $costs, ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated  costsProvider 
 
testInstanceCanBeCreated()
 
getName()
Returns a unique name/id of the concrete password encoder. 
 
testExceptionIsRaisedWhenClientSaltCouldNotBeGeneratedInCaseNoClientSaltExistsYet()
 
testCostsCannotBeSetBelowRange(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated 
 
testNameShouldBeBcrypt(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated 
 
testEncoderReliesOnSalts(ilBcryptPasswordEncoder $encoder)
testInstanceCanBeCreated 
 
setTestDirectoryUrl(string $testDirectoryUrl)
 
isPasswordValid(string $encoded, string $raw, string $salt)
Checks a raw password against an encoded password. 
 
testNoExceptionIfPasswordsContainA8BitCharacterAndBackwardCompatibilityIsEnabledWithIgnoredSecurityFlaw()