ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilObjUserPasswordTest Class Reference
+ Inheritance diagram for ilObjUserPasswordTest:
+ Collaboration diagram for ilObjUserPasswordTest:

Public Member Functions

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

Data Fields

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

Protected Member Functions

 setUp ()
 Sets up the fixture, for example, open a network connection. More...
 

Detailed Description

Definition at line 15 of file ilObjUserPasswordTest.php.

Member Function Documentation

◆ setUp()

ilObjUserPasswordTest::setUp ( )
protected

Sets up the fixture, for example, open a network connection.

This method is called before a test is executed.

Definition at line 31 of file ilObjUserPasswordTest.php.

32 {
33 if(!defined('CLIENT_DATA_DIR'))
34 {
35 define('CLIENT_DATA_DIR', '/tmp');
36 }
37
38 parent::setUp();
39 }

◆ testExceptionIsRaisedIfAnUnsupportedEncoderIsRequestedFromFactory()

ilObjUserPasswordTest::testExceptionIsRaisedIfAnUnsupportedEncoderIsRequestedFromFactory ( )

@expectedException ilUserException

Definition at line 291 of file ilObjUserPasswordTest.php.

292 {
293 $factory = new ilUserPasswordEncoderFactory(array('default_password_encoder' => 'md5'));
294 $factory->getEncoderByName('phpunit');
295 }

◆ testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutEncoderInformation()

ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutEncoderInformation ( )

@expectedException ilUserException

Definition at line 44 of file ilObjUserPasswordTest.php.

◆ testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutFactory()

ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutFactory ( )

@expectedException ilUserException

Definition at line 52 of file ilObjUserPasswordTest.php.

53 {
55 array(
56 'password_encoder' => 'md5'
57 )
58 );
59 }

◆ testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutValidFactory()

ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutValidFactory ( )

@expectedException PHPUnit_Framework_Error

Definition at line 64 of file ilObjUserPasswordTest.php.

65 {
67 array(
68 'password_encoder' => 'md5',
69 'encoder_factory' => 'test'
70 )
71 );
72 }

◆ testFactoryCanBeCreated()

ilObjUserPasswordTest::testFactoryCanBeCreated ( )

Definition at line 252 of file ilObjUserPasswordTest.php.

253 {
254 $factory = new ilUserPasswordEncoderFactory();
255 $this->assertInstanceOf('ilUserPasswordEncoderFactory', $factory);
256 }

◆ testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndNoDefaultEncoderWasSpecifiedInFallbackMode()

ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndNoDefaultEncoderWasSpecifiedInFallbackMode ( )

@expectedException ilUserException

Definition at line 300 of file ilObjUserPasswordTest.php.

301 {
302 $factory = new ilUserPasswordEncoderFactory();
303 $factory->getEncoderByName('phpunit', true);
304 }

◆ testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndTheDefaultEncoderDoesNotMatchOneOfTheSupportedEncodersInFallbackMode()

ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndTheDefaultEncoderDoesNotMatchOneOfTheSupportedEncodersInFallbackMode ( )

@expectedException ilUserException

Definition at line 309 of file ilObjUserPasswordTest.php.

310 {
311 $factory = new ilUserPasswordEncoderFactory(array('default_password_encoder' => 'phpunit'));
312 $factory->getEncoderByName('phpunit', true);
313 }

◆ testFactoryRaisesAnExceptionIfAnUnsupportedEncoderWasInjected()

ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderWasInjected ( )

@expectedException ilUserException

Definition at line 282 of file ilObjUserPasswordTest.php.

283 {
284 $factory = new ilUserPasswordEncoderFactory();
285 $factory->setEncoders(array('phpunit'));
286 }

◆ testFactoryReturnsCorrectEncoderIfAMatchingEncoderWasFound()

ilObjUserPasswordTest::testFactoryReturnsCorrectEncoderIfAMatchingEncoderWasFound ( )

Definition at line 331 of file ilObjUserPasswordTest.php.

332 {
333 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
334 $encoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('mockencoder'));
335
336 $factory = new ilUserPasswordEncoderFactory(array('default_password_encoder' => $encoder->getName()));
337 $factory->setEncoders(array($encoder));
338 $this->assertEquals($encoder, $factory->getEncoderByName('mockencoder', true));
339 }

◆ testFactoryReturnsTheDefaultEncoderIfAnUnsupportedEncoderIsRequestedAndASupportedDefaultEncoderWasSpecifiedInFallbackMode()

ilObjUserPasswordTest::testFactoryReturnsTheDefaultEncoderIfAnUnsupportedEncoderIsRequestedAndASupportedDefaultEncoderWasSpecifiedInFallbackMode ( )

Definition at line 318 of file ilObjUserPasswordTest.php.

319 {
320 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
321 $encoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('mockencoder'));
322
323 $factory = new ilUserPasswordEncoderFactory(array('default_password_encoder' => $encoder->getName()));
324 $factory->setEncoders(array($encoder));
325 $this->assertEquals($encoder, $factory->getEncoderByName('phpunit', true));
326 }

◆ testGettersOfFactoryShouldReturnWhatWasSetBySetters()

ilObjUserPasswordTest::testGettersOfFactoryShouldReturnWhatWasSetBySetters ( )

Definition at line 261 of file ilObjUserPasswordTest.php.

262 {
263 $factory = new ilUserPasswordEncoderFactory(array('default_password_encoder' => 'md5'));
264 $this->assertEquals('md5', $factory->getDefaultEncoder());
265
266 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
267 $encoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('mockencoder'));
268
269 $second_mockencoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
270 $second_mockencoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('second_mockencoder'));
271
272 $factory->setEncoders(array($encoder, $second_mockencoder));
273 $this->assertCount(2, $factory->getEncoders());
274 $this->assertCount(2, $factory->getSupportedEncoderNames());
275 $this->assertCount(0, array_diff(array('mockencoder', 'second_mockencoder'), $factory->getSupportedEncoderNames()));
276 $this->assertCount(0, array_diff($factory->getSupportedEncoderNames(), array('mockencoder', 'second_mockencoder')));
277 }

◆ testInstanceCanBeCreated()

ilObjUserPasswordTest::testInstanceCanBeCreated ( )

Definition at line 77 of file ilObjUserPasswordTest.php.

78 {
79 $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
80 $factory_mock->expects($this->exactly(2))->method('getSupportedEncoderNames')->will($this->onConsecutiveCalls(
81 array(
82 'mockencoder', 'second_mockencoder'
83 ),
84 array(
85 'mockencoder'
86 )
87 ));
88
89 $password_manager = new ilUserPasswordManager(
90 array(
91 'password_encoder' => 'md5',
92 'encoder_factory' => $factory_mock
93 )
94 );
95 $this->assertInstanceOf('ilUserPasswordManager', $password_manager);
96 $this->assertEquals('md5', $password_manager->getEncoderName());
97 $this->assertEquals($factory_mock, $password_manager->getEncoderFactory());
98
99 $this->assertTrue($password_manager->isEncodingTypeSupported('second_mockencoder'));
100 $this->assertFalse($password_manager->isEncodingTypeSupported('second_mockencoder'));
101 }

◆ testPasswordManagerEncodesRawPasswordWithoutSalt()

ilObjUserPasswordTest::testPasswordManagerEncodesRawPasswordWithoutSalt ( )

Definition at line 136 of file ilObjUserPasswordTest.php.

137 {
138 $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
139 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
140 $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
141
142 $user_mock->expects($this->once())->method('setPasswordSalt')->with($this->equalTo(null));
143 $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue(null));
144 $user_mock->expects($this->once())->method('setPasswordEncodingType')->with($this->equalTo('mockencoder'));
145 $user_mock->expects($this->once())->method('setPasswd')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(IL_PASSWD_CRYPTED));
146
147 $encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
148 $encoder->expects($this->once())->method('requiresSalt')->will($this->returnValue(false));
149 $encoder->expects($this->once())->method('encodePassword')->with($this->equalTo(self::PASSWORD), $this->equalTo(null))->will($this->returnValue(self::ENCODED_PASSWORD));
150
151 $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
152
153 $password_manager = new ilUserPasswordManager(
154 array(
155 'password_encoder' => 'mockencoder',
156 'encoder_factory' => $factory_mock
157 )
158 );
159
160 $password_manager->encodePassword($user_mock, self::PASSWORD);
161 }
const IL_PASSWD_CRYPTED

References IL_PASSWD_CRYPTED.

◆ testPasswordManagerEncodesRawPasswordWithSalt()

ilObjUserPasswordTest::testPasswordManagerEncodesRawPasswordWithSalt ( )

Definition at line 106 of file ilObjUserPasswordTest.php.

107 {
108 $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
109 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
110 $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
111
112 $user_mock->expects($this->once())->method('setPasswordSalt')->with($this->isType('string'));
113 $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
114 $user_mock->expects($this->once())->method('setPasswordEncodingType')->with($this->equalTo('mockencoder'));
115 $user_mock->expects($this->once())->method('setPasswd')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(IL_PASSWD_CRYPTED));
116
117 $encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
118 $encoder->expects($this->once())->method('requiresSalt')->will($this->returnValue(true));
119 $encoder->expects($this->once())->method('encodePassword')->with($this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(self::ENCODED_PASSWORD));
120
121 $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
122
123 $password_manager = new ilUserPasswordManager(
124 array(
125 'password_encoder' => 'mockencoder',
126 'encoder_factory' => $factory_mock
127 )
128 );
129
130 $password_manager->encodePassword($user_mock, self::PASSWORD);
131 }

References IL_PASSWD_CRYPTED.

◆ testPasswordManagerMigratesPasswordOnVerificationWithVariantEncoders()

ilObjUserPasswordTest::testPasswordManagerMigratesPasswordOnVerificationWithVariantEncoders ( )

Definition at line 194 of file ilObjUserPasswordTest.php.

195 {
196 $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
197 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
198 $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
199
200 $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
201 $user_mock->expects($this->once())->method('getPasswordEncodingType')->will($this->returnValue('second_mockencoder'));
202 $user_mock->expects($this->once())->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
203 $user_mock->expects($this->once())->method('resetPassword')->with($this->equalTo(self::PASSWORD), $this->equalTo(self::PASSWORD));
204
205 $encoder->expects($this->once())->method('getName')->will($this->returnValue('second_mockencoder'));
206 $encoder->expects($this->once())->method('isPasswordValid')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(true));
207
208 $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
209
210 $password_manager = new ilUserPasswordManager(
211 array(
212 'password_encoder' => 'mockencoder',
213 'encoder_factory' => $factory_mock
214 )
215 );
216
217 $this->assertTrue($password_manager->verifyPassword($user_mock, self::PASSWORD));
218 }

◆ testPasswordManagerNeverMigratesPasswordOnFailedVerificationWithVariantEncoders()

ilObjUserPasswordTest::testPasswordManagerNeverMigratesPasswordOnFailedVerificationWithVariantEncoders ( )

Definition at line 223 of file ilObjUserPasswordTest.php.

224 {
225 $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
226 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
227 $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
228
229 $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
230 $user_mock->expects($this->once())->method('getPasswordEncodingType')->will($this->returnValue('second_mockencoder'));
231 $user_mock->expects($this->once())->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
232 $user_mock->expects($this->never())->method('resetPassword');
233
234 $encoder->expects($this->once())->method('getName')->will($this->returnValue('second_mockencoder'));
235 $encoder->expects($this->once())->method('isPasswordValid')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(false));
236
237 $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
238
239 $password_manager = new ilUserPasswordManager(
240 array(
241 'password_encoder' => 'mockencoder',
242 'encoder_factory' => $factory_mock
243 )
244 );
245
246 $this->assertFalse($password_manager->verifyPassword($user_mock, self::PASSWORD));
247 }

◆ testPasswordManagerVerifiesPassword()

ilObjUserPasswordTest::testPasswordManagerVerifiesPassword ( )

Definition at line 166 of file ilObjUserPasswordTest.php.

167 {
168 $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
169 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
170 $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
171
172 $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
173 $user_mock->expects($this->once())->method('getPasswordEncodingType')->will($this->returnValue('mockencoder'));
174 $user_mock->expects($this->once())->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
175
176 $encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
177 $encoder->expects($this->once())->method('isPasswordValid')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(true));
178
179 $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
180
181 $password_manager = new ilUserPasswordManager(
182 array(
183 'password_encoder' => 'mockencoder',
184 'encoder_factory' => $factory_mock
185 )
186 );
187
188 $this->assertTrue($password_manager->verifyPassword($user_mock, self::PASSWORD));
189 }

Field Documentation

◆ ENCODED_PASSWORD

const ilObjUserPasswordTest::ENCODED_PASSWORD = 'encoded'

Definition at line 25 of file ilObjUserPasswordTest.php.

◆ PASSWORD

const ilObjUserPasswordTest::PASSWORD = 'password'

Definition at line 20 of file ilObjUserPasswordTest.php.


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