ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilBcryptPasswordEncoderTest Class Reference
+ Inheritance diagram for ilBcryptPasswordEncoderTest:
+ Collaboration diagram for ilBcryptPasswordEncoderTest:

Public Member Functions

 getTestDirectory ()
 setTestDirectory ($test_directory)
 testInstanceCanBeCreated ()
 testCostsCanBeRetrievedWhenCostsAreSet (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated
 testCostsCannotBeSetAboveRange (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated ilPasswordException
 testCostsCannotBeSetBelowRange (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated ilPasswordException
 testCostsCanBeSetInRange ($costs, ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated costsProvider
 costsProvider ()
 testPasswordShouldBeCorrectlyEncodedAndVerified (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated
 testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated ilPasswordException
 testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength (ilBcryptPasswordEncoder $encoder)
 testInstanceCanBeCreated
 testExceptionIsRaisedIfSaltIsMissingIsOnEncoding ()
 ilPasswordException
 testExceptionIsRaisedIfSaltIsMissingIsOnVerification ()
 ilPasswordException
 testExceptionIsRaisedIfAGeneratedClientSaltCouldNotBeStoredOnEncoderSelection ()
 testClientSaltIsGeneratedAndStoredOnEncoderSelection ()
 testInstanceCanBeCreatedAndInitializedWithClientSalt ()
 testBackwardCompatibilityCanBeRetrievedWhenBackwardCompatibilityIsSet ()
 testBackwardCompatibility ()
 testExceptionIsRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabled ()
 ilPasswordException
 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.

Protected Attributes

 $test_directory

Private Member Functions

 isVsfStreamInstalled ()
 skipIfPhpVersionIsNotSupported ()
 skipIfvfsStreamNotSupported ()

Detailed Description

Definition at line 11 of file ilBcryptPasswordEncoderTest.php.

Member Function Documentation

ilBcryptPasswordEncoderTest::costsProvider ( )
Returns
array

Definition at line 145 of file ilBcryptPasswordEncoderTest.php.

{
$data = array();
for($i = 4; $i <= 31; $i++)
{
$data[] = array($i);
}
return $data;
}
ilBcryptPasswordEncoderTest::getTestDirectory ( )
ilBcryptPasswordEncoderTest::isVsfStreamInstalled ( )
private
Returns
bool

Definition at line 62 of file ilBcryptPasswordEncoderTest.php.

Referenced by setUp(), and skipIfvfsStreamNotSupported().

{
return @include_once('vfsStream.php');
}

+ Here is the caller graph for this function:

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

Definition at line 54 of file ilBcryptPasswordEncoderTest.php.

References $test_directory.

Referenced by setUp().

{
$this->test_directory = $test_directory;
}

+ Here is the caller graph for this function:

ilBcryptPasswordEncoderTest::setUp ( )
protected

Setup.

Definition at line 70 of file ilBcryptPasswordEncoderTest.php.

References isVsfStreamInstalled(), and setTestDirectory().

{
if($this->isVsfStreamInstalled())
{
vfsStream::setup();
$this->setTestDirectory(vfsStream::newDirectory('tests')->at(vfsStreamWrapper::getRoot()));
define('CLIENT_DATA_DIR', vfsStream::url('root/tests'));
}
}

+ Here is the call graph for this function:

ilBcryptPasswordEncoderTest::skipIfPhpVersionIsNotSupported ( )
private

Definition at line 300 of file ilBcryptPasswordEncoderTest.php.

Referenced by testBackwardCompatibility().

{
if(version_compare(phpversion(), '5.3.7', '<'))
{
$this->markTestSkipped('Requires PHP >= 5.3.7');
}
}

+ Here is the caller graph for this function:

ilBcryptPasswordEncoderTest::skipIfvfsStreamNotSupported ( )
private

Definition at line 311 of file ilBcryptPasswordEncoderTest.php.

References isVsfStreamInstalled().

Referenced by testClientSaltIsGeneratedAndStoredOnEncoderSelection(), testExceptionIsRaisedIfAGeneratedClientSaltCouldNotBeStoredOnEncoderSelection(), and testInstanceCanBeCreatedAndInitializedWithClientSalt().

{
if(!$this->isVsfStreamInstalled())
{
$this->markTestSkipped('Requires vfsStream (http://vfs.bovigo.org)');
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilBcryptPasswordEncoderTest::testBackwardCompatibility ( )

Definition at line 278 of file ilBcryptPasswordEncoderTest.php.

References skipIfPhpVersionIsNotSupported().

{
$encoder = new ilBcryptPasswordEncoder();
$encoder->setClientSalt(self::CLIENT_SALT);
$encoder->setBackwardCompatibility(true);
$encoded_password = $encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
$this->assertTrue($encoder->isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
$this->assertEquals('$2a$', substr($encoded_password, 0, 4));
$another_encoder = new ilBcryptPasswordEncoder();
$another_encoder->setClientSalt(self::CLIENT_SALT);
$another_encoder->setBackwardCompatibility(false);
$another_encoded_password = $another_encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
$this->assertEquals('$2y$', substr($another_encoded_password, 0, 4));
$this->assertTrue($another_encoder->isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
}

+ Here is the call graph for this function:

ilBcryptPasswordEncoderTest::testBackwardCompatibilityCanBeRetrievedWhenBackwardCompatibilityIsSet ( )

Definition at line 266 of file ilBcryptPasswordEncoderTest.php.

{
$encoder = new ilBcryptPasswordEncoder();
$encoder->setBackwardCompatibility(true);
$this->assertTrue($encoder->isBackwardCompatibilityEnabled());
$encoder->setBackwardCompatibility(false);
$this->assertFalse($encoder->isBackwardCompatibilityEnabled());
}
ilBcryptPasswordEncoderTest::testClientSaltIsGeneratedAndStoredOnEncoderSelection ( )

Definition at line 234 of file ilBcryptPasswordEncoderTest.php.

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

{
$this->getTestDirectory()->chmod(0777);
$encoder = new ilBcryptPasswordEncoder();
$this->assertNull($encoder->getClientSalt());
$encoder->onSelection();
$this->assertNotNull($encoder->getClientSalt());
$this->assertFileExists(vfsStream::url('root/tests/' . ilBcryptPasswordEncoder::SALT_STORAGE_FILENAME));
}

+ Here is the call graph for this function:

ilBcryptPasswordEncoderTest::testCostsCanBeRetrievedWhenCostsAreSet ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 109 of file ilBcryptPasswordEncoderTest.php.

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

{
$encoder->setCosts(4);
$this->assertEquals(4, $encoder->getCosts());
}

+ Here is the call graph for this function:

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

testInstanceCanBeCreated costsProvider

Definition at line 137 of file ilBcryptPasswordEncoderTest.php.

References ilBcryptPasswordEncoder\setCosts().

{
$encoder->setCosts($costs);
}

+ Here is the call graph for this function:

ilBcryptPasswordEncoderTest::testCostsCannotBeSetAboveRange ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated ilPasswordException

Definition at line 119 of file ilBcryptPasswordEncoderTest.php.

References ilBcryptPasswordEncoder\setCosts().

{
$encoder->setCosts(32);
}

+ Here is the call graph for this function:

ilBcryptPasswordEncoderTest::testCostsCannotBeSetBelowRange ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated ilPasswordException

Definition at line 128 of file ilBcryptPasswordEncoderTest.php.

References ilBcryptPasswordEncoder\setCosts().

{
$encoder->setCosts(3);
}

+ Here is the call graph for this function:

ilBcryptPasswordEncoderTest::testExceptionIsNotRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabledWithIgnoredSecurityFlaw ( )

Definition at line 333 of file ilBcryptPasswordEncoderTest.php.

{
$encoder = new ilBcryptPasswordEncoder();
$encoder->setClientSalt(self::CLIENT_SALT);
$encoder->setBackwardCompatibility(true);
$encoder->setIsSecurityFlawIgnored(true);
$encoder->encodePassword(self::PASSWORD . chr(195), self::PASSWORD_SALT);
}
ilBcryptPasswordEncoderTest::testExceptionIsRaisedIfAGeneratedClientSaltCouldNotBeStoredOnEncoderSelection ( )

Definition at line 211 of file ilBcryptPasswordEncoderTest.php.

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

{
$encoder = new ilBcryptPasswordEncoder();
$this->assertNull($encoder->getClientSalt());
try
{
$this->getTestDirectory()->chmod(0000);
$encoder->onSelection();
$this->fail('An expected exception has not been raised.');
}
catch(Exception $e)
{
$this->assertNull($encoder->getClientSalt());
$this->assertFileNotExists(vfsStream::url('root/tests/' . ilBcryptPasswordEncoder::SALT_STORAGE_FILENAME));
}
}

+ Here is the call graph for this function:

ilBcryptPasswordEncoderTest::testExceptionIsRaisedIfSaltIsMissingIsOnEncoding ( )

ilPasswordException

Definition at line 189 of file ilBcryptPasswordEncoderTest.php.

{
$encoder = new ilBcryptPasswordEncoder();
$encoder->setClientSalt(null);
$encoder->setCosts(self::VALID_COSTS);
$encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
}
ilBcryptPasswordEncoderTest::testExceptionIsRaisedIfSaltIsMissingIsOnVerification ( )

ilPasswordException

Definition at line 200 of file ilBcryptPasswordEncoderTest.php.

{
$encoder = new ilBcryptPasswordEncoder();
$encoder->setClientSalt(null);
$encoder->setCosts(self::VALID_COSTS);
$encoder->isPasswordValid('12121212', self::PASSWORD, self::PASSWORD_SALT);
}
ilBcryptPasswordEncoderTest::testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated ilPasswordException

Definition at line 171 of file ilBcryptPasswordEncoderTest.php.

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

{
$encoder->setCosts(self::VALID_COSTS);
$encoder->encodePassword(str_repeat('a', 5000), self::PASSWORD_SALT);
}

+ Here is the call graph for this function:

ilBcryptPasswordEncoderTest::testExceptionIsRaisedIfTheRawPasswordContainsA8BitCharacterAndBackwardCompatibilityIsEnabled ( )

ilPasswordException

Definition at line 322 of file ilBcryptPasswordEncoderTest.php.

{
$encoder = new ilBcryptPasswordEncoder();
$encoder->setClientSalt(self::CLIENT_SALT);
$encoder->setBackwardCompatibility(true);
$encoder->encodePassword(self::PASSWORD . chr(195), self::PASSWORD_SALT);
}
ilBcryptPasswordEncoderTest::testInstanceCanBeCreated ( )
Returns
ilBcryptPasswordEncoder

Definition at line 84 of file ilBcryptPasswordEncoderTest.php.

{
$security_flaw_ignoring_encoder = new ilBcryptPasswordEncoder(array(
'ignore_security_flaw' => true
));
$this->assertTrue($security_flaw_ignoring_encoder->isSecurityFlawIgnored());
$security_flaw_respecting_encoder = new ilBcryptPasswordEncoder(array(
'ignore_security_flaw' => false
));
$this->assertFalse($security_flaw_respecting_encoder->isSecurityFlawIgnored());
$encoder = new ilBcryptPasswordEncoder(array(
'cost' => self::VALID_COSTS
));
$this->assertInstanceOf('ilBcryptPasswordEncoder', $encoder);
$this->assertEquals(self::VALID_COSTS, $encoder->getCosts());
$this->assertFalse($encoder->isSecurityFlawIgnored());
$encoder->setClientSalt(self::CLIENT_SALT);
return $encoder;
}
ilBcryptPasswordEncoderTest::testInstanceCanBeCreatedAndInitializedWithClientSalt ( )

Definition at line 252 of file ilBcryptPasswordEncoderTest.php.

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

{
$this->getTestDirectory()->chmod(0777);
vfsStream::newFile(ilBcryptPasswordEncoder::SALT_STORAGE_FILENAME)->withContent(self::CLIENT_SALT)->at($this->getTestDirectory());
$encoder = new ilBcryptPasswordEncoder();
$this->assertEquals(self::CLIENT_SALT, $encoder->getClientSalt());
}

+ Here is the call graph for this function:

ilBcryptPasswordEncoderTest::testNameShouldBeBcrypt ( )

Definition at line 345 of file ilBcryptPasswordEncoderTest.php.

{
$encoder = new ilBcryptPasswordEncoder();
$this->assertEquals('bcrypt', $encoder->getName());
}
ilBcryptPasswordEncoderTest::testPasswordShouldBeCorrectlyEncodedAndVerified ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 158 of file ilBcryptPasswordEncoderTest.php.

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

{
$encoder->setCosts(self::VALID_COSTS);
$encoded_password = $encoder->encodePassword(self::PASSWORD, self::PASSWORD_SALT);
$this->assertTrue($encoder->isPasswordValid($encoded_password, self::PASSWORD, self::PASSWORD_SALT));
$this->assertFalse($encoder->isPasswordValid($encoded_password, self::WRONG_PASSWORD, self::PASSWORD_SALT));
return $encoder;
}

+ Here is the call graph for this function:

ilBcryptPasswordEncoderTest::testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength ( ilBcryptPasswordEncoder  $encoder)

testInstanceCanBeCreated

Definition at line 180 of file ilBcryptPasswordEncoderTest.php.

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

{
$encoder->setCosts(self::VALID_COSTS);
$this->assertFalse($encoder->isPasswordValid('encoded', str_repeat('a', 5000), self::PASSWORD_SALT));
}

+ Here is the call graph for this function:

Field Documentation

ilBcryptPasswordEncoderTest::$test_directory
protected

Definition at line 41 of file ilBcryptPasswordEncoderTest.php.

Referenced by getTestDirectory(), and setTestDirectory().

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

Definition at line 31 of file ilBcryptPasswordEncoderTest.php.

const ilBcryptPasswordEncoderTest::PASSWORD = 'password'

Definition at line 21 of file ilBcryptPasswordEncoderTest.php.

const ilBcryptPasswordEncoderTest::PASSWORD_SALT = 'salt'

Definition at line 36 of file ilBcryptPasswordEncoderTest.php.

const ilBcryptPasswordEncoderTest::VALID_COSTS = '08'

Definition at line 16 of file ilBcryptPasswordEncoderTest.php.

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: