ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilObjUserPasswordTest Class Reference
+ Inheritance diagram for ilObjUserPasswordTest:
+ Collaboration diagram for ilObjUserPasswordTest:

Public Member Functions

 getTestDirectory ()
 
 setTestDirectory (vfs\vfsStreamDirectory $testDirectory)
 
 getTestDirectoryUrl ()
 
 setTestDirectoryUrl (string $testDirectoryUrl)
 
 testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutEncoderInformation ()
 
 testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutFactory ()
 
 testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutValidFactory ()
 
 testInstanceCanBeCreated ()
 
 testPasswordManagerEncodesRawPasswordWithSalt ()
 
 testPasswordManagerEncodesRawPasswordWithoutSalt ()
 
 testPasswordManagerVerifiesPassword ()
 
 testPasswordManagerMigratesPasswordOnVerificationWithVariantEncoders ()
 
 testPasswordManagerReencodesPasswordIfReencodingIsNecessary ()
 
 testPasswordManagerNeverMigratesPasswordOnFailedVerificationWithVariantEncoders ()
 
 testFactoryCanBeCreated ()
 
 testGettersOfFactoryShouldReturnWhatWasSetBySetters ()
 
 testFactoryRaisesAnExceptionIfAnUnsupportedEncoderWasInjected ()
 
 testExceptionIsRaisedIfAnUnsupportedEncoderIsRequestedFromFactory ()
 
 testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndNoDefaultEncoderWasSpecifiedInFallbackMode ()
 
 testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndTheDefaultEncoderDoesNotMatchOneOfTheSupportedEncodersInFallbackMode ()
 
 testFactoryReturnsTheDefaultEncoderIfAnUnsupportedEncoderIsRequestedAndASupportedDefaultEncoderWasSpecifiedInFallbackMode ()
 
 testFactoryReturnsCorrectEncoderIfAMatchingEncoderWasFound ()
 

Data Fields

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

Protected Member Functions

 setUp ()
 Setup. More...
 
- Protected Member Functions inherited from ilUserBaseTest
 assertException ($exception_class)
 

Protected Attributes

 $testDirectory
 
 $testDirectoryUrl
 

Detailed Description

Definition at line 20 of file ilObjUserPasswordTest.php.

Member Function Documentation

◆ getTestDirectory()

ilObjUserPasswordTest::getTestDirectory ( )
Returns
vfs

Definition at line 37 of file ilObjUserPasswordTest.php.

References $testDirectory.

37  : vfs\vfsStreamDirectory
38  {
39  return $this->testDirectory;
40  }

◆ getTestDirectoryUrl()

ilObjUserPasswordTest::getTestDirectoryUrl ( )
Returns
string

Definition at line 53 of file ilObjUserPasswordTest.php.

References $testDirectoryUrl.

Referenced by testExceptionIsRaisedIfAnUnsupportedEncoderIsRequestedFromFactory(), testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutEncoderInformation(), testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutFactory(), testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutValidFactory(), testFactoryCanBeCreated(), testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndNoDefaultEncoderWasSpecifiedInFallbackMode(), testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndTheDefaultEncoderDoesNotMatchOneOfTheSupportedEncodersInFallbackMode(), testFactoryRaisesAnExceptionIfAnUnsupportedEncoderWasInjected(), testFactoryReturnsCorrectEncoderIfAMatchingEncoderWasFound(), testFactoryReturnsTheDefaultEncoderIfAnUnsupportedEncoderIsRequestedAndASupportedDefaultEncoderWasSpecifiedInFallbackMode(), testGettersOfFactoryShouldReturnWhatWasSetBySetters(), testInstanceCanBeCreated(), testPasswordManagerEncodesRawPasswordWithoutSalt(), testPasswordManagerEncodesRawPasswordWithSalt(), testPasswordManagerMigratesPasswordOnVerificationWithVariantEncoders(), testPasswordManagerNeverMigratesPasswordOnFailedVerificationWithVariantEncoders(), testPasswordManagerReencodesPasswordIfReencodingIsNecessary(), and testPasswordManagerVerifiesPassword().

53  : string
54  {
56  }
+ Here is the caller graph for this function:

◆ setTestDirectory()

ilObjUserPasswordTest::setTestDirectory ( vfs\vfsStreamDirectory  $testDirectory)
Parameters
vfs\vfsStreamDirectory$testDirectory

Definition at line 45 of file ilObjUserPasswordTest.php.

References $testDirectory.

Referenced by setUp().

45  : void
46  {
47  $this->testDirectory = $testDirectory;
48  }
+ Here is the caller graph for this function:

◆ setTestDirectoryUrl()

ilObjUserPasswordTest::setTestDirectoryUrl ( string  $testDirectoryUrl)
Parameters
string$testDirectoryUrl

Definition at line 61 of file ilObjUserPasswordTest.php.

References $testDirectoryUrl.

Referenced by setUp().

61  : void
62  {
63  $this->testDirectoryUrl = $testDirectoryUrl;
64  }
+ Here is the caller graph for this function:

◆ setUp()

ilObjUserPasswordTest::setUp ( )
protected

Setup.

Definition at line 69 of file ilObjUserPasswordTest.php.

References setTestDirectory(), and setTestDirectoryUrl().

69  : void
70  {
71  vfs\vfsStream::setup();
72  $this->setTestDirectory(vfs\vfsStream::newDirectory('tests')->at(vfs\vfsStreamWrapper::getRoot()));
73  $this->setTestDirectoryUrl(vfs\vfsStream::url('root/tests'));
74 
75  parent::setUp();
76  }
setTestDirectoryUrl(string $testDirectoryUrl)
setTestDirectory(vfs\vfsStreamDirectory $testDirectory)
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfAnUnsupportedEncoderIsRequestedFromFactory()

ilObjUserPasswordTest::testExceptionIsRaisedIfAnUnsupportedEncoderIsRequestedFromFactory ( )
Exceptions
ilPasswordException
ilUserException

Definition at line 446 of file ilObjUserPasswordTest.php.

References $factory, ilUserBaseTest\assertException(), and getTestDirectoryUrl().

446  : void
447  {
448  $this->assertException(ilUserException::class);
450  'default_password_encoder' => 'md5',
451  'data_directory' => $this->getTestDirectoryUrl()
452  ));
453  $factory->getEncoderByName('phpunit');
454  }
assertException($exception_class)
$factory
Definition: metadata.php:58
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutEncoderInformation()

ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutEncoderInformation ( )
Exceptions
ilUserException

Definition at line 81 of file ilObjUserPasswordTest.php.

References ilUserBaseTest\assertException(), and getTestDirectoryUrl().

81  : void
82  {
83  $this->assertException(ilUserException::class);
84  new ilUserPasswordManager(array('data_directory' => $this->getTestDirectoryUrl()));
85  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutFactory()

ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutFactory ( )
Exceptions
ilUserException

Definition at line 90 of file ilObjUserPasswordTest.php.

References ilUserBaseTest\assertException(), and getTestDirectoryUrl().

90  : void
91  {
92  $this->assertException(ilUserException::class);
94  array(
95  'password_encoder' => 'md5',
96  'data_directory' => $this->getTestDirectoryUrl()
97  )
98  );
99  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutValidFactory()

ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutValidFactory ( )
Exceptions
ilUserException

Definition at line 104 of file ilObjUserPasswordTest.php.

References Vendor\Package\$e, ilUserBaseTest\assertException(), and getTestDirectoryUrl().

104  : void
105  {
106  $this->assertException(PHPUnit\Framework\Error\Error::class);
107  try {
109  array(
110  'password_encoder' => 'md5',
111  'encoder_factory' => 'test',
112  'data_directory' => $this->getTestDirectoryUrl()
113  )
114  );
115  } catch (TypeError $e) {
116  throw new PHPUnit\Framework\Error\Error($e->getMessage(), $e->getCode(), $e->getFile(), $e->getLine());
117  }
118  }
assertException($exception_class)
+ Here is the call graph for this function:

◆ testFactoryCanBeCreated()

ilObjUserPasswordTest::testFactoryCanBeCreated ( )
Exceptions
ilPasswordException

Definition at line 389 of file ilObjUserPasswordTest.php.

References $factory, and getTestDirectoryUrl().

389  : void
390  {
392  'data_directory' => $this->getTestDirectoryUrl()
393  ]);
394  $this->assertInstanceOf('ilUserPasswordEncoderFactory', $factory);
395  }
$factory
Definition: metadata.php:58
+ Here is the call graph for this function:

◆ testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndNoDefaultEncoderWasSpecifiedInFallbackMode()

ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndNoDefaultEncoderWasSpecifiedInFallbackMode ( )
Exceptions
ilPasswordException
ilUserException

Definition at line 460 of file ilObjUserPasswordTest.php.

References $factory, ilUserBaseTest\assertException(), and getTestDirectoryUrl().

460  : void
461  {
462  $this->assertException(ilUserException::class);
464  'data_directory' => $this->getTestDirectoryUrl()
465  ));
466  $factory->getEncoderByName('phpunit', true);
467  }
assertException($exception_class)
$factory
Definition: metadata.php:58
+ Here is the call graph for this function:

◆ testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndTheDefaultEncoderDoesNotMatchOneOfTheSupportedEncodersInFallbackMode()

ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndTheDefaultEncoderDoesNotMatchOneOfTheSupportedEncodersInFallbackMode ( )
Exceptions
ilPasswordException
ilUserException

Definition at line 473 of file ilObjUserPasswordTest.php.

References $factory, ilUserBaseTest\assertException(), and getTestDirectoryUrl().

473  : void
474  {
475  $this->assertException(ilUserException::class);
477  'default_password_encoder' => 'phpunit',
478  'data_directory' => $this->getTestDirectoryUrl()
479  ));
480  $factory->getEncoderByName('phpunit', true);
481  }
assertException($exception_class)
$factory
Definition: metadata.php:58
+ Here is the call graph for this function:

◆ testFactoryRaisesAnExceptionIfAnUnsupportedEncoderWasInjected()

ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderWasInjected ( )
Exceptions
ilPasswordException
ilUserException

Definition at line 433 of file ilObjUserPasswordTest.php.

References $factory, ilUserBaseTest\assertException(), and getTestDirectoryUrl().

433  : void
434  {
435  $this->assertException(ilUserException::class);
437  'data_directory' => $this->getTestDirectoryUrl()
438  ));
439  $factory->setEncoders(array('phpunit'));
440  }
assertException($exception_class)
$factory
Definition: metadata.php:58
+ Here is the call graph for this function:

◆ testFactoryReturnsCorrectEncoderIfAMatchingEncoderWasFound()

ilObjUserPasswordTest::testFactoryReturnsCorrectEncoderIfAMatchingEncoderWasFound ( )
Exceptions
ilUserException
ilPasswordException
ReflectionException

Definition at line 506 of file ilObjUserPasswordTest.php.

References $factory, and getTestDirectoryUrl().

506  : void
507  {
508  $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
509  $encoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('mockencoder'));
510 
512  'default_password_encoder' => $encoder->getName(),
513  'data_directory' => $this->getTestDirectoryUrl()
514  ));
515  $factory->setEncoders(array($encoder));
516  $this->assertEquals($encoder, $factory->getEncoderByName('mockencoder', true));
517  }
$factory
Definition: metadata.php:58
+ Here is the call graph for this function:

◆ testFactoryReturnsTheDefaultEncoderIfAnUnsupportedEncoderIsRequestedAndASupportedDefaultEncoderWasSpecifiedInFallbackMode()

ilObjUserPasswordTest::testFactoryReturnsTheDefaultEncoderIfAnUnsupportedEncoderIsRequestedAndASupportedDefaultEncoderWasSpecifiedInFallbackMode ( )
Exceptions
ReflectionException
ilPasswordException
ilUserException

Definition at line 488 of file ilObjUserPasswordTest.php.

References $factory, and getTestDirectoryUrl().

488  : void
489  {
490  $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
491  $encoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('mockencoder'));
492 
494  'default_password_encoder' => $encoder->getName(),
495  'data_directory' => $this->getTestDirectoryUrl()
496  ));
497  $factory->setEncoders(array($encoder));
498  $this->assertEquals($encoder, $factory->getEncoderByName('phpunit', true));
499  }
$factory
Definition: metadata.php:58
+ Here is the call graph for this function:

◆ testGettersOfFactoryShouldReturnWhatWasSetBySetters()

ilObjUserPasswordTest::testGettersOfFactoryShouldReturnWhatWasSetBySetters ( )
Exceptions
ReflectionException
ilPasswordException
ilUserException

Definition at line 402 of file ilObjUserPasswordTest.php.

References $factory, and getTestDirectoryUrl().

402  : void
403  {
405  'default_password_encoder' => 'md5',
406  'data_directory' => $this->getTestDirectoryUrl()
407  ));
408  $this->assertEquals('md5', $factory->getDefaultEncoder());
409 
410  $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
411  $encoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('mockencoder'));
412 
413  $second_mockencoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
414  $second_mockencoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('second_mockencoder'));
415 
416  $factory->setEncoders(array($encoder, $second_mockencoder));
417  $this->assertCount(2, $factory->getEncoders());
418  $this->assertCount(2, $factory->getSupportedEncoderNames());
419  $this->assertCount(
420  0,
421  array_diff(array('mockencoder', 'second_mockencoder'), $factory->getSupportedEncoderNames())
422  );
423  $this->assertCount(
424  0,
425  array_diff($factory->getSupportedEncoderNames(), array('mockencoder', 'second_mockencoder'))
426  );
427  }
$factory
Definition: metadata.php:58
+ Here is the call graph for this function:

◆ testInstanceCanBeCreated()

ilObjUserPasswordTest::testInstanceCanBeCreated ( )
Exceptions
ilUserException
ReflectionException

Definition at line 124 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl().

124  : void
125  {
126  $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
127  $factory_mock->expects($this->exactly(2))->method('getSupportedEncoderNames')->will($this->onConsecutiveCalls(
128  array(
129  'mockencoder',
130  'second_mockencoder'
131  ),
132  array(
133  'mockencoder'
134  )
135  ));
136 
137  $password_manager = new ilUserPasswordManager(
138  array(
139  'password_encoder' => 'md5',
140  'encoder_factory' => $factory_mock,
141  'data_directory' => $this->getTestDirectoryUrl()
142  )
143  );
144  $this->assertInstanceOf('ilUserPasswordManager', $password_manager);
145  $this->assertEquals('md5', $password_manager->getEncoderName());
146  $this->assertEquals($factory_mock, $password_manager->getEncoderFactory());
147 
148  $this->assertTrue($password_manager->isEncodingTypeSupported('second_mockencoder'));
149  $this->assertFalse($password_manager->isEncodingTypeSupported('second_mockencoder'));
150  }
+ Here is the call graph for this function:

◆ testPasswordManagerEncodesRawPasswordWithoutSalt()

ilObjUserPasswordTest::testPasswordManagerEncodesRawPasswordWithoutSalt ( )
Exceptions
ilUserException
ReflectionException

Definition at line 195 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl(), and IL_PASSWD_CRYPTED.

195  : void
196  {
197  $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
198  $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
199  $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
200 
201  $user_mock->expects($this->once())->method('setPasswordSalt')->with($this->equalTo(null));
202  $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue(null));
203  $user_mock->expects($this->once())->method('setPasswordEncodingType')->with($this->equalTo('mockencoder'));
204  $user_mock->expects($this->once())->method('setPasswd')->with(
205  $this->equalTo(self::ENCODED_PASSWORD),
206  $this->equalTo(IL_PASSWD_CRYPTED)
207  );
208 
209  $encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
210  $encoder->expects($this->once())->method('requiresSalt')->will($this->returnValue(false));
211  $encoder->expects($this->once())->method('encodePassword')->with(
212  $this->equalTo(self::PASSWORD),
213  $this->equalTo(null)
214  )->will($this->returnValue(self::ENCODED_PASSWORD));
215 
216  $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
217 
218  $password_manager = new ilUserPasswordManager(
219  array(
220  'password_encoder' => 'mockencoder',
221  'encoder_factory' => $factory_mock,
222  'data_directory' => $this->getTestDirectoryUrl()
223  )
224  );
225 
226  $password_manager->encodePassword($user_mock, self::PASSWORD);
227  }
const IL_PASSWD_CRYPTED
+ Here is the call graph for this function:

◆ testPasswordManagerEncodesRawPasswordWithSalt()

ilObjUserPasswordTest::testPasswordManagerEncodesRawPasswordWithSalt ( )
Exceptions
ilUserException
ReflectionException

