ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 ()
 
 testPasswordManagerReencodesPasswordIfReencodingIsNecessary ()
 
 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...
 
- Protected Member Functions inherited from ilUserBaseTest
 assertException ($exception_class)
 

Detailed Description

Definition at line 17 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 33 of file ilObjUserPasswordTest.php.

34 {
35 if(!defined('CLIENT_DATA_DIR'))
36 {
37 define('CLIENT_DATA_DIR', '/tmp');
38 }
39
40 parent::setUp();
41 }
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27

References defined.

◆ testExceptionIsRaisedIfAnUnsupportedEncoderIsRequestedFromFactory()

ilObjUserPasswordTest::testExceptionIsRaisedIfAnUnsupportedEncoderIsRequestedFromFactory ( )

@expectedException ilUserException

Definition at line 338 of file ilObjUserPasswordTest.php.

339 {
340 $this->assertException(ilUserException::class);
341 $factory = new ilUserPasswordEncoderFactory(array('default_password_encoder' => 'md5'));
342 $factory->getEncoderByName('phpunit');
343 }
assertException($exception_class)

References ilUserBaseTest\assertException().

+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutEncoderInformation()

ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutEncoderInformation ( )

@expectedException ilUserException

Definition at line 46 of file ilObjUserPasswordTest.php.

47 {
48 $this->assertException(ilUserException::class);
50 }

References ilUserBaseTest\assertException().

+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutFactory()

ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutFactory ( )

@expectedException ilUserException

Definition at line 55 of file ilObjUserPasswordTest.php.

56 {
57 $this->assertException(ilUserException::class);
59 array(
60 'password_encoder' => 'md5'
61 )
62 );
63 }

References ilUserBaseTest\assertException().

+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutValidFactory()

ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutValidFactory ( )

@expectedException PHPUnit_Framework_Error

Definition at line 68 of file ilObjUserPasswordTest.php.

69 {
70 $this->assertException(PHPUnit_Framework_Error::class);
71 try
72 {
74 array(
75 'password_encoder' => 'md5',
76 'encoder_factory' => 'test'
77 )
78 );
79 }
80 catch(TypeError $e)
81 {
82 throw new PHPUnit_Framework_Error($e->getMessage(), $e->getCode(), $e->getFile(), $e->getLine());
83 }
84 }

References ilUserBaseTest\assertException().

+ Here is the call graph for this function:

◆ testFactoryCanBeCreated()

ilObjUserPasswordTest::testFactoryCanBeCreated ( )

Definition at line 298 of file ilObjUserPasswordTest.php.

299 {
300 $factory = new ilUserPasswordEncoderFactory();
301 $this->assertInstanceOf('ilUserPasswordEncoderFactory', $factory);
302 }

◆ testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndNoDefaultEncoderWasSpecifiedInFallbackMode()

ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndNoDefaultEncoderWasSpecifiedInFallbackMode ( )

@expectedException ilUserException

Definition at line 348 of file ilObjUserPasswordTest.php.

349 {
350 $this->assertException(ilUserException::class);
351 $factory = new ilUserPasswordEncoderFactory();
352 $factory->getEncoderByName('phpunit', true);
353 }

References ilUserBaseTest\assertException().

+ Here is the call graph for this function:

◆ testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndTheDefaultEncoderDoesNotMatchOneOfTheSupportedEncodersInFallbackMode()

ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndTheDefaultEncoderDoesNotMatchOneOfTheSupportedEncodersInFallbackMode ( )

@expectedException ilUserException

Definition at line 358 of file ilObjUserPasswordTest.php.

359 {
360 $this->assertException(ilUserException::class);
361 $factory = new ilUserPasswordEncoderFactory(array('default_password_encoder' => 'phpunit'));
362 $factory->getEncoderByName('phpunit', true);
363 }

References ilUserBaseTest\assertException().

+ Here is the call graph for this function:

◆ testFactoryRaisesAnExceptionIfAnUnsupportedEncoderWasInjected()

ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderWasInjected ( )

@expectedException ilUserException

Definition at line 328 of file ilObjUserPasswordTest.php.

329 {
330 $this->assertException(ilUserException::class);
331 $factory = new ilUserPasswordEncoderFactory();
332 $factory->setEncoders(array('phpunit'));
333 }

References ilUserBaseTest\assertException().

+ Here is the call graph for this function:

◆ testFactoryReturnsCorrectEncoderIfAMatchingEncoderWasFound()

ilObjUserPasswordTest::testFactoryReturnsCorrectEncoderIfAMatchingEncoderWasFound ( )

Definition at line 381 of file ilObjUserPasswordTest.php.

382 {
383 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
384 $encoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('mockencoder'));
385
386 $factory = new ilUserPasswordEncoderFactory(array('default_password_encoder' => $encoder->getName()));
387 $factory->setEncoders(array($encoder));
388 $this->assertEquals($encoder, $factory->getEncoderByName('mockencoder', true));
389 }

◆ testFactoryReturnsTheDefaultEncoderIfAnUnsupportedEncoderIsRequestedAndASupportedDefaultEncoderWasSpecifiedInFallbackMode()

ilObjUserPasswordTest::testFactoryReturnsTheDefaultEncoderIfAnUnsupportedEncoderIsRequestedAndASupportedDefaultEncoderWasSpecifiedInFallbackMode ( )

Definition at line 368 of file ilObjUserPasswordTest.php.

369 {
370 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
371 $encoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('mockencoder'));
372
373 $factory = new ilUserPasswordEncoderFactory(array('default_password_encoder' => $encoder->getName()));
374 $factory->setEncoders(array($encoder));
375 $this->assertEquals($encoder, $factory->getEncoderByName('phpunit', true));
376 }

◆ testGettersOfFactoryShouldReturnWhatWasSetBySetters()

ilObjUserPasswordTest::testGettersOfFactoryShouldReturnWhatWasSetBySetters ( )

Definition at line 307 of file ilObjUserPasswordTest.php.

308 {
309 $factory = new ilUserPasswordEncoderFactory(array('default_password_encoder' => 'md5'));
310 $this->assertEquals('md5', $factory->getDefaultEncoder());
311
312 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
313 $encoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('mockencoder'));
314
315 $second_mockencoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
316 $second_mockencoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('second_mockencoder'));
317
318 $factory->setEncoders(array($encoder, $second_mockencoder));
319 $this->assertCount(2, $factory->getEncoders());
320 $this->assertCount(2, $factory->getSupportedEncoderNames());
321 $this->assertCount(0, array_diff(array('mockencoder', 'second_mockencoder'), $factory->getSupportedEncoderNames()));
322 $this->assertCount(0, array_diff($factory->getSupportedEncoderNames(), array('mockencoder', 'second_mockencoder')));
323 }

◆ testInstanceCanBeCreated()

ilObjUserPasswordTest::testInstanceCanBeCreated ( )

Definition at line 89 of file ilObjUserPasswordTest.php.

90 {
91 $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
92 $factory_mock->expects($this->exactly(2))->method('getSupportedEncoderNames')->will($this->onConsecutiveCalls(
93 array(
94 'mockencoder', 'second_mockencoder'
95 ),
96 array(
97 'mockencoder'
98 )
99 ));
100
101 $password_manager = new ilUserPasswordManager(
102 array(
103 'password_encoder' => 'md5',
104 'encoder_factory' => $factory_mock
105 )
106 );
107 $this->assertInstanceOf('ilUserPasswordManager', $password_manager);
108 $this->assertEquals('md5', $password_manager->getEncoderName());
109 $this->assertEquals($factory_mock, $password_manager->getEncoderFactory());
110
111 $this->assertTrue($password_manager->isEncodingTypeSupported('second_mockencoder'));
112 $this->assertFalse($password_manager->isEncodingTypeSupported('second_mockencoder'));
113 }

