ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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'
 

Detailed Description

Definition at line 15 of file ilObjUserPasswordTest.php.

Member Function Documentation

◆ testExceptionIsRaisedIfAnUnsupportedEncoderIsRequestedFromFactory()

ilObjUserPasswordTest::testExceptionIsRaisedIfAnUnsupportedEncoderIsRequestedFromFactory ( )

@expectedException ilUserException

Definition at line 277 of file ilObjUserPasswordTest.php.

278 {
279 $factory = new ilUserPasswordEncoderFactory(array('default_password_encoder' => 'md5'));
280 $factory->getEncoderByName('phpunit');
281 }

◆ testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutEncoderInformation()

ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutEncoderInformation ( )

@expectedException ilUserException

Definition at line 30 of file ilObjUserPasswordTest.php.

◆ testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutFactory()

ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutFactory ( )

@expectedException ilUserException

Definition at line 38 of file ilObjUserPasswordTest.php.

39 {
41 array(
42 'password_encoder' => 'md5'
43 )
44 );
45 }

◆ testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutValidFactory()

ilObjUserPasswordTest::testExceptionIsRaisedIfPasswordManagerIsCreatedWithoutValidFactory ( )

@expectedException PHPUnit_Framework_Error

Definition at line 50 of file ilObjUserPasswordTest.php.

51 {
53 array(
54 'password_encoder' => 'md5',
55 'encoder_factory' => 'test'
56 )
57 );
58 }

◆ testFactoryCanBeCreated()

ilObjUserPasswordTest::testFactoryCanBeCreated ( )

Definition at line 238 of file ilObjUserPasswordTest.php.

239 {
240 $factory = new ilUserPasswordEncoderFactory();
241 $this->assertInstanceOf('ilUserPasswordEncoderFactory', $factory);
242 }

◆ testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndNoDefaultEncoderWasSpecifiedInFallbackMode()

ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndNoDefaultEncoderWasSpecifiedInFallbackMode ( )

@expectedException ilUserException

Definition at line 286 of file ilObjUserPasswordTest.php.

287 {
288 $factory = new ilUserPasswordEncoderFactory();
289 $factory->getEncoderByName('phpunit', true);
290 }

◆ testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndTheDefaultEncoderDoesNotMatchOneOfTheSupportedEncodersInFallbackMode()

ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderIsRequestedAndTheDefaultEncoderDoesNotMatchOneOfTheSupportedEncodersInFallbackMode ( )

@expectedException ilUserException

Definition at line 295 of file ilObjUserPasswordTest.php.

296 {
297 $factory = new ilUserPasswordEncoderFactory(array('default_password_encoder' => 'phpunit'));
298 $factory->getEncoderByName('phpunit', true);
299 }

◆ testFactoryRaisesAnExceptionIfAnUnsupportedEncoderWasInjected()

ilObjUserPasswordTest::testFactoryRaisesAnExceptionIfAnUnsupportedEncoderWasInjected ( )

@expectedException ilUserException

Definition at line 268 of file ilObjUserPasswordTest.php.

269 {
270 $factory = new ilUserPasswordEncoderFactory();
271 $factory->setEncoders(array('phpunit'));
272 }

◆ testFactoryReturnsCorrectEncoderIfAMatchingEncoderWasFound()

ilObjUserPasswordTest::testFactoryReturnsCorrectEncoderIfAMatchingEncoderWasFound ( )

Definition at line 317 of file ilObjUserPasswordTest.php.

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

◆ testFactoryReturnsTheDefaultEncoderIfAnUnsupportedEncoderIsRequestedAndASupportedDefaultEncoderWasSpecifiedInFallbackMode()

ilObjUserPasswordTest::testFactoryReturnsTheDefaultEncoderIfAnUnsupportedEncoderIsRequestedAndASupportedDefaultEncoderWasSpecifiedInFallbackMode ( )

Definition at line 304 of file ilObjUserPasswordTest.php.

305 {
306 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
307 $encoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('mockencoder'));
308
309 $factory = new ilUserPasswordEncoderFactory(array('default_password_encoder' => $encoder->getName()));
310 $factory->setEncoders(array($encoder));
311 $this->assertEquals($encoder, $factory->getEncoderByName('phpunit', true));
312 }

◆ testGettersOfFactoryShouldReturnWhatWasSetBySetters()

ilObjUserPasswordTest::testGettersOfFactoryShouldReturnWhatWasSetBySetters ( )

Definition at line 247 of file ilObjUserPasswordTest.php.

248 {
249 $factory = new ilUserPasswordEncoderFactory(array('default_password_encoder' => 'md5'));
250 $this->assertEquals('md5', $factory->getDefaultEncoder());
251
252 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
253 $encoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('mockencoder'));
254
255 $second_mockencoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
256 $second_mockencoder->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('second_mockencoder'));
257
258 $factory->setEncoders(array($encoder, $second_mockencoder));
259 $this->assertCount(2, $factory->getEncoders());
260 $this->assertCount(2, $factory->getSupportedEncoderNames());
261 $this->assertCount(0, array_diff(array('mockencoder', 'second_mockencoder'), $factory->getSupportedEncoderNames()));
262 $this->assertCount(0, array_diff($factory->getSupportedEncoderNames(), array('mockencoder', 'second_mockencoder')));
263 }

◆ testInstanceCanBeCreated()