Definition at line 156 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl(), and IL_PASSWD_CRYPTED.

156  : void
157  {
158  $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
159  $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
160  $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
161 
162  $user_mock->expects($this->once())->method('setPasswordSalt')->with($this->isType('string'));
163  $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
164  $user_mock->expects($this->once())->method('setPasswordEncodingType')->with($this->equalTo('mockencoder'));
165  $user_mock->expects($this->once())->method('setPasswd')->with(
166  $this->equalTo(self::ENCODED_PASSWORD),
167  $this->equalTo(IL_PASSWD_CRYPTED)
168  );
169 
170  $encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
171  $encoder->expects($this->once())->method('requiresSalt')->will($this->returnValue(true));
172  $encoder->expects($this->once())->method('encodePassword')
173  ->with(
174  $this->equalTo(self::PASSWORD),
175  $this->isType('string')
176  )->will($this->returnValue(self::ENCODED_PASSWORD));
177 
178  $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
179 
180  $password_manager = new ilUserPasswordManager(
181  array(
182  'password_encoder' => 'mockencoder',
183  'encoder_factory' => $factory_mock,
184  'data_directory' => $this->getTestDirectoryUrl()
185  )
186  );
187 
188  $password_manager->encodePassword($user_mock, self::PASSWORD);
189  }
const IL_PASSWD_CRYPTED
+ Here is the call graph for this function:

◆ testPasswordManagerMigratesPasswordOnVerificationWithVariantEncoders()

ilObjUserPasswordTest::testPasswordManagerMigratesPasswordOnVerificationWithVariantEncoders ( )
Exceptions
ilUserException
ReflectionException

Definition at line 271 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl().

271  : void
272  {
273  $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
274  $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
275  $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
276 
277  $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
278  $user_mock->expects($this->once())->method('getPasswordEncodingType')->will($this->returnValue('second_mockencoder'));
279  $user_mock->expects($this->once())->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
280  $user_mock->expects($this->once())->method('resetPassword')->with(
281  $this->equalTo(self::PASSWORD),
282  $this->equalTo(self::PASSWORD)
283  );
284 
285  $encoder->expects($this->once())->method('getName')->will($this->returnValue('second_mockencoder'));
286  $encoder->expects($this->once())->method('isPasswordValid')->with(
287  $this->equalTo(self::ENCODED_PASSWORD),
288  $this->equalTo(self::PASSWORD),
289  $this->isType('string')
290  )->will($this->returnValue(true));
291  $encoder->expects($this->never())->method('requiresReencoding')
292  ->with($this->equalTo(self::ENCODED_PASSWORD))
293  ->will($this->returnValue(false));
294 
295  $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
296 
297  $password_manager = new ilUserPasswordManager(
298  array(
299  'password_encoder' => 'mockencoder',
300  'encoder_factory' => $factory_mock,
301  'data_directory' => $this->getTestDirectoryUrl()
302  )
303  );
304 
305  $this->assertTrue($password_manager->verifyPassword($user_mock, self::PASSWORD));
306  }
+ Here is the call graph for this function:

◆ testPasswordManagerNeverMigratesPasswordOnFailedVerificationWithVariantEncoders()

ilObjUserPasswordTest::testPasswordManagerNeverMigratesPasswordOnFailedVerificationWithVariantEncoders ( )
Exceptions
ilUserException
ReflectionException

Definition at line 353 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl().

353  : void
354  {
355  $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
356  $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
357  $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
358 
359  $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
360  $user_mock->expects($this->once())->method('getPasswordEncodingType')->will($this->returnValue('second_mockencoder'));
361  $user_mock->expects($this->once())->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
362  $user_mock->expects($this->never())->method('resetPassword');
363 
364  $encoder->expects($this->once())->method('getName')->will($this->returnValue('second_mockencoder'));
365  $encoder->expects($this->never())->method('requiresReencoding');
366  $encoder->expects($this->once())->method('isPasswordValid')
367  ->with(
368  $this->equalTo(self::ENCODED_PASSWORD),
369  $this->equalTo(self::PASSWORD),
370  $this->isType('string')
371  )->will($this->returnValue(false));
372 
373  $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
374 
375  $password_manager = new ilUserPasswordManager(
376  array(
377  'password_encoder' => 'mockencoder',
378  'encoder_factory' => $factory_mock,
379  'data_directory' => $this->getTestDirectoryUrl()
380  )
381  );
382 
383  $this->assertFalse($password_manager->verifyPassword($user_mock, self::PASSWORD));
384  }
+ Here is the call graph for this function:

◆ testPasswordManagerReencodesPasswordIfReencodingIsNecessary()

ilObjUserPasswordTest::testPasswordManagerReencodesPasswordIfReencodingIsNecessary ( )
Exceptions
ilUserException
ReflectionException

Definition at line 312 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl().

312  : void
313  {
314  $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
315  $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
316  $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
317 
318  $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
319  $user_mock->expects($this->once())->method('getPasswordEncodingType')->will($this->returnValue('mockencoder'));
320  $user_mock->expects($this->exactly(2))->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
321  $user_mock->expects($this->once())->method('resetPassword')->with(
322  $this->equalTo(self::PASSWORD),
323  $this->equalTo(self::PASSWORD)
324  );
325 
326  $encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
327  $encoder->expects($this->once())->method('isPasswordValid')->with(
328  $this->equalTo(self::ENCODED_PASSWORD),
329  $this->equalTo(self::PASSWORD),
330  $this->isType('string')
331  )->will($this->returnValue(true));
332  $encoder->expects($this->once())->method('requiresReencoding')
333  ->with($this->equalTo(self::ENCODED_PASSWORD))
334  ->will($this->returnValue(true));
335 
336  $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
337 
338  $password_manager = new ilUserPasswordManager(
339  array(
340  'password_encoder' => 'mockencoder',
341  'encoder_factory' => $factory_mock,
342  'data_directory' => $this->getTestDirectoryUrl()
343  )
344  );
345 
346  $this->assertTrue($password_manager->verifyPassword($user_mock, self::PASSWORD));
347  }
+ Here is the call graph for this function:

◆ testPasswordManagerVerifiesPassword()

ilObjUserPasswordTest::testPasswordManagerVerifiesPassword ( )
Exceptions
ilUserException
ReflectionException

Definition at line 233 of file ilObjUserPasswordTest.php.

References getTestDirectoryUrl().

233  : void
234  {
235  $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
236  $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
237  $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
238 
239  $user_mock->expects($this->atLeast(1))->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
240  $user_mock->expects($this->atLeast(1))->method('getPasswordEncodingType')->will($this->returnValue('mockencoder'));
241  $user_mock->expects($this->atLeast(1))->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
242  $user_mock->expects($this->never())->method('resetPassword');
243 
244  $encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
245  $encoder->expects($this->once())->method('isPasswordValid')->with(
246  $this->equalTo(self::ENCODED_PASSWORD),
247  $this->equalTo(self::PASSWORD),
248  $this->isType('string')
249  )->will($this->returnValue(true));
250  $encoder->expects($this->once())->method('requiresReencoding')
251  ->with($this->equalTo(self::ENCODED_PASSWORD))
252  ->will($this->returnValue(false));
253 
254  $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
255 
256  $password_manager = new ilUserPasswordManager(
257  array(
258  'password_encoder' => 'mockencoder',
259  'encoder_factory' => $factory_mock,
260  'data_directory' => $this->getTestDirectoryUrl()
261  )
262  );
263 
264  $this->assertTrue($password_manager->verifyPassword($user_mock, self::PASSWORD));
265  }
+ Here is the call graph for this function:

Field Documentation

◆ $testDirectory

ilObjUserPasswordTest::$testDirectory
protected

Definition at line 29 of file ilObjUserPasswordTest.php.

Referenced by getTestDirectory(), and setTestDirectory().

◆ $testDirectoryUrl

ilObjUserPasswordTest::$testDirectoryUrl
protected

Definition at line 32 of file ilObjUserPasswordTest.php.

Referenced by getTestDirectoryUrl(), and setTestDirectoryUrl().

◆ ENCODED_PASSWORD

const ilObjUserPasswordTest::ENCODED_PASSWORD = 'encoded'

Definition at line 26 of file ilObjUserPasswordTest.php.

◆ PASSWORD

const ilObjUserPasswordTest::PASSWORD = 'password'

Definition at line 23 of file ilObjUserPasswordTest.php.


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