◆ testPasswordManagerEncodesRawPasswordWithoutSalt()

ilObjUserPasswordTest::testPasswordManagerEncodesRawPasswordWithoutSalt ( )

Definition at line 148 of file ilObjUserPasswordTest.php.

149 {
150 $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
151 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
152 $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
153
154 $user_mock->expects($this->once())->method('setPasswordSalt')->with($this->equalTo(null));
155 $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue(null));
156 $user_mock->expects($this->once())->method('setPasswordEncodingType')->with($this->equalTo('mockencoder'));
157 $user_mock->expects($this->once())->method('setPasswd')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(IL_PASSWD_CRYPTED));
158
159 $encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
160 $encoder->expects($this->once())->method('requiresSalt')->will($this->returnValue(false));
161 $encoder->expects($this->once())->method('encodePassword')->with($this->equalTo(self::PASSWORD), $this->equalTo(null))->will($this->returnValue(self::ENCODED_PASSWORD));
162
163 $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
164
165 $password_manager = new ilUserPasswordManager(
166 array(
167 'password_encoder' => 'mockencoder',
168 'encoder_factory' => $factory_mock
169 )
170 );
171
172 $password_manager->encodePassword($user_mock, self::PASSWORD);
173 }
const IL_PASSWD_CRYPTED

References IL_PASSWD_CRYPTED.

◆ testPasswordManagerEncodesRawPasswordWithSalt()

ilObjUserPasswordTest::testPasswordManagerEncodesRawPasswordWithSalt ( )

Definition at line 118 of file ilObjUserPasswordTest.php.

119 {
120 $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
121 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
122 $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
123
124 $user_mock->expects($this->once())->method('setPasswordSalt')->with($this->isType('string'));
125 $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
126 $user_mock->expects($this->once())->method('setPasswordEncodingType')->with($this->equalTo('mockencoder'));
127 $user_mock->expects($this->once())->method('setPasswd')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(IL_PASSWD_CRYPTED));
128
129 $encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
130 $encoder->expects($this->once())->method('requiresSalt')->will($this->returnValue(true));
131 $encoder->expects($this->once())->method('encodePassword')->with($this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(self::ENCODED_PASSWORD));
132
133 $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
134
135 $password_manager = new ilUserPasswordManager(
136 array(
137 'password_encoder' => 'mockencoder',
138 'encoder_factory' => $factory_mock
139 )
140 );
141
142 $password_manager->encodePassword($user_mock, self::PASSWORD);
143 }

References IL_PASSWD_CRYPTED.

◆ testPasswordManagerMigratesPasswordOnVerificationWithVariantEncoders()

ilObjUserPasswordTest::testPasswordManagerMigratesPasswordOnVerificationWithVariantEncoders ( )

Definition at line 208 of file ilObjUserPasswordTest.php.

209 {
210 $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
211 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
212 $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
213
214 $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
215 $user_mock->expects($this->once())->method('getPasswordEncodingType')->will($this->returnValue('second_mockencoder'));
216 $user_mock->expects($this->once())->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
217 $user_mock->expects($this->once())->method('resetPassword')->with($this->equalTo(self::PASSWORD), $this->equalTo(self::PASSWORD));
218
219 $encoder->expects($this->once())->method('getName')->will($this->returnValue('second_mockencoder'));
220 $encoder->expects($this->once())->method('isPasswordValid')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(true));
221 $encoder->expects($this->never())->method('requiresReencoding')->with($this->equalTo(self::ENCODED_PASSWORD))->will($this->returnValue(false));
222
223 $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
224
225 $password_manager = new ilUserPasswordManager(
226 array(
227 'password_encoder' => 'mockencoder',
228 'encoder_factory' => $factory_mock
229 )
230 );
231
232 $this->assertTrue($password_manager->verifyPassword($user_mock, self::PASSWORD));
233 }

◆ testPasswordManagerNeverMigratesPasswordOnFailedVerificationWithVariantEncoders()

ilObjUserPasswordTest::testPasswordManagerNeverMigratesPasswordOnFailedVerificationWithVariantEncoders ( )

Definition at line 268 of file ilObjUserPasswordTest.php.

269 {
270 $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
271 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
272 $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
273
274 $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
275 $user_mock->expects($this->once())->method('getPasswordEncodingType')->will($this->returnValue('second_mockencoder'));
276 $user_mock->expects($this->once())->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
277 $user_mock->expects($this->never())->method('resetPassword');
278
279 $encoder->expects($this->once())->method('getName')->will($this->returnValue('second_mockencoder'));
280 $encoder->expects($this->never())->method('requiresReencoding');
281 $encoder->expects($this->once())->method('isPasswordValid')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(false));
282
283 $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
284
285 $password_manager = new ilUserPasswordManager(
286 array(
287 'password_encoder' => 'mockencoder',
288 'encoder_factory' => $factory_mock
289 )
290 );
291
292 $this->assertFalse($password_manager->verifyPassword($user_mock, self::PASSWORD));
293 }

◆ testPasswordManagerReencodesPasswordIfReencodingIsNecessary()

ilObjUserPasswordTest::testPasswordManagerReencodesPasswordIfReencodingIsNecessary ( )

Definition at line 238 of file ilObjUserPasswordTest.php.

239 {
240 $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
241 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
242 $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
243
244 $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
245 $user_mock->expects($this->once())->method('getPasswordEncodingType')->will($this->returnValue('mockencoder'));
246 $user_mock->expects($this->exactly(2))->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
247 $user_mock->expects($this->once())->method('resetPassword')->with($this->equalTo(self::PASSWORD), $this->equalTo(self::PASSWORD));
248
249 $encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
250 $encoder->expects($this->once())->method('isPasswordValid')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(true));
251 $encoder->expects($this->once())->method('requiresReencoding')->with($this->equalTo(self::ENCODED_PASSWORD))->will($this->returnValue(true));
252
253 $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
254
255 $password_manager = new ilUserPasswordManager(
256 array(
257 'password_encoder' => 'mockencoder',
258 'encoder_factory' => $factory_mock
259 )
260 );
261
262 $this->assertTrue($password_manager->verifyPassword($user_mock, self::PASSWORD));
263 }

◆ testPasswordManagerVerifiesPassword()

ilObjUserPasswordTest::testPasswordManagerVerifiesPassword ( )

Definition at line 178 of file ilObjUserPasswordTest.php.

179 {
180 $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
181 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
182 $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
183
184 $user_mock->expects($this->atLeast(1))->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
185 $user_mock->expects($this->atLeast(1))->method('getPasswordEncodingType')->will($this->returnValue('mockencoder'));
186 $user_mock->expects($this->atLeast(1))->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
187 $user_mock->expects($this->never())->method('resetPassword');
188
189 $encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
190 $encoder->expects($this->once())->method('isPasswordValid')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(true));
191 $encoder->expects($this->once())->method('requiresReencoding')->with($this->equalTo(self::ENCODED_PASSWORD))->will($this->returnValue(false));
192
193 $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
194
195 $password_manager = new ilUserPasswordManager(
196 array(
197 'password_encoder' => 'mockencoder',
198 'encoder_factory' => $factory_mock
199 )
200 );
201
202 $this->assertTrue($password_manager->verifyPassword($user_mock, self::PASSWORD));
203 }

Field Documentation

◆ ENCODED_PASSWORD

const ilObjUserPasswordTest::ENCODED_PASSWORD = 'encoded'

Definition at line 27 of file ilObjUserPasswordTest.php.

◆ PASSWORD

const ilObjUserPasswordTest::PASSWORD = 'password'

Definition at line 22 of file ilObjUserPasswordTest.php.


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