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 define(
'CLIENT_DATA_DIR', vfsStream::url(
'root/tests'));
87 'ignore_security_flaw' =>
true
89 $this->assertTrue($security_flaw_ignoring_encoder->isSecurityFlawIgnored());
92 'ignore_security_flaw' =>
false
94 $this->assertFalse($security_flaw_respecting_encoder->isSecurityFlawIgnored());
97 'cost' => self::VALID_COSTS
99 $this->assertInstanceOf(
'ilBcryptPasswordEncoder', $encoder);
100 $this->assertEquals(self::VALID_COSTS, $encoder->getCosts());
101 $this->assertFalse($encoder->isSecurityFlawIgnored());
102 $encoder->setClientSalt(self::CLIENT_SALT);
112 $this->assertEquals(4, $encoder->
getCosts());
148 for($i = 4; $i <= 31; $i++)
160 $encoder->
setCosts(self::VALID_COSTS);
161 $encoded_password = $encoder->
encodePassword(self::PASSWORD, self::PASSWORD_SALT);
162 $this->assertTrue($encoder->
isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
163 $this->assertFalse($encoder->
isPasswordValid($encoded_password, self::WRONG_PASSWORD, self::PASSWORD_SALT));
173 $encoder->
setCosts(self::VALID_COSTS);
174 $encoder->
encodePassword(str_repeat(
'a', 5000), self::PASSWORD_SALT);
182 $encoder->
setCosts(self::VALID_COSTS);
183 $this->assertFalse($encoder->
isPasswordValid(
'encoded', str_repeat(
'a', 5000), self::PASSWORD_SALT));
192 $encoder->setClientSalt(null);
193 $encoder->setCosts(self::VALID_COSTS);
194 $encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
203 $encoder->setClientSalt(null);
204 $encoder->setCosts(self::VALID_COSTS);
205 $encoder->isPasswordValid(
'12121212', self::PASSWORD, self::PASSWORD_SALT);
216 $this->assertNull($encoder->getClientSalt());
221 $encoder->onSelection();
222 $this->fail(
'An expected exception has not been raised.');
226 $this->assertNull($encoder->getClientSalt());
241 $this->assertNull($encoder->getClientSalt());
243 $encoder->onSelection();
245 $this->assertNotNull($encoder->getClientSalt());
260 $this->assertEquals(self::CLIENT_SALT, $encoder->getClientSalt());
269 $encoder->setBackwardCompatibility(
true);
270 $this->assertTrue($encoder->isBackwardCompatibilityEnabled());
271 $encoder->setBackwardCompatibility(
false);
272 $this->assertFalse($encoder->isBackwardCompatibilityEnabled());
283 $encoder->setClientSalt(self::CLIENT_SALT);
284 $encoder->setBackwardCompatibility(
true);
285 $encoded_password = $encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
286 $this->assertTrue($encoder->isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
287 $this->assertEquals(
'$2a$', substr($encoded_password, 0, 4));
290 $another_encoder->setClientSalt(self::CLIENT_SALT);
291 $another_encoder->setBackwardCompatibility(
false);
292 $another_encoded_password = $another_encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
293 $this->assertEquals(
'$2y$', substr($another_encoded_password, 0, 4));
294 $this->assertTrue($another_encoder->isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
302 if(version_compare(phpversion(),
'5.3.7',
'<'))
304 $this->markTestSkipped(
'Requires PHP >= 5.3.7');
315 $this->markTestSkipped(
'Requires vfsStream (http://vfs.bovigo.org)');
325 $encoder->setClientSalt(self::CLIENT_SALT);
326 $encoder->setBackwardCompatibility(
true);
327 $encoder->encodePassword(self::PASSWORD . chr(195), self::PASSWORD_SALT);
336 $encoder->setClientSalt(self::CLIENT_SALT);
337 $encoder->setBackwardCompatibility(
true);
338 $encoder->setIsSecurityFlawIgnored(
true);
339 $encoder->encodePassword(self::PASSWORD . chr(195), self::PASSWORD_SALT);
348 $this->assertEquals(
'bcrypt', $encoder->getName());