ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
ilBcryptPasswordEncoderTest Class Reference
+ Inheritance diagram for ilBcryptPasswordEncoderTest:
+ Collaboration diagram for ilBcryptPasswordEncoderTest:

Public Member Functions

 getTestDirectory ()
 
 setTestDirectory ($test_directory)
 
 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...
 
 costsProvider ()
 
 testPasswordShouldBeCorrectlyEncodedAndVerified (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated ilPasswordException More...
 
 testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated More...
 
 testExceptionIsRaisedIfSaltIsMissingIsOnEncoding ()
 ilPasswordException More...
 
 testExceptionIsRaisedIfSaltIsMissingIsOnVerification ()
 ilPasswordException More...
 
 testInstanceCanBeCreatedAndInitializedWithClientSalt ()
 
 testBackwardCompatibilityCanBeRetrievedWhenBackwardCompatibilityIsSet ()
 
 testBackwardCompatibility ()
 
 testExceptionIsRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabled ()
 ilPasswordException More...
 
 testExceptionIsNotRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabledWithIgnoredSecurityFlaw ()
 
 testNameShouldBeBcrypt ()
 

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 Attributes

 $test_directory
 

Private Member Functions

 isVsfStreamInstalled ()
 
 skipIfPhpVersionIsNotSupported ()
 
 skipIfvfsStreamNotSupported ()
 

Detailed Description

Definition at line 11 of file ilBcryptPasswordEncoderTest.php.

Member Function Documentation

◆ costsProvider()

ilBcryptPasswordEncoderTest::costsProvider ( )
Returns
array

Definition at line 153 of file ilBcryptPasswordEncoderTest.php.

References $data.

154  {
155  $data = array();
156  for($i = 4; $i <= 31; $i++)
157  {
158  $data[] = array($i);
159  }
160  return $data;
161  }
$data

◆ getTestDirectory()

ilBcryptPasswordEncoderTest::getTestDirectory ( )
Returns
vfsStreamDirectory

Definition at line 46 of file ilBcryptPasswordEncoderTest.php.

References $test_directory.

Referenced by testInstanceCanBeCreatedAndInitializedWithClientSalt().

+ Here is the caller graph for this function:

◆ isVsfStreamInstalled()

ilBcryptPasswordEncoderTest::isVsfStreamInstalled ( )
private
Returns
bool

Definition at line 62 of file ilBcryptPasswordEncoderTest.php.

Referenced by setUp(), and skipIfvfsStreamNotSupported().

63  {
64  return @include_once('vfsStream.php');
65  }
+ Here is the caller graph for this function:

◆ setTestDirectory()

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

Definition at line 54 of file ilBcryptPasswordEncoderTest.php.

References $test_directory.

Referenced by setUp().

55  {
56  $this->test_directory = $test_directory;
57  }
+ Here is the caller graph for this function:

◆ setUp()

ilBcryptPasswordEncoderTest::setUp ( )
protected

Setup.

Definition at line 70 of file ilBcryptPasswordEncoderTest.php.

References isVsfStreamInstalled(), and setTestDirectory().

71  {
72  if($this->isVsfStreamInstalled())
73  {
74  vfsStream::setup();
75  $this->setTestDirectory(vfsStream::newDirectory('tests')->at(vfsStreamWrapper::getRoot()));
76  if(!defined('CLIENT_DATA_DIR'))
77  {
78  define('CLIENT_DATA_DIR', vfsStream::url('root/tests'));
79  }
80  }
81  else if(!defined('CLIENT_DATA_DIR'))
82  {
83  define('CLIENT_DATA_DIR', '/tmp');
84  }
85 
86  parent::setUp();
87  }
+ Here is the call graph for this function:

◆ skipIfPhpVersionIsNotSupported()

ilBcryptPasswordEncoderTest::skipIfPhpVersionIsNotSupported ( )
private

Definition at line 267 of file ilBcryptPasswordEncoderTest.php.

Referenced by testBackwardCompatibility().

268  {
269  if(version_compare(phpversion(), '5.3.7', '<'))
270  {
271  $this->markTestSkipped('Requires PHP >= 5.3.7');
272  }
273  }
+ Here is the caller graph for this function:

◆ skipIfvfsStreamNotSupported()

ilBcryptPasswordEncoderTest::skipIfvfsStreamNotSupported ( )
private

Definition at line 278 of file ilBcryptPasswordEncoderTest.php.

References isVsfStreamInstalled().

Referenced by testInstanceCanBeCreatedAndInitializedWithClientSalt().

279  {
280  if(!$this->isVsfStreamInstalled())
281  {
282  $this->markTestSkipped('Requires vfsStream (http://vfs.bovigo.org)');
283  }
284  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testBackwardCompatibility()

ilBcryptPasswordEncoderTest::testBackwardCompatibility ( )

Definition at line 245 of file ilBcryptPasswordEncoderTest.php.

References skipIfPhpVersionIsNotSupported().

246  {
248 
249  $encoder = new ilBcryptPasswordEncoder();
250  $encoder->setClientSalt(self::CLIENT_SALT);
251  $encoder->setBackwardCompatibility(true);
252  $encoded_password = $encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
253  $this->assertTrue($encoder->isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
254  $this->assertEquals('$2a$', substr($encoded_password, 0, 4));
255 
256  $another_encoder = new ilBcryptPasswordEncoder();
257  $another_encoder->setClientSalt(self::CLIENT_SALT);
258  $another_encoder->setBackwardCompatibility(false);
259  $another_encoded_password = $another_encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
260  $this->assertEquals('$2y$', substr($another_encoded_password, 0, 4));
261  $this->assertTrue($another_encoder->isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
262  }
+ Here is the call graph for this function:

◆ testBackwardCompatibilityCanBeRetrievedWhenBackwardCompatibilityIsSet()

ilBcryptPasswordEncoderTest::testBackwardCompatibilityCanBeRetrievedWhenBackwardCompatibilityIsSet ( )

Definition at line 233 of file ilBcryptPasswordEncoderTest.php.

234  {
235  $encoder = new ilBcryptPasswordEncoder();
236  $encoder->setBackwardCompatibility(true);
237  $this->assertTrue($encoder->isBackwardCompatibilityEnabled());
238  $encoder->setBackwardCompatibility(false);
239  $this->assertFalse($encoder->isBackwardCompatibilityEnabled());
240  }

◆ testCostsCanBeRetrievedWhenCostsAreSet()

ilBcryptPasswordEncoderTest::testCostsCanBeRetrievedWhenCostsAreSet ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 117 of file ilBcryptPasswordEncoderTest.php.

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

118  {
119  $encoder->setCosts(4);
120  $this->assertEquals(4, $encoder->getCosts());
121  }
+ Here is the call graph for this function:

◆ testCostsCanBeSetInRange()

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

testInstanceCanBeCreated costsProvider

Definition at line 145 of file ilBcryptPasswordEncoderTest.php.

References ilBcryptPasswordEncoder\setCosts().

146  {
147  $encoder->setCosts($costs);
148  }
+ Here is the call graph for this function:

◆ testCostsCannotBeSetAboveRange()

ilBcryptPasswordEncoderTest::testCostsCannotBeSetAboveRange ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated ilPasswordException

Definition at line 127 of file ilBcryptPasswordEncoderTest.php.

References ilBcryptPasswordEncoder\setCosts().

128  {
129  $encoder->setCosts(32);
130  }
+ Here is the call graph for this function:

◆ testCostsCannotBeSetBelowRange()

ilBcryptPasswordEncoderTest::testCostsCannotBeSetBelowRange ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated ilPasswordException

Definition at line 136 of file ilBcryptPasswordEncoderTest.php.

References ilBcryptPasswordEncoder\setCosts().

137  {
138  $encoder->setCosts(3);
139  }
+ Here is the call graph for this function:

◆ testExceptionIsNotRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabledWithIgnoredSecurityFlaw()

ilBcryptPasswordEncoderTest::testExceptionIsNotRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabledWithIgnoredSecurityFlaw ( )

Definition at line 300 of file ilBcryptPasswordEncoderTest.php.

301  {
302  $encoder = new ilBcryptPasswordEncoder();
303  $encoder->setClientSalt(self::CLIENT_SALT);
304  $encoder->setBackwardCompatibility(true);
305  $encoder->setIsSecurityFlawIgnored(true);
306  $encoder->encodePassword(self::PASSWORD . chr(195), self::PASSWORD_SALT);
307  }

◆ testExceptionIsRaisedIfSaltIsMissingIsOnEncoding()

ilBcryptPasswordEncoderTest::testExceptionIsRaisedIfSaltIsMissingIsOnEncoding ( )

ilPasswordException

Definition at line 197 of file ilBcryptPasswordEncoderTest.php.

198  {
199  $encoder = new ilBcryptPasswordEncoder();
200  $encoder->setClientSalt(null);
201  $encoder->setCosts(self::VALID_COSTS);
202  $encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
203  }

◆ testExceptionIsRaisedIfSaltIsMissingIsOnVerification()

ilBcryptPasswordEncoderTest::testExceptionIsRaisedIfSaltIsMissingIsOnVerification ( )

ilPasswordException

Definition at line 208 of file ilBcryptPasswordEncoderTest.php.

209  {
210  $encoder = new ilBcryptPasswordEncoder();
211  $encoder->setClientSalt(null);
212  $encoder->setCosts(self::VALID_COSTS);
213  $encoder->isPasswordValid('12121212', self::PASSWORD, self::PASSWORD_SALT);
214  }

◆ testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding()

ilBcryptPasswordEncoderTest::testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated ilPasswordException

Definition at line 179 of file ilBcryptPasswordEncoderTest.php.

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

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

◆ testExceptionIsRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabled()

ilBcryptPasswordEncoderTest::testExceptionIsRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabled ( )

ilPasswordException

Definition at line 289 of file ilBcryptPasswordEncoderTest.php.

290  {
291  $encoder = new ilBcryptPasswordEncoder();
292  $encoder->setClientSalt(self::CLIENT_SALT);
293  $encoder->setBackwardCompatibility(true);
294  $encoder->encodePassword(self::PASSWORD . chr(195), self::PASSWORD_SALT);
295  }

◆ testInstanceCanBeCreated()

ilBcryptPasswordEncoderTest::testInstanceCanBeCreated ( )
Returns
ilBcryptPasswordEncoder

Definition at line 92 of file ilBcryptPasswordEncoderTest.php.

93  {
94  $security_flaw_ignoring_encoder = new ilBcryptPasswordEncoder(array(
95  'ignore_security_flaw' => true
96  ));
97  $this->assertTrue($security_flaw_ignoring_encoder->isSecurityFlawIgnored());
98 
99  $security_flaw_respecting_encoder = new ilBcryptPasswordEncoder(array(
100  'ignore_security_flaw' => false
101  ));
102  $this->assertFalse($security_flaw_respecting_encoder->isSecurityFlawIgnored());
103 
104  $encoder = new ilBcryptPasswordEncoder(array(
105  'cost' => self::VALID_COSTS
106  ));
107  $this->assertInstanceOf('ilBcryptPasswordEncoder', $encoder);
108  $this->assertEquals(self::VALID_COSTS, $encoder->getCosts());
109  $this->assertFalse($encoder->isSecurityFlawIgnored());
110  $encoder->setClientSalt(self::CLIENT_SALT);
111  return $encoder;
112  }

◆ testInstanceCanBeCreatedAndInitializedWithClientSalt()

ilBcryptPasswordEncoderTest::testInstanceCanBeCreatedAndInitializedWithClientSalt ( )

Definition at line 219 of file ilBcryptPasswordEncoderTest.php.

References getTestDirectory(), ilBcryptPasswordEncoder\SALT_STORAGE_FILENAME, and skipIfvfsStreamNotSupported().

220  {
222 
223  $this->getTestDirectory()->chmod(0777);
224  vfsStream::newFile(ilBcryptPasswordEncoder::SALT_STORAGE_FILENAME)->withContent(self::CLIENT_SALT)->at($this->getTestDirectory());
225 
226  $encoder = new ilBcryptPasswordEncoder();
227  $this->assertEquals(self::CLIENT_SALT, $encoder->getClientSalt());
228  }
+ Here is the call graph for this function:

◆ testNameShouldBeBcrypt()

ilBcryptPasswordEncoderTest::testNameShouldBeBcrypt ( )

Definition at line 312 of file ilBcryptPasswordEncoderTest.php.

313  {
314  $encoder = new ilBcryptPasswordEncoder();
315  $this->assertEquals('bcrypt', $encoder->getName());
316  }

◆ testPasswordShouldBeCorrectlyEncodedAndVerified()

ilBcryptPasswordEncoderTest::testPasswordShouldBeCorrectlyEncodedAndVerified ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 166 of file ilBcryptPasswordEncoderTest.php.

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

167  {
168  $encoder->setCosts(self::VALID_COSTS);
169  $encoded_password = $encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
170  $this->assertTrue($encoder->isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
171  $this->assertFalse($encoder->isPasswordValid($encoded_password, self::WRONG_PASSWORD, self::PASSWORD_SALT));
172  return $encoder;
173  }
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 188 of file ilBcryptPasswordEncoderTest.php.

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

189  {
190  $encoder->setCosts(self::VALID_COSTS);
191  $this->assertFalse($encoder->isPasswordValid('encoded', str_repeat('a', 5000), self::PASSWORD_SALT));
192  }
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 41 of file ilBcryptPasswordEncoderTest.php.

Referenced by getTestDirectory(), and setTestDirectory().

◆ CLIENT_SALT

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

Definition at line 31 of file ilBcryptPasswordEncoderTest.php.

◆ PASSWORD

const ilBcryptPasswordEncoderTest::PASSWORD = 'password'

Definition at line 21 of file ilBcryptPasswordEncoderTest.php.

◆ PASSWORD_SALT

const ilBcryptPasswordEncoderTest::PASSWORD_SALT = 'salt'

Definition at line 36 of file ilBcryptPasswordEncoderTest.php.

◆ VALID_COSTS

const ilBcryptPasswordEncoderTest::VALID_COSTS = '08'

Definition at line 16 of file ilBcryptPasswordEncoderTest.php.

◆ WRONG_PASSWORD

const ilBcryptPasswordEncoderTest::WRONG_PASSWORD = 'wrong_password'

Definition at line 26 of file ilBcryptPasswordEncoderTest.php.


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