ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilBcryptPasswordEncoderTest Class Reference
+ Inheritance diagram for ilBcryptPasswordEncoderTest:
+ Collaboration diagram for ilBcryptPasswordEncoderTest:

Public Member Functions

 getTestDirectory ()
 
 setTestDirectory ($test_directory)
 
 costsProvider ()
 
 testInstanceCanBeCreated ()
 
 testCostsCanBeRetrievedWhenCostsAreSet (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testCostsCannotBeSetAboveRange (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated ilPasswordException More...
 
 testCostsCannotBeSetBelowRange (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated ilPasswordException More...
 
 testCostsCanBeSetInRange ($costs, ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated costsProvider More...
 
 testPasswordShouldBeCorrectlyEncodedAndVerified (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated ilPasswordException More...
 
 testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testEncoderReliesOnSalts (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testEncoderDoesNotSupportReencoding (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testNameShouldBeBcrypt (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testExceptionIsRaisedIfSaltIsMissingIsOnEncoding ()
 ilPasswordException More...
 
 testExceptionIsRaisedIfSaltIsMissingIsOnVerification ()
 ilPasswordException More...
 
 testInstanceCanBeCreatedAndInitializedWithClientSalt ()
 
 testClientSaltIsGeneratedWhenNoClientSaltExistsYet ()
 
 testExceptionIsRaisedWhenClientSaltCouldNotBeGeneratedInCaseNoClientSaltExistsYet ()
 ilPasswordException More...
 
 testBackwardCompatibilityCanBeRetrievedWhenBackwardCompatibilityIsSet ()
 
 testBackwardCompatibility ()
 
 testExceptionIsRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabled ()
 ilPasswordException More...
 
 testExceptionIsNotRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabledWithIgnoredSecurityFlaw ()
 

Data Fields

const VALID_COSTS = '08'
 
const PASSWORD = 'password'
 
const WRONG_PASSWORD = 'wrong_password'
 
const CLIENT_SALT = 'homer!12345_/'
 
const PASSWORD_SALT = 'salt'
 

Protected Member Functions

 setUp ()
 Setup. More...
 
- Protected Member Functions inherited from ilPasswordBaseTest
 assertException ($exception_class)
 

Protected Attributes

 $test_directory
 

Private Member Functions

 skipIfPhpVersionIsNotSupported ()
 

Detailed Description

Definition at line 14 of file ilBcryptPasswordEncoderTest.php.

Member Function Documentation

◆ costsProvider()

ilBcryptPasswordEncoderTest::costsProvider ( )
Returns
array

Definition at line 92 of file ilBcryptPasswordEncoderTest.php.

References $data, and array.

93  {
94  $data = array();
95  for($i = 4; $i <= 31; $i++)
96  {
97  $data[] = array($i);
98  }
99  return $data;
100  }
Create styles array
The data for the language used.

◆ getTestDirectory()

ilBcryptPasswordEncoderTest::getTestDirectory ( )

◆ setTestDirectory()

ilBcryptPasswordEncoderTest::setTestDirectory (   $test_directory)
Parameters
vfs\vfsStreamDirectory$test_directory

Definition at line 57 of file ilBcryptPasswordEncoderTest.php.

References $test_directory.

Referenced by setUp().

58  {
59  $this->test_directory = $test_directory;
60  }
+ Here is the caller graph for this function:

◆ setUp()

ilBcryptPasswordEncoderTest::setUp ( )
protected

Setup.

Definition at line 65 of file ilBcryptPasswordEncoderTest.php.

References defined, and setTestDirectory().

66  {
67  vfs\vfsStream::setup();
68  $this->setTestDirectory(vfs\vfsStream::newDirectory('tests')->at(vfs\vfsStreamWrapper::getRoot()));
69 
70  if(!defined('CLIENT_DATA_DIR'))
71  {
72  define('CLIENT_DATA_DIR', vfs\vfsStream::url('root/tests'));
73  }
74 
75  parent::setUp();
76  }
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
+ Here is the call graph for this function:

◆ skipIfPhpVersionIsNotSupported()

ilBcryptPasswordEncoderTest::skipIfPhpVersionIsNotSupported ( )
private

Definition at line 81 of file ilBcryptPasswordEncoderTest.php.

Referenced by testBackwardCompatibility().

82  {
83  if(version_compare(phpversion(), '5.3.7', '<'))
84  {
85  $this->markTestSkipped('Requires PHP >= 5.3.7');
86  }
87  }
+ Here is the caller graph for this function:

◆ testBackwardCompatibility()

ilBcryptPasswordEncoderTest::testBackwardCompatibility ( )

Definition at line 294 of file ilBcryptPasswordEncoderTest.php.

References skipIfPhpVersionIsNotSupported().

295  {
297 
298  $encoder = new ilBcryptPasswordEncoder();
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));
304 
305  $another_encoder = new ilBcryptPasswordEncoder();
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));
311  }
+ Here is the call graph for this function:

◆ testBackwardCompatibilityCanBeRetrievedWhenBackwardCompatibilityIsSet()

ilBcryptPasswordEncoderTest::testBackwardCompatibilityCanBeRetrievedWhenBackwardCompatibilityIsSet ( )

Definition at line 282 of file ilBcryptPasswordEncoderTest.php.

283  {
284  $encoder = new ilBcryptPasswordEncoder();
285  $encoder->setBackwardCompatibility(true);
286  $this->assertTrue($encoder->isBackwardCompatibilityEnabled());
287  $encoder->setBackwardCompatibility(false);
288  $this->assertFalse($encoder->isBackwardCompatibilityEnabled());
289  }

◆ testClientSaltIsGeneratedWhenNoClientSaltExistsYet()

ilBcryptPasswordEncoderTest::testClientSaltIsGeneratedWhenNoClientSaltExistsYet ( )

Definition at line 260 of file ilBcryptPasswordEncoderTest.php.

References getTestDirectory().

261  {
262  $this->getTestDirectory()->chmod(0777);
263 
264  $encoder = new ilBcryptPasswordEncoder();
265  $this->assertNotNull($encoder->getClientSalt());
266  }
+ Here is the call graph for this function:

◆ testCostsCanBeRetrievedWhenCostsAreSet()

ilBcryptPasswordEncoderTest::testCostsCanBeRetrievedWhenCostsAreSet ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 130 of file ilBcryptPasswordEncoderTest.php.

References ilBcryptPhpPasswordEncoder\getCosts(), and ilBcryptPhpPasswordEncoder\setCosts().

131  {
132  $encoder->setCosts(4);
133  $this->assertEquals(4, $encoder->getCosts());
134  }
+ Here is the call graph for this function:

◆ testCostsCanBeSetInRange()

ilBcryptPasswordEncoderTest::testCostsCanBeSetInRange (   $costs,
ilBcryptPasswordEncoder  $encoder 
)

testInstanceCanBeCreated costsProvider

Definition at line 160 of file ilBcryptPasswordEncoderTest.php.

References ilBcryptPhpPasswordEncoder\setCosts().

161  {
162  $encoder->setCosts($costs);
163  }
+ Here is the call graph for this function:

◆ testCostsCannotBeSetAboveRange()

ilBcryptPasswordEncoderTest::testCostsCannotBeSetAboveRange ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated ilPasswordException

Definition at line 140 of file ilBcryptPasswordEncoderTest.php.

References ilPasswordBaseTest\assertException(), and ilBcryptPhpPasswordEncoder\setCosts().

141  {
142  $this->assertException(ilPasswordException::class);
143  $encoder->setCosts(32);
144  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testCostsCannotBeSetBelowRange()

ilBcryptPasswordEncoderTest::testCostsCannotBeSetBelowRange ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated ilPasswordException

Definition at line 150 of file ilBcryptPasswordEncoderTest.php.

References ilPasswordBaseTest\assertException(), and ilBcryptPhpPasswordEncoder\setCosts().

151  {
152  $this->assertException(ilPasswordException::class);
153  $encoder->setCosts(3);
154  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testEncoderDoesNotSupportReencoding()

ilBcryptPasswordEncoderTest::testEncoderDoesNotSupportReencoding ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 208 of file ilBcryptPasswordEncoderTest.php.

References ilBcryptPasswordEncoder\requiresReencoding().

209  {
210  $this->assertFalse($encoder->requiresReencoding('hello'));
211  }
requiresReencoding($encoded)
{Returns whether or not the a encoded password needs to be re-encoded.string boolean} ...
+ Here is the call graph for this function:

◆ testEncoderReliesOnSalts()

ilBcryptPasswordEncoderTest::testEncoderReliesOnSalts ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 200 of file ilBcryptPasswordEncoderTest.php.

References ilBcryptPasswordEncoder\requiresSalt().

201  {
202  $this->assertTrue($encoder->requiresSalt());
203  }
requiresSalt()
{Returns whether or not the encoder requires a salt.boolean}
+ Here is the call graph for this function:

◆ testExceptionIsNotRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabledWithIgnoredSecurityFlaw()

ilBcryptPasswordEncoderTest::testExceptionIsNotRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabledWithIgnoredSecurityFlaw ( )

Definition at line 328 of file ilBcryptPasswordEncoderTest.php.

329  {
330  $encoder = new ilBcryptPasswordEncoder();
331  $encoder->setClientSalt(self::CLIENT_SALT);
332  $encoder->setBackwardCompatibility(true);
333  $encoder->setIsSecurityFlawIgnored(true);
334  $encoder->encodePassword(self::PASSWORD . chr(195), self::PASSWORD_SALT);
335  }

◆ testExceptionIsRaisedIfSaltIsMissingIsOnEncoding()

ilBcryptPasswordEncoderTest::testExceptionIsRaisedIfSaltIsMissingIsOnEncoding ( )

ilPasswordException

Definition at line 224 of file ilBcryptPasswordEncoderTest.php.

References ilPasswordBaseTest\assertException().

225  {
226  $this->assertException(ilPasswordException::class);
227  $encoder = new ilBcryptPasswordEncoder();
228  $encoder->setClientSalt(null);
229  $encoder->setCosts(self::VALID_COSTS);
230  $encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
231  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfSaltIsMissingIsOnVerification()

ilBcryptPasswordEncoderTest::testExceptionIsRaisedIfSaltIsMissingIsOnVerification ( )

ilPasswordException

Definition at line 236 of file ilBcryptPasswordEncoderTest.php.

References ilPasswordBaseTest\assertException().

237  {
238  $this->assertException(ilPasswordException::class);
239  $encoder = new ilBcryptPasswordEncoder();
240  $encoder->setClientSalt(null);
241  $encoder->setCosts(self::VALID_COSTS);
242  $encoder->isPasswordValid('12121212', self::PASSWORD, self::PASSWORD_SALT);
243  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding()

ilBcryptPasswordEncoderTest::testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated ilPasswordException

Definition at line 181 of file ilBcryptPasswordEncoderTest.php.

References ilPasswordBaseTest\assertException(), ilBcryptPasswordEncoder\encodePassword(), and ilBcryptPhpPasswordEncoder\setCosts().

182  {
183  $this->assertException(ilPasswordException::class);
184  $encoder->setCosts(self::VALID_COSTS);
185  $encoder->encodePassword(str_repeat('a', 5000), self::PASSWORD_SALT);
186  }
encodePassword($raw, $salt)
{Encodes the raw password.The password to encode The salt string The encoded password} ...
assertException($exception_class)
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabled()

ilBcryptPasswordEncoderTest::testExceptionIsRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabled ( )

ilPasswordException

Definition at line 316 of file ilBcryptPasswordEncoderTest.php.

References ilPasswordBaseTest\assertException().

317  {
318  $this->assertException(ilPasswordException::class);
319  $encoder = new ilBcryptPasswordEncoder();
320  $encoder->setClientSalt(self::CLIENT_SALT);
321  $encoder->setBackwardCompatibility(true);
322  $encoder->encodePassword(self::PASSWORD . chr(195), self::PASSWORD_SALT);
323  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testExceptionIsRaisedWhenClientSaltCouldNotBeGeneratedInCaseNoClientSaltExistsYet()

ilBcryptPasswordEncoderTest::testExceptionIsRaisedWhenClientSaltCouldNotBeGeneratedInCaseNoClientSaltExistsYet ( )

ilPasswordException

Definition at line 271 of file ilBcryptPasswordEncoderTest.php.

References ilPasswordBaseTest\assertException(), and getTestDirectory().

272  {
273  $this->assertException(ilPasswordException::class);
274  $this->getTestDirectory()->chmod(0000);
275 
276  $encoder = new ilBcryptPasswordEncoder();
277  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testInstanceCanBeCreated()

ilBcryptPasswordEncoderTest::testInstanceCanBeCreated ( )
Returns
ilBcryptPasswordEncoder

Definition at line 105 of file ilBcryptPasswordEncoderTest.php.

References array.

106  {
107  $security_flaw_ignoring_encoder = new ilBcryptPasswordEncoder(array(
108  'ignore_security_flaw' => true
109  ));
110  $this->assertTrue($security_flaw_ignoring_encoder->isSecurityFlawIgnored());
111 
112  $security_flaw_respecting_encoder = new ilBcryptPasswordEncoder(array(
113  'ignore_security_flaw' => false
114  ));
115  $this->assertFalse($security_flaw_respecting_encoder->isSecurityFlawIgnored());
116 
117  $encoder = new ilBcryptPasswordEncoder(array(
118  'cost' => self::VALID_COSTS
119  ));
120  $this->assertInstanceOf('ilBcryptPasswordEncoder', $encoder);
121  $this->assertEquals(self::VALID_COSTS, $encoder->getCosts());
122  $this->assertFalse($encoder->isSecurityFlawIgnored());
123  $encoder->setClientSalt(self::CLIENT_SALT);
124  return $encoder;
125  }
Create styles array
The data for the language used.

◆ testInstanceCanBeCreatedAndInitializedWithClientSalt()

ilBcryptPasswordEncoderTest::testInstanceCanBeCreatedAndInitializedWithClientSalt ( )

Definition at line 248 of file ilBcryptPasswordEncoderTest.php.

References getTestDirectory(), and ilBcryptPasswordEncoder\SALT_STORAGE_FILENAME.

249  {
250  $this->getTestDirectory()->chmod(0777);
251  vfs\vfsStream::newFile(ilBcryptPasswordEncoder::SALT_STORAGE_FILENAME)->withContent(self::CLIENT_SALT)->at($this->getTestDirectory());
252 
253  $encoder = new ilBcryptPasswordEncoder();
254  $this->assertEquals(self::CLIENT_SALT, $encoder->getClientSalt());
255  }
+ Here is the call graph for this function:

◆ testNameShouldBeBcrypt()

ilBcryptPasswordEncoderTest::testNameShouldBeBcrypt ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 216 of file ilBcryptPasswordEncoderTest.php.

References ilBcryptPasswordEncoder\getName().

217  {
218  $this->assertEquals('bcrypt', $encoder->getName());
219  }
getName()
{Returns a unique name/id of the concrete password encoder.string}
+ Here is the call graph for this function:

◆ testPasswordShouldBeCorrectlyEncodedAndVerified()

ilBcryptPasswordEncoderTest::testPasswordShouldBeCorrectlyEncodedAndVerified ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 168 of file ilBcryptPasswordEncoderTest.php.

References ilBcryptPasswordEncoder\encodePassword(), ilBcryptPasswordEncoder\isPasswordValid(), and ilBcryptPhpPasswordEncoder\setCosts().

169  {
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));
174  return $encoder;
175  }
encodePassword($raw, $salt)
{Encodes the raw password.The password to encode The salt string The encoded password} ...
isPasswordValid($encoded, $raw, $salt)
{Checks a raw password against an encoded password.The raw password has to be injected into the encod...
+ Here is the call graph for this function:

◆ testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength()

ilBcryptPasswordEncoderTest::testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 191 of file ilBcryptPasswordEncoderTest.php.

References ilBcryptPasswordEncoder\isPasswordValid(), and ilBcryptPhpPasswordEncoder\setCosts().

192  {
193  $encoder->setCosts(self::VALID_COSTS);
194  $this->assertFalse($encoder->isPasswordValid('encoded', str_repeat('a', 5000), self::PASSWORD_SALT));
195  }
isPasswordValid($encoded, $raw, $salt)
{Checks a raw password against an encoded password.The raw password has to be injected into the encod...
+ Here is the call graph for this function:

Field Documentation

◆ $test_directory

ilBcryptPasswordEncoderTest::$test_directory
protected

Definition at line 44 of file ilBcryptPasswordEncoderTest.php.

Referenced by getTestDirectory(), and setTestDirectory().

◆ CLIENT_SALT

const ilBcryptPasswordEncoderTest::CLIENT_SALT = 'homer!12345_/'

Definition at line 34 of file ilBcryptPasswordEncoderTest.php.

◆ PASSWORD

const ilBcryptPasswordEncoderTest::PASSWORD = 'password'

Definition at line 24 of file ilBcryptPasswordEncoderTest.php.

◆ PASSWORD_SALT

const ilBcryptPasswordEncoderTest::PASSWORD_SALT = 'salt'

Definition at line 39 of file ilBcryptPasswordEncoderTest.php.

◆ VALID_COSTS

const ilBcryptPasswordEncoderTest::VALID_COSTS = '08'

Definition at line 19 of file ilBcryptPasswordEncoderTest.php.

◆ WRONG_PASSWORD

const ilBcryptPasswordEncoderTest::WRONG_PASSWORD = 'wrong_password'

Definition at line 29 of file ilBcryptPasswordEncoderTest.php.


The documentation for this class was generated from the following file: