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

Public Member Functions

 testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutEncoderInformation ()
 ilUserException
 testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutFactory ()
 ilUserException
 testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutValidFactory ()
 PHPUnit_Framework_Error
 testInstanceCanBeCreated ()
 testPasswordManagerEncodesRawPasswordWithSalt ()
 testPasswordManagerEncodesRawPasswordWithoutSalt ()
 testPasswordManagerVerifiesPassword ()
 testPasswordManagerMigratesPasswordOnVerificationWithVariantEncoders ()
 testPasswordManagerNeverMigratesPasswordOnFailedVerificationWithVariantEncoders ()
 testFactoryCanBeCreated ()
 testGettersOfFactoryShouldReturnWhatWasSetBySetters ()
 testFactoryRaisesAnExceptionIfAnUnsupportedEncoderWasInjected ()
 ilUserException
 testExceptionIsRaisedIfAnUnsupportedEncoderIsRequestedFromFactory ()
 ilUserException
 testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndNoDefaultEncoderWasSpecifiedInFallbackMode ()
 ilUserException
 testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndTheDefaultEncoderDoesNotMatchOneOfTheSupportedEncodersInFallbackMode ()
 ilUserException
 testFactoryReturnsTheDefaultEncoderIfAnUnsupportedEncoderIsRequestedAndASupportedDefaultEncoderWasSpecifiedInFallbackMode ()
 testFactoryReturnsCorrectEncoderIfAMatchingEncoderWasFound ()

Data Fields

const PASSWORD = 'password'
const ENCODED_PASSWORD = 'encoded'

Detailed Description

Definition at line 15 of file ilObjUserPasswordTest.php.

Member Function Documentation

ilObjUserPasswordTest::testExceptionIsRaisedIfAnUnsupportedEncoderIsRequestedFromFactory ( )

ilUserException

Definition at line 277 of file ilObjUserPasswordTest.php.

{
$factory = new ilUserPasswordEncoderFactory(array('default_password_encoder' => 'md5'));
$factory->getEncoderByName('phpunit');
}
ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutEncoderInformation ( )

ilUserException

Definition at line 30 of file ilObjUserPasswordTest.php.

ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutFactory ( )

ilUserException

Definition at line 38 of file ilObjUserPasswordTest.php.

{
array(
'password_encoder' => 'md5'
)
);
}
ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutValidFactory ( )

PHPUnit_Framework_Error

Definition at line 50 of file ilObjUserPasswordTest.php.

{
array(
'password_encoder' => 'md5',
'encoder_factory' => 'test'
)
);
}
ilObjUserPasswordTest::testFactoryCanBeCreated ( )

Definition at line 238 of file ilObjUserPasswordTest.php.

{
$factory = new ilUserPasswordEncoderFactory();
$this->assertInstanceOf('ilUserPasswordEncoderFactory', $factory);
}
ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndNoDefaultEncoderWasSpecifiedInFallbackMode ( )

ilUserException

Definition at line 286 of file ilObjUserPasswordTest.php.

{
$factory = new ilUserPasswordEncoderFactory();
$factory->getEncoderByName('phpunit', true);
}
ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndTheDefaultEncoderDoesNotMatchOneOfTheSupportedEncodersInFallbackMode ( )

ilUserException

Definition at line 295 of file ilObjUserPasswordTest.php.

{
$factory = new ilUserPasswordEncoderFactory(array('default_password_encoder' => 'phpunit'));
$factory->getEncoderByName('phpunit', true);
}
ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderWasInjected ( )

ilUserException

Definition at line 268 of file ilObjUserPasswordTest.php.

{
$factory = new ilUserPasswordEncoderFactory();
$factory->setEncoders(array('phpunit'));
}
ilObjUserPasswordTest::testFactoryReturnsCorrectEncoderIfAMatchingEncoderWasFound ( )

Definition at line 317 of file ilObjUserPasswordTest.php.

{
$encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
$encoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('mockencoder'));
$factory = new ilUserPasswordEncoderFactory(array('default_password_encoder' => $encoder->getName()));
$factory->setEncoders(array($encoder));
$this->assertEquals($encoder, $factory->getEncoderByName('mockencoder', true));
}
ilObjUserPasswordTest::testFactoryReturnsTheDefaultEncoderIfAnUnsupportedEncoderIsRequestedAndASupportedDefaultEncoderWasSpecifiedInFallbackMode ( )

Definition at line 304 of file ilObjUserPasswordTest.php.

{
$encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
$encoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('mockencoder'));
$factory = new ilUserPasswordEncoderFactory(array('default_password_encoder' => $encoder->getName()));
$factory->setEncoders(array($encoder));
$this->assertEquals($encoder, $factory->getEncoderByName('phpunit', true));
}
ilObjUserPasswordTest::testGettersOfFactoryShouldReturnWhatWasSetBySetters ( )

Definition at line 247 of file ilObjUserPasswordTest.php.

{
$factory = new ilUserPasswordEncoderFactory(array('default_password_encoder' => 'md5'));
$this->assertEquals('md5', $factory->getDefaultEncoder());
$encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
$encoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('mockencoder'));
$second_mockencoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
$second_mockencoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('second_mockencoder'));
$factory->setEncoders(array($encoder, $second_mockencoder));
$this->assertCount(2, $factory->getEncoders());
$this->assertCount(2, $factory->getSupportedEncoderNames());
$this->assertCount(0, array_diff(array('mockencoder', 'second_mockencoder'), $factory->getSupportedEncoderNames()));
$this->assertCount(0, array_diff($factory->getSupportedEncoderNames(), array('mockencoder', 'second_mockencoder')));
}
ilObjUserPasswordTest::testInstanceCanBeCreated ( )

Definition at line 63 of file ilObjUserPasswordTest.php.

{
$factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
$factory_mock->expects($this->exactly(2))->method('getSupportedEncoderNames')->will($this->onConsecutiveCalls(
array(
'mockencoder', 'second_mockencoder'
),
array(
'mockencoder'
)
));
$password_manager = new ilUserPasswordManager(
array(
'password_encoder' => 'md5',
'encoder_factory' => $factory_mock
)
);
$this->assertInstanceOf('ilUserPasswordManager', $password_manager);
$this->assertEquals('md5', $password_manager->getEncoderName());
$this->assertEquals($factory_mock, $password_manager->getEncoderFactory());
$this->assertTrue($password_manager->isEncodingTypeSupported('second_mockencoder'));
$this->assertFalse($password_manager->isEncodingTypeSupported('second_mockencoder'));
}
ilObjUserPasswordTest::testPasswordManagerEncodesRawPasswordWithoutSalt ( )

Definition at line 122 of file ilObjUserPasswordTest.php.

References IL_PASSWD_CRYPTED.

{
$user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
$encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
$factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
$user_mock->expects($this->once())->method('setPasswordSalt')->with($this->equalTo(null));
$user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue(null));
$user_mock->expects($this->once())->method('setPasswordEncodingType')->with($this->equalTo('mockencoder'));
$user_mock->expects($this->once())->method('setPasswd')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(IL_PASSWD_CRYPTED));
$encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
$encoder->expects($this->once())->method('requiresSalt')->will($this->returnValue(false));
$encoder->expects($this->once())->method('encodePassword')->with($this->equalTo(self::PASSWORD), $this->equalTo(null))->will($this->returnValue(self::ENCODED_PASSWORD));
$factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
$password_manager = new ilUserPasswordManager(
array(
'password_encoder' => 'mockencoder',
'encoder_factory' => $factory_mock
)
);
$password_manager->encodePassword($user_mock, self::PASSWORD);
}
ilObjUserPasswordTest::testPasswordManagerEncodesRawPasswordWithSalt ( )

Definition at line 92 of file ilObjUserPasswordTest.php.

References IL_PASSWD_CRYPTED.

{
$user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
$encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
$factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
$user_mock->expects($this->once())->method('setPasswordSalt')->with($this->isType('string'));
$user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
$user_mock->expects($this->once())->method('setPasswordEncodingType')->with($this->equalTo('mockencoder'));
$user_mock->expects($this->once())->method('setPasswd')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(IL_PASSWD_CRYPTED));
$encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
$encoder->expects($this->once())->method('requiresSalt')->will($this->returnValue(true));
$encoder->expects($this->once())->method('encodePassword')->with($this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(self::ENCODED_PASSWORD));
$factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
$password_manager = new ilUserPasswordManager(
array(
'password_encoder' => 'mockencoder',
'encoder_factory' => $factory_mock
)
);
$password_manager->encodePassword($user_mock, self::PASSWORD);
}
ilObjUserPasswordTest::testPasswordManagerMigratesPasswordOnVerificationWithVariantEncoders ( )

Definition at line 180 of file ilObjUserPasswordTest.php.

{
$user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
$encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
$factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
$user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
$user_mock->expects($this->once())->method('getPasswordEncodingType')->will($this->returnValue('second_mockencoder'));
$user_mock->expects($this->once())->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
$user_mock->expects($this->once())->method('resetPassword')->with($this->equalTo(self::PASSWORD), $this->equalTo(self::PASSWORD));
$encoder->expects($this->once())->method('getName')->will($this->returnValue('second_mockencoder'));
$encoder->expects($this->once())->method('isPasswordValid')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(true));
$factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
$password_manager = new ilUserPasswordManager(
array(
'password_encoder' => 'mockencoder',
'encoder_factory' => $factory_mock
)
);
$this->assertTrue($password_manager->verifyPassword($user_mock, self::PASSWORD));
}
ilObjUserPasswordTest::testPasswordManagerNeverMigratesPasswordOnFailedVerificationWithVariantEncoders ( )

Definition at line 209 of file ilObjUserPasswordTest.php.

{
$user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
$encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
$factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
$user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
$user_mock->expects($this->once())->method('getPasswordEncodingType')->will($this->returnValue('second_mockencoder'));
$user_mock->expects($this->once())->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
$user_mock->expects($this->never())->method('resetPassword');
$encoder->expects($this->once())->method('getName')->will($this->returnValue('second_mockencoder'));
$encoder->expects($this->once())->method('isPasswordValid')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(false));
$factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
$password_manager = new ilUserPasswordManager(
array(
'password_encoder' => 'mockencoder',
'encoder_factory' => $factory_mock
)
);
$this->assertFalse($password_manager->verifyPassword($user_mock, self::PASSWORD));
}
ilObjUserPasswordTest::testPasswordManagerVerifiesPassword ( )

Definition at line 152 of file ilObjUserPasswordTest.php.

{
$user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
$encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
$factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
$user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
$user_mock->expects($this->once())->method('getPasswordEncodingType')->will($this->returnValue('mockencoder'));
$user_mock->expects($this->once())->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
$encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
$encoder->expects($this->once())->method('isPasswordValid')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(true));
$factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
$password_manager = new ilUserPasswordManager(
array(
'password_encoder' => 'mockencoder',
'encoder_factory' => $factory_mock
)
);
$this->assertTrue($password_manager->verifyPassword($user_mock, self::PASSWORD));
}

Field Documentation

const ilObjUserPasswordTest::ENCODED_PASSWORD = 'encoded'

Definition at line 25 of file ilObjUserPasswordTest.php.

const ilObjUserPasswordTest::PASSWORD = 'password'

Definition at line 20 of file ilObjUserPasswordTest.php.


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