ilObjUserPasswordTest::testInstanceCanBeCreated ( )

Definition at line 63 of file ilObjUserPasswordTest.php.

64 {
65 $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
66 $factory_mock->expects($this->exactly(2))->method('getSupportedEncoderNames')->will($this->onConsecutiveCalls(
67 array(
68 'mockencoder', 'second_mockencoder'
69 ),
70 array(
71 'mockencoder'
72 )
73 ));
74
75 $password_manager = new ilUserPasswordManager(
76 array(
77 'password_encoder' => 'md5',
78 'encoder_factory' => $factory_mock
79 )
80 );
81 $this->assertInstanceOf('ilUserPasswordManager', $password_manager);
82 $this->assertEquals('md5', $password_manager->getEncoderName());
83 $this->assertEquals($factory_mock, $password_manager->getEncoderFactory());
84
85 $this->assertTrue($password_manager->isEncodingTypeSupported('second_mockencoder'));
86 $this->assertFalse($password_manager->isEncodingTypeSupported('second_mockencoder'));
87 }

◆ testPasswordManagerEncodesRawPasswordWithoutSalt()

ilObjUserPasswordTest::testPasswordManagerEncodesRawPasswordWithoutSalt ( )

Definition at line 122 of file ilObjUserPasswordTest.php.

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

References IL_PASSWD_CRYPTED.

◆ testPasswordManagerEncodesRawPasswordWithSalt()

ilObjUserPasswordTest::testPasswordManagerEncodesRawPasswordWithSalt ( )

Definition at line 92 of file ilObjUserPasswordTest.php.

93 {
94 $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
95 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
96 $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
97
98 $user_mock->expects($this->once())->method('setPasswordSalt')->with($this->isType('string'));
99 $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
100 $user_mock->expects($this->once())->method('setPasswordEncodingType')->with($this->equalTo('mockencoder'));
101 $user_mock->expects($this->once())->method('setPasswd')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(IL_PASSWD_CRYPTED));
102
103 $encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
104 $encoder->expects($this->once())->method('requiresSalt')->will($this->returnValue(true));
105 $encoder->expects($this->once())->method('encodePassword')->with($this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(self::ENCODED_PASSWORD));
106
107 $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
108
109 $password_manager = new ilUserPasswordManager(
110 array(
111 'password_encoder' => 'mockencoder',
112 'encoder_factory' => $factory_mock
113 )
114 );
115
116 $password_manager->encodePassword($user_mock, self::PASSWORD);
117 }

References IL_PASSWD_CRYPTED.

◆ testPasswordManagerMigratesPasswordOnVerificationWithVariantEncoders()

ilObjUserPasswordTest::testPasswordManagerMigratesPasswordOnVerificationWithVariantEncoders ( )

Definition at line 180 of file ilObjUserPasswordTest.php.

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

◆ testPasswordManagerNeverMigratesPasswordOnFailedVerificationWithVariantEncoders()

ilObjUserPasswordTest::testPasswordManagerNeverMigratesPasswordOnFailedVerificationWithVariantEncoders ( )

Definition at line 209 of file ilObjUserPasswordTest.php.

210 {
211 $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
212 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
213 $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
214
215 $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
216 $user_mock->expects($this->once())->method('getPasswordEncodingType')->will($this->returnValue('second_mockencoder'));
217 $user_mock->expects($this->once())->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
218 $user_mock->expects($this->never())->method('resetPassword');
219
220 $encoder->expects($this->once())->method('getName')->will($this->returnValue('second_mockencoder'));
221 $encoder->expects($this->once())->method('isPasswordValid')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(self::PASSWORD), $this->isType('string'))->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->assertFalse($password_manager->verifyPassword($user_mock, self::PASSWORD));
233 }

◆ testPasswordManagerVerifiesPassword()

ilObjUserPasswordTest::testPasswordManagerVerifiesPassword ( )

Definition at line 152 of file ilObjUserPasswordTest.php.

153 {
154 $user_mock = $this->getMockBuilder('ilObjUser')->disableOriginalConstructor()->getMock();
155 $encoder = $this->getMockBuilder('ilBasePasswordEncoder')->disableOriginalConstructor()->getMock();
156 $factory_mock = $this->getMockBuilder('ilUserPasswordEncoderFactory')->disableOriginalConstructor()->getMock();
157
158 $user_mock->expects($this->once())->method('getPasswordSalt')->will($this->returnValue('asuperrandomsalt'));
159 $user_mock->expects($this->once())->method('getPasswordEncodingType')->will($this->returnValue('mockencoder'));
160 $user_mock->expects($this->once())->method('getPasswd')->will($this->returnValue(self::ENCODED_PASSWORD));
161
162 $encoder->expects($this->once())->method('getName')->will($this->returnValue('mockencoder'));
163 $encoder->expects($this->once())->method('isPasswordValid')->with($this->equalTo(self::ENCODED_PASSWORD), $this->equalTo(self::PASSWORD), $this->isType('string'))->will($this->returnValue(true));
164
165 $factory_mock->expects($this->once())->method('getEncoderByName')->will($this->returnValue($encoder));
166
167 $password_manager = new ilUserPasswordManager(
168 array(
169 'password_encoder' => 'mockencoder',
170 'encoder_factory' => $factory_mock
171 )
172 );
173
174 $this->assertTrue($password_manager->verifyPassword($user_mock, self::PASSWORD));
175 }

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: