@@ -16,40 +16,40 @@ |
||
16 | 16 | use Psr\Log\LoggerInterface; |
17 | 17 | |
18 | 18 | class LoggedInCheckCommandTest extends ALoginTestCommand { |
19 | - /** @var LoggerInterface|MockObject */ |
|
20 | - private $logger; |
|
19 | + /** @var LoggerInterface|MockObject */ |
|
20 | + private $logger; |
|
21 | 21 | |
22 | - /** @var IEventDispatcher|MockObject */ |
|
23 | - private $dispatcher; |
|
22 | + /** @var IEventDispatcher|MockObject */ |
|
23 | + private $dispatcher; |
|
24 | 24 | |
25 | - protected function setUp(): void { |
|
26 | - parent::setUp(); |
|
25 | + protected function setUp(): void { |
|
26 | + parent::setUp(); |
|
27 | 27 | |
28 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
29 | - $this->dispatcher = $this->createMock(IEventDispatcher::class); |
|
28 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
29 | + $this->dispatcher = $this->createMock(IEventDispatcher::class); |
|
30 | 30 | |
31 | - $this->cmd = new LoggedInCheckCommand( |
|
32 | - $this->logger, |
|
33 | - $this->dispatcher |
|
34 | - ); |
|
35 | - } |
|
31 | + $this->cmd = new LoggedInCheckCommand( |
|
32 | + $this->logger, |
|
33 | + $this->dispatcher |
|
34 | + ); |
|
35 | + } |
|
36 | 36 | |
37 | - public function testProcessSuccessfulLogin(): void { |
|
38 | - $data = $this->getLoggedInLoginData(); |
|
37 | + public function testProcessSuccessfulLogin(): void { |
|
38 | + $data = $this->getLoggedInLoginData(); |
|
39 | 39 | |
40 | - $result = $this->cmd->process($data); |
|
40 | + $result = $this->cmd->process($data); |
|
41 | 41 | |
42 | - $this->assertTrue($result->isSuccess()); |
|
43 | - } |
|
42 | + $this->assertTrue($result->isSuccess()); |
|
43 | + } |
|
44 | 44 | |
45 | - public function testProcessFailedLogin(): void { |
|
46 | - $data = $this->getFailedLoginData(); |
|
47 | - $this->logger->expects($this->once()) |
|
48 | - ->method('warning'); |
|
45 | + public function testProcessFailedLogin(): void { |
|
46 | + $data = $this->getFailedLoginData(); |
|
47 | + $this->logger->expects($this->once()) |
|
48 | + ->method('warning'); |
|
49 | 49 | |
50 | - $result = $this->cmd->process($data); |
|
50 | + $result = $this->cmd->process($data); |
|
51 | 51 | |
52 | - $this->assertFalse($result->isSuccess()); |
|
53 | - $this->assertSame(LoginController::LOGIN_MSG_INVALIDPASSWORD, $result->getErrorMessage()); |
|
54 | - } |
|
52 | + $this->assertFalse($result->isSuccess()); |
|
53 | + $this->assertSame(LoginController::LOGIN_MSG_INVALIDPASSWORD, $result->getErrorMessage()); |
|
54 | + } |
|
55 | 55 | } |
@@ -19,323 +19,323 @@ |
||
19 | 19 | use PHPUnit\Framework\MockObject\MockObject; |
20 | 20 | |
21 | 21 | class TwoFactorCommandTest extends ALoginTestCommand { |
22 | - /** @var Manager|MockObject */ |
|
23 | - private $twoFactorManager; |
|
24 | - |
|
25 | - /** @var MandatoryTwoFactor|MockObject */ |
|
26 | - private $mandatoryTwoFactor; |
|
27 | - |
|
28 | - /** @var IURLGenerator|MockObject */ |
|
29 | - private $urlGenerator; |
|
30 | - |
|
31 | - protected function setUp(): void { |
|
32 | - parent::setUp(); |
|
33 | - |
|
34 | - $this->twoFactorManager = $this->createMock(Manager::class); |
|
35 | - $this->mandatoryTwoFactor = $this->createMock(MandatoryTwoFactor::class); |
|
36 | - $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
37 | - |
|
38 | - $this->cmd = new TwoFactorCommand( |
|
39 | - $this->twoFactorManager, |
|
40 | - $this->mandatoryTwoFactor, |
|
41 | - $this->urlGenerator |
|
42 | - ); |
|
43 | - } |
|
44 | - |
|
45 | - public function testNotTwoFactorAuthenticated(): void { |
|
46 | - $data = $this->getLoggedInLoginData(); |
|
47 | - $this->twoFactorManager->expects($this->once()) |
|
48 | - ->method('isTwoFactorAuthenticated') |
|
49 | - ->willReturn(false); |
|
50 | - $this->twoFactorManager->expects($this->never()) |
|
51 | - ->method('prepareTwoFactorLogin'); |
|
52 | - |
|
53 | - $result = $this->cmd->process($data); |
|
54 | - |
|
55 | - $this->assertTrue($result->isSuccess()); |
|
56 | - } |
|
57 | - |
|
58 | - public function testProcessOneActiveProvider(): void { |
|
59 | - $data = $this->getLoggedInLoginData(); |
|
60 | - $this->twoFactorManager->expects($this->once()) |
|
61 | - ->method('isTwoFactorAuthenticated') |
|
62 | - ->willReturn(true); |
|
63 | - $this->twoFactorManager->expects($this->once()) |
|
64 | - ->method('prepareTwoFactorLogin') |
|
65 | - ->with( |
|
66 | - $this->user, |
|
67 | - $data->isRememberLogin() |
|
68 | - ); |
|
69 | - $provider = $this->createMock(ITwoFactorAuthProvider::class); |
|
70 | - $this->twoFactorManager->expects($this->once()) |
|
71 | - ->method('getProviderSet') |
|
72 | - ->willReturn(new ProviderSet([ |
|
73 | - $provider, |
|
74 | - ], false)); |
|
75 | - $this->twoFactorManager->expects($this->once()) |
|
76 | - ->method('getLoginSetupProviders') |
|
77 | - ->with($this->user) |
|
78 | - ->willReturn([]); |
|
79 | - $this->mandatoryTwoFactor->expects($this->any()) |
|
80 | - ->method('isEnforcedFor') |
|
81 | - ->with($this->user) |
|
82 | - ->willReturn(false); |
|
83 | - $provider->expects($this->once()) |
|
84 | - ->method('getId') |
|
85 | - ->willReturn('test'); |
|
86 | - $this->urlGenerator->expects($this->once()) |
|
87 | - ->method('linkToRoute') |
|
88 | - ->with( |
|
89 | - 'core.TwoFactorChallenge.showChallenge', |
|
90 | - [ |
|
91 | - 'challengeProviderId' => 'test' |
|
92 | - ] |
|
93 | - ) |
|
94 | - ->willReturn('two/factor/url'); |
|
95 | - |
|
96 | - $result = $this->cmd->process($data); |
|
97 | - |
|
98 | - $this->assertTrue($result->isSuccess()); |
|
99 | - $this->assertEquals('two/factor/url', $result->getRedirectUrl()); |
|
100 | - } |
|
101 | - |
|
102 | - public function testProcessMissingProviders(): void { |
|
103 | - $data = $this->getLoggedInLoginData(); |
|
104 | - $this->twoFactorManager->expects($this->once()) |
|
105 | - ->method('isTwoFactorAuthenticated') |
|
106 | - ->willReturn(true); |
|
107 | - $this->twoFactorManager->expects($this->once()) |
|
108 | - ->method('prepareTwoFactorLogin') |
|
109 | - ->with( |
|
110 | - $this->user, |
|
111 | - $data->isRememberLogin() |
|
112 | - ); |
|
113 | - $provider = $this->createMock(ITwoFactorAuthProvider::class); |
|
114 | - $provider->expects($this->once()) |
|
115 | - ->method('getId') |
|
116 | - ->willReturn('test1'); |
|
117 | - $this->twoFactorManager->expects($this->once()) |
|
118 | - ->method('getProviderSet') |
|
119 | - ->willReturn(new ProviderSet([ |
|
120 | - $provider, |
|
121 | - ], true)); |
|
122 | - $this->twoFactorManager->expects($this->once()) |
|
123 | - ->method('getLoginSetupProviders') |
|
124 | - ->with($this->user) |
|
125 | - ->willReturn([]); |
|
126 | - $this->mandatoryTwoFactor->expects($this->any()) |
|
127 | - ->method('isEnforcedFor') |
|
128 | - ->with($this->user) |
|
129 | - ->willReturn(false); |
|
130 | - $this->urlGenerator->expects($this->once()) |
|
131 | - ->method('linkToRoute') |
|
132 | - ->with( |
|
133 | - 'core.TwoFactorChallenge.selectChallenge' |
|
134 | - ) |
|
135 | - ->willReturn('two/factor/url'); |
|
136 | - |
|
137 | - $result = $this->cmd->process($data); |
|
138 | - |
|
139 | - $this->assertTrue($result->isSuccess()); |
|
140 | - $this->assertEquals('two/factor/url', $result->getRedirectUrl()); |
|
141 | - } |
|
142 | - |
|
143 | - public function testProcessTwoActiveProviders(): void { |
|
144 | - $data = $this->getLoggedInLoginData(); |
|
145 | - $this->twoFactorManager->expects($this->once()) |
|
146 | - ->method('isTwoFactorAuthenticated') |
|
147 | - ->willReturn(true); |
|
148 | - $this->twoFactorManager->expects($this->once()) |
|
149 | - ->method('prepareTwoFactorLogin') |
|
150 | - ->with( |
|
151 | - $this->user, |
|
152 | - $data->isRememberLogin() |
|
153 | - ); |
|
154 | - $provider1 = $this->createMock(ITwoFactorAuthProvider::class); |
|
155 | - $provider2 = $this->createMock(ITwoFactorAuthProvider::class); |
|
156 | - $provider1->expects($this->once()) |
|
157 | - ->method('getId') |
|
158 | - ->willReturn('test1'); |
|
159 | - $provider2->expects($this->once()) |
|
160 | - ->method('getId') |
|
161 | - ->willReturn('test2'); |
|
162 | - $this->twoFactorManager->expects($this->once()) |
|
163 | - ->method('getProviderSet') |
|
164 | - ->willReturn(new ProviderSet([ |
|
165 | - $provider1, |
|
166 | - $provider2, |
|
167 | - ], false)); |
|
168 | - $this->twoFactorManager->expects($this->once()) |
|
169 | - ->method('getLoginSetupProviders') |
|
170 | - ->with($this->user) |
|
171 | - ->willReturn([]); |
|
172 | - $this->mandatoryTwoFactor->expects($this->any()) |
|
173 | - ->method('isEnforcedFor') |
|
174 | - ->with($this->user) |
|
175 | - ->willReturn(false); |
|
176 | - $this->urlGenerator->expects($this->once()) |
|
177 | - ->method('linkToRoute') |
|
178 | - ->with( |
|
179 | - 'core.TwoFactorChallenge.selectChallenge' |
|
180 | - ) |
|
181 | - ->willReturn('two/factor/url'); |
|
182 | - |
|
183 | - $result = $this->cmd->process($data); |
|
184 | - |
|
185 | - $this->assertTrue($result->isSuccess()); |
|
186 | - $this->assertEquals('two/factor/url', $result->getRedirectUrl()); |
|
187 | - } |
|
188 | - |
|
189 | - public function testProcessFailingProviderAndEnforcedButNoSetupProviders(): void { |
|
190 | - $data = $this->getLoggedInLoginData(); |
|
191 | - $this->twoFactorManager->expects($this->once()) |
|
192 | - ->method('isTwoFactorAuthenticated') |
|
193 | - ->willReturn(true); |
|
194 | - $this->twoFactorManager->expects($this->once()) |
|
195 | - ->method('prepareTwoFactorLogin') |
|
196 | - ->with( |
|
197 | - $this->user, |
|
198 | - $data->isRememberLogin() |
|
199 | - ); |
|
200 | - $this->twoFactorManager->expects($this->once()) |
|
201 | - ->method('getProviderSet') |
|
202 | - ->willReturn(new ProviderSet([], true)); |
|
203 | - $this->twoFactorManager->expects($this->once()) |
|
204 | - ->method('getLoginSetupProviders') |
|
205 | - ->with($this->user) |
|
206 | - ->willReturn([]); |
|
207 | - $this->mandatoryTwoFactor->expects($this->any()) |
|
208 | - ->method('isEnforcedFor') |
|
209 | - ->with($this->user) |
|
210 | - ->willReturn(true); |
|
211 | - $this->urlGenerator->expects($this->once()) |
|
212 | - ->method('linkToRoute') |
|
213 | - ->with( |
|
214 | - 'core.TwoFactorChallenge.selectChallenge' |
|
215 | - ) |
|
216 | - ->willReturn('two/factor/url'); |
|
217 | - |
|
218 | - $result = $this->cmd->process($data); |
|
219 | - |
|
220 | - $this->assertTrue($result->isSuccess()); |
|
221 | - $this->assertEquals('two/factor/url', $result->getRedirectUrl()); |
|
222 | - } |
|
223 | - |
|
224 | - public function testProcessFailingProviderAndEnforced(): void { |
|
225 | - $data = $this->getLoggedInLoginData(); |
|
226 | - $this->twoFactorManager->expects($this->once()) |
|
227 | - ->method('isTwoFactorAuthenticated') |
|
228 | - ->willReturn(true); |
|
229 | - $this->twoFactorManager->expects($this->once()) |
|
230 | - ->method('prepareTwoFactorLogin') |
|
231 | - ->with( |
|
232 | - $this->user, |
|
233 | - $data->isRememberLogin() |
|
234 | - ); |
|
235 | - $provider = $this->createMock(IActivatableAtLogin::class); |
|
236 | - $this->twoFactorManager->expects($this->once()) |
|
237 | - ->method('getProviderSet') |
|
238 | - ->willReturn(new ProviderSet([ |
|
239 | - $provider, |
|
240 | - ], true)); |
|
241 | - $this->twoFactorManager->expects($this->once()) |
|
242 | - ->method('getLoginSetupProviders') |
|
243 | - ->with($this->user) |
|
244 | - ->willReturn([]); |
|
245 | - $this->mandatoryTwoFactor->expects($this->any()) |
|
246 | - ->method('isEnforcedFor') |
|
247 | - ->with($this->user) |
|
248 | - ->willReturn(true); |
|
249 | - $this->urlGenerator->expects($this->once()) |
|
250 | - ->method('linkToRoute') |
|
251 | - ->with( |
|
252 | - 'core.TwoFactorChallenge.selectChallenge' |
|
253 | - ) |
|
254 | - ->willReturn('two/factor/url'); |
|
255 | - |
|
256 | - $result = $this->cmd->process($data); |
|
257 | - |
|
258 | - $this->assertTrue($result->isSuccess()); |
|
259 | - $this->assertEquals('two/factor/url', $result->getRedirectUrl()); |
|
260 | - } |
|
261 | - |
|
262 | - public function testProcessNoProvidersButEnforced(): void { |
|
263 | - $data = $this->getLoggedInLoginData(); |
|
264 | - $this->twoFactorManager->expects($this->once()) |
|
265 | - ->method('isTwoFactorAuthenticated') |
|
266 | - ->willReturn(true); |
|
267 | - $this->twoFactorManager->expects($this->once()) |
|
268 | - ->method('prepareTwoFactorLogin') |
|
269 | - ->with( |
|
270 | - $this->user, |
|
271 | - $data->isRememberLogin() |
|
272 | - ); |
|
273 | - $this->twoFactorManager->expects($this->once()) |
|
274 | - ->method('getProviderSet') |
|
275 | - ->willReturn(new ProviderSet([], false)); |
|
276 | - $this->twoFactorManager->expects($this->once()) |
|
277 | - ->method('getLoginSetupProviders') |
|
278 | - ->with($this->user) |
|
279 | - ->willReturn([]); |
|
280 | - $this->mandatoryTwoFactor->expects($this->any()) |
|
281 | - ->method('isEnforcedFor') |
|
282 | - ->with($this->user) |
|
283 | - ->willReturn(true); |
|
284 | - $this->urlGenerator->expects($this->once()) |
|
285 | - ->method('linkToRoute') |
|
286 | - ->with( |
|
287 | - 'core.TwoFactorChallenge.selectChallenge' |
|
288 | - ) |
|
289 | - ->willReturn('two/factor/url'); |
|
290 | - |
|
291 | - $result = $this->cmd->process($data); |
|
292 | - |
|
293 | - $this->assertTrue($result->isSuccess()); |
|
294 | - $this->assertEquals('two/factor/url', $result->getRedirectUrl()); |
|
295 | - } |
|
296 | - |
|
297 | - public function testProcessWithRedirectUrl(): void { |
|
298 | - $data = $this->getLoggedInLoginDataWithRedirectUrl(); |
|
299 | - $this->twoFactorManager->expects($this->once()) |
|
300 | - ->method('isTwoFactorAuthenticated') |
|
301 | - ->willReturn(true); |
|
302 | - $this->twoFactorManager->expects($this->once()) |
|
303 | - ->method('prepareTwoFactorLogin') |
|
304 | - ->with( |
|
305 | - $this->user, |
|
306 | - $data->isRememberLogin() |
|
307 | - ); |
|
308 | - $provider = $this->createMock(ITwoFactorAuthProvider::class); |
|
309 | - $this->twoFactorManager->expects($this->once()) |
|
310 | - ->method('getProviderSet') |
|
311 | - ->willReturn(new ProviderSet([ |
|
312 | - $provider, |
|
313 | - ], false)); |
|
314 | - $this->twoFactorManager->expects($this->once()) |
|
315 | - ->method('getLoginSetupProviders') |
|
316 | - ->with($this->user) |
|
317 | - ->willReturn([]); |
|
318 | - $this->mandatoryTwoFactor->expects($this->any()) |
|
319 | - ->method('isEnforcedFor') |
|
320 | - ->with($this->user) |
|
321 | - ->willReturn(false); |
|
322 | - $provider->expects($this->once()) |
|
323 | - ->method('getId') |
|
324 | - ->willReturn('test'); |
|
325 | - $this->urlGenerator->expects($this->once()) |
|
326 | - ->method('linkToRoute') |
|
327 | - ->with( |
|
328 | - 'core.TwoFactorChallenge.showChallenge', |
|
329 | - [ |
|
330 | - 'challengeProviderId' => 'test', |
|
331 | - 'redirect_url' => $this->redirectUrl, |
|
332 | - ] |
|
333 | - ) |
|
334 | - ->willReturn('two/factor/url'); |
|
335 | - |
|
336 | - $result = $this->cmd->process($data); |
|
337 | - |
|
338 | - $this->assertTrue($result->isSuccess()); |
|
339 | - $this->assertEquals('two/factor/url', $result->getRedirectUrl()); |
|
340 | - } |
|
22 | + /** @var Manager|MockObject */ |
|
23 | + private $twoFactorManager; |
|
24 | + |
|
25 | + /** @var MandatoryTwoFactor|MockObject */ |
|
26 | + private $mandatoryTwoFactor; |
|
27 | + |
|
28 | + /** @var IURLGenerator|MockObject */ |
|
29 | + private $urlGenerator; |
|
30 | + |
|
31 | + protected function setUp(): void { |
|
32 | + parent::setUp(); |
|
33 | + |
|
34 | + $this->twoFactorManager = $this->createMock(Manager::class); |
|
35 | + $this->mandatoryTwoFactor = $this->createMock(MandatoryTwoFactor::class); |
|
36 | + $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
37 | + |
|
38 | + $this->cmd = new TwoFactorCommand( |
|
39 | + $this->twoFactorManager, |
|
40 | + $this->mandatoryTwoFactor, |
|
41 | + $this->urlGenerator |
|
42 | + ); |
|
43 | + } |
|
44 | + |
|
45 | + public function testNotTwoFactorAuthenticated(): void { |
|
46 | + $data = $this->getLoggedInLoginData(); |
|
47 | + $this->twoFactorManager->expects($this->once()) |
|
48 | + ->method('isTwoFactorAuthenticated') |
|
49 | + ->willReturn(false); |
|
50 | + $this->twoFactorManager->expects($this->never()) |
|
51 | + ->method('prepareTwoFactorLogin'); |
|
52 | + |
|
53 | + $result = $this->cmd->process($data); |
|
54 | + |
|
55 | + $this->assertTrue($result->isSuccess()); |
|
56 | + } |
|
57 | + |
|
58 | + public function testProcessOneActiveProvider(): void { |
|
59 | + $data = $this->getLoggedInLoginData(); |
|
60 | + $this->twoFactorManager->expects($this->once()) |
|
61 | + ->method('isTwoFactorAuthenticated') |
|
62 | + ->willReturn(true); |
|
63 | + $this->twoFactorManager->expects($this->once()) |
|
64 | + ->method('prepareTwoFactorLogin') |
|
65 | + ->with( |
|
66 | + $this->user, |
|
67 | + $data->isRememberLogin() |
|
68 | + ); |
|
69 | + $provider = $this->createMock(ITwoFactorAuthProvider::class); |
|
70 | + $this->twoFactorManager->expects($this->once()) |
|
71 | + ->method('getProviderSet') |
|
72 | + ->willReturn(new ProviderSet([ |
|
73 | + $provider, |
|
74 | + ], false)); |
|
75 | + $this->twoFactorManager->expects($this->once()) |
|
76 | + ->method('getLoginSetupProviders') |
|
77 | + ->with($this->user) |
|
78 | + ->willReturn([]); |
|
79 | + $this->mandatoryTwoFactor->expects($this->any()) |
|
80 | + ->method('isEnforcedFor') |
|
81 | + ->with($this->user) |
|
82 | + ->willReturn(false); |
|
83 | + $provider->expects($this->once()) |
|
84 | + ->method('getId') |
|
85 | + ->willReturn('test'); |
|
86 | + $this->urlGenerator->expects($this->once()) |
|
87 | + ->method('linkToRoute') |
|
88 | + ->with( |
|
89 | + 'core.TwoFactorChallenge.showChallenge', |
|
90 | + [ |
|
91 | + 'challengeProviderId' => 'test' |
|
92 | + ] |
|
93 | + ) |
|
94 | + ->willReturn('two/factor/url'); |
|
95 | + |
|
96 | + $result = $this->cmd->process($data); |
|
97 | + |
|
98 | + $this->assertTrue($result->isSuccess()); |
|
99 | + $this->assertEquals('two/factor/url', $result->getRedirectUrl()); |
|
100 | + } |
|
101 | + |
|
102 | + public function testProcessMissingProviders(): void { |
|
103 | + $data = $this->getLoggedInLoginData(); |
|
104 | + $this->twoFactorManager->expects($this->once()) |
|
105 | + ->method('isTwoFactorAuthenticated') |
|
106 | + ->willReturn(true); |
|
107 | + $this->twoFactorManager->expects($this->once()) |
|
108 | + ->method('prepareTwoFactorLogin') |
|
109 | + ->with( |
|
110 | + $this->user, |
|
111 | + $data->isRememberLogin() |
|
112 | + ); |
|
113 | + $provider = $this->createMock(ITwoFactorAuthProvider::class); |
|
114 | + $provider->expects($this->once()) |
|
115 | + ->method('getId') |
|
116 | + ->willReturn('test1'); |
|
117 | + $this->twoFactorManager->expects($this->once()) |
|
118 | + ->method('getProviderSet') |
|
119 | + ->willReturn(new ProviderSet([ |
|
120 | + $provider, |
|
121 | + ], true)); |
|
122 | + $this->twoFactorManager->expects($this->once()) |
|
123 | + ->method('getLoginSetupProviders') |
|
124 | + ->with($this->user) |
|
125 | + ->willReturn([]); |
|
126 | + $this->mandatoryTwoFactor->expects($this->any()) |
|
127 | + ->method('isEnforcedFor') |
|
128 | + ->with($this->user) |
|
129 | + ->willReturn(false); |
|
130 | + $this->urlGenerator->expects($this->once()) |
|
131 | + ->method('linkToRoute') |
|
132 | + ->with( |
|
133 | + 'core.TwoFactorChallenge.selectChallenge' |
|
134 | + ) |
|
135 | + ->willReturn('two/factor/url'); |
|
136 | + |
|
137 | + $result = $this->cmd->process($data); |
|
138 | + |
|
139 | + $this->assertTrue($result->isSuccess()); |
|
140 | + $this->assertEquals('two/factor/url', $result->getRedirectUrl()); |
|
141 | + } |
|
142 | + |
|
143 | + public function testProcessTwoActiveProviders(): void { |
|
144 | + $data = $this->getLoggedInLoginData(); |
|
145 | + $this->twoFactorManager->expects($this->once()) |
|
146 | + ->method('isTwoFactorAuthenticated') |
|
147 | + ->willReturn(true); |
|
148 | + $this->twoFactorManager->expects($this->once()) |
|
149 | + ->method('prepareTwoFactorLogin') |
|
150 | + ->with( |
|
151 | + $this->user, |
|
152 | + $data->isRememberLogin() |
|
153 | + ); |
|
154 | + $provider1 = $this->createMock(ITwoFactorAuthProvider::class); |
|
155 | + $provider2 = $this->createMock(ITwoFactorAuthProvider::class); |
|
156 | + $provider1->expects($this->once()) |
|
157 | + ->method('getId') |
|
158 | + ->willReturn('test1'); |
|
159 | + $provider2->expects($this->once()) |
|
160 | + ->method('getId') |
|
161 | + ->willReturn('test2'); |
|
162 | + $this->twoFactorManager->expects($this->once()) |
|
163 | + ->method('getProviderSet') |
|
164 | + ->willReturn(new ProviderSet([ |
|
165 | + $provider1, |
|
166 | + $provider2, |
|
167 | + ], false)); |
|
168 | + $this->twoFactorManager->expects($this->once()) |
|
169 | + ->method('getLoginSetupProviders') |
|
170 | + ->with($this->user) |
|
171 | + ->willReturn([]); |
|
172 | + $this->mandatoryTwoFactor->expects($this->any()) |
|
173 | + ->method('isEnforcedFor') |
|
174 | + ->with($this->user) |
|
175 | + ->willReturn(false); |
|
176 | + $this->urlGenerator->expects($this->once()) |
|
177 | + ->method('linkToRoute') |
|
178 | + ->with( |
|
179 | + 'core.TwoFactorChallenge.selectChallenge' |
|
180 | + ) |
|
181 | + ->willReturn('two/factor/url'); |
|
182 | + |
|
183 | + $result = $this->cmd->process($data); |
|
184 | + |
|
185 | + $this->assertTrue($result->isSuccess()); |
|
186 | + $this->assertEquals('two/factor/url', $result->getRedirectUrl()); |
|
187 | + } |
|
188 | + |
|
189 | + public function testProcessFailingProviderAndEnforcedButNoSetupProviders(): void { |
|
190 | + $data = $this->getLoggedInLoginData(); |
|
191 | + $this->twoFactorManager->expects($this->once()) |
|
192 | + ->method('isTwoFactorAuthenticated') |
|
193 | + ->willReturn(true); |
|
194 | + $this->twoFactorManager->expects($this->once()) |
|
195 | + ->method('prepareTwoFactorLogin') |
|
196 | + ->with( |
|
197 | + $this->user, |
|
198 | + $data->isRememberLogin() |
|
199 | + ); |
|
200 | + $this->twoFactorManager->expects($this->once()) |
|
201 | + ->method('getProviderSet') |
|
202 | + ->willReturn(new ProviderSet([], true)); |
|
203 | + $this->twoFactorManager->expects($this->once()) |
|
204 | + ->method('getLoginSetupProviders') |
|
205 | + ->with($this->user) |
|
206 | + ->willReturn([]); |
|
207 | + $this->mandatoryTwoFactor->expects($this->any()) |
|
208 | + ->method('isEnforcedFor') |
|
209 | + ->with($this->user) |
|
210 | + ->willReturn(true); |
|
211 | + $this->urlGenerator->expects($this->once()) |
|
212 | + ->method('linkToRoute') |
|
213 | + ->with( |
|
214 | + 'core.TwoFactorChallenge.selectChallenge' |
|
215 | + ) |
|
216 | + ->willReturn('two/factor/url'); |
|
217 | + |
|
218 | + $result = $this->cmd->process($data); |
|
219 | + |
|
220 | + $this->assertTrue($result->isSuccess()); |
|
221 | + $this->assertEquals('two/factor/url', $result->getRedirectUrl()); |
|
222 | + } |
|
223 | + |
|
224 | + public function testProcessFailingProviderAndEnforced(): void { |
|
225 | + $data = $this->getLoggedInLoginData(); |
|
226 | + $this->twoFactorManager->expects($this->once()) |
|
227 | + ->method('isTwoFactorAuthenticated') |
|
228 | + ->willReturn(true); |
|
229 | + $this->twoFactorManager->expects($this->once()) |
|
230 | + ->method('prepareTwoFactorLogin') |
|
231 | + ->with( |
|
232 | + $this->user, |
|
233 | + $data->isRememberLogin() |
|
234 | + ); |
|
235 | + $provider = $this->createMock(IActivatableAtLogin::class); |
|
236 | + $this->twoFactorManager->expects($this->once()) |
|
237 | + ->method('getProviderSet') |
|
238 | + ->willReturn(new ProviderSet([ |
|
239 | + $provider, |
|
240 | + ], true)); |
|
241 | + $this->twoFactorManager->expects($this->once()) |
|
242 | + ->method('getLoginSetupProviders') |
|
243 | + ->with($this->user) |
|
244 | + ->willReturn([]); |
|
245 | + $this->mandatoryTwoFactor->expects($this->any()) |
|
246 | + ->method('isEnforcedFor') |
|
247 | + ->with($this->user) |
|
248 | + ->willReturn(true); |
|
249 | + $this->urlGenerator->expects($this->once()) |
|
250 | + ->method('linkToRoute') |
|
251 | + ->with( |
|
252 | + 'core.TwoFactorChallenge.selectChallenge' |
|
253 | + ) |
|
254 | + ->willReturn('two/factor/url'); |
|
255 | + |
|
256 | + $result = $this->cmd->process($data); |
|
257 | + |
|
258 | + $this->assertTrue($result->isSuccess()); |
|
259 | + $this->assertEquals('two/factor/url', $result->getRedirectUrl()); |
|
260 | + } |
|
261 | + |
|
262 | + public function testProcessNoProvidersButEnforced(): void { |
|
263 | + $data = $this->getLoggedInLoginData(); |
|
264 | + $this->twoFactorManager->expects($this->once()) |
|
265 | + ->method('isTwoFactorAuthenticated') |
|
266 | + ->willReturn(true); |
|
267 | + $this->twoFactorManager->expects($this->once()) |
|
268 | + ->method('prepareTwoFactorLogin') |
|
269 | + ->with( |
|
270 | + $this->user, |
|
271 | + $data->isRememberLogin() |
|
272 | + ); |
|
273 | + $this->twoFactorManager->expects($this->once()) |
|
274 | + ->method('getProviderSet') |
|
275 | + ->willReturn(new ProviderSet([], false)); |
|
276 | + $this->twoFactorManager->expects($this->once()) |
|
277 | + ->method('getLoginSetupProviders') |
|
278 | + ->with($this->user) |
|
279 | + ->willReturn([]); |
|
280 | + $this->mandatoryTwoFactor->expects($this->any()) |
|
281 | + ->method('isEnforcedFor') |
|
282 | + ->with($this->user) |
|
283 | + ->willReturn(true); |
|
284 | + $this->urlGenerator->expects($this->once()) |
|
285 | + ->method('linkToRoute') |
|
286 | + ->with( |
|
287 | + 'core.TwoFactorChallenge.selectChallenge' |
|
288 | + ) |
|
289 | + ->willReturn('two/factor/url'); |
|
290 | + |
|
291 | + $result = $this->cmd->process($data); |
|
292 | + |
|
293 | + $this->assertTrue($result->isSuccess()); |
|
294 | + $this->assertEquals('two/factor/url', $result->getRedirectUrl()); |
|
295 | + } |
|
296 | + |
|
297 | + public function testProcessWithRedirectUrl(): void { |
|
298 | + $data = $this->getLoggedInLoginDataWithRedirectUrl(); |
|
299 | + $this->twoFactorManager->expects($this->once()) |
|
300 | + ->method('isTwoFactorAuthenticated') |
|
301 | + ->willReturn(true); |
|
302 | + $this->twoFactorManager->expects($this->once()) |
|
303 | + ->method('prepareTwoFactorLogin') |
|
304 | + ->with( |
|
305 | + $this->user, |
|
306 | + $data->isRememberLogin() |
|
307 | + ); |
|
308 | + $provider = $this->createMock(ITwoFactorAuthProvider::class); |
|
309 | + $this->twoFactorManager->expects($this->once()) |
|
310 | + ->method('getProviderSet') |
|
311 | + ->willReturn(new ProviderSet([ |
|
312 | + $provider, |
|
313 | + ], false)); |
|
314 | + $this->twoFactorManager->expects($this->once()) |
|
315 | + ->method('getLoginSetupProviders') |
|
316 | + ->with($this->user) |
|
317 | + ->willReturn([]); |
|
318 | + $this->mandatoryTwoFactor->expects($this->any()) |
|
319 | + ->method('isEnforcedFor') |
|
320 | + ->with($this->user) |
|
321 | + ->willReturn(false); |
|
322 | + $provider->expects($this->once()) |
|
323 | + ->method('getId') |
|
324 | + ->willReturn('test'); |
|
325 | + $this->urlGenerator->expects($this->once()) |
|
326 | + ->method('linkToRoute') |
|
327 | + ->with( |
|
328 | + 'core.TwoFactorChallenge.showChallenge', |
|
329 | + [ |
|
330 | + 'challengeProviderId' => 'test', |
|
331 | + 'redirect_url' => $this->redirectUrl, |
|
332 | + ] |
|
333 | + ) |
|
334 | + ->willReturn('two/factor/url'); |
|
335 | + |
|
336 | + $result = $this->cmd->process($data); |
|
337 | + |
|
338 | + $this->assertTrue($result->isSuccess()); |
|
339 | + $this->assertEquals('two/factor/url', $result->getRedirectUrl()); |
|
340 | + } |
|
341 | 341 | } |
@@ -16,64 +16,64 @@ |
||
16 | 16 | use Psr\Log\LoggerInterface; |
17 | 17 | |
18 | 18 | class UserDisabledCheckCommandTest extends ALoginTestCommand { |
19 | - /** @var IUserManager|MockObject */ |
|
20 | - private $userManager; |
|
21 | - |
|
22 | - /** @var LoggerInterface|MockObject */ |
|
23 | - private $logger; |
|
24 | - |
|
25 | - protected function setUp(): void { |
|
26 | - parent::setUp(); |
|
27 | - |
|
28 | - $this->userManager = $this->createMock(IUserManager::class); |
|
29 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
30 | - |
|
31 | - $this->cmd = new UserDisabledCheckCommand( |
|
32 | - $this->userManager, |
|
33 | - $this->logger |
|
34 | - ); |
|
35 | - } |
|
36 | - |
|
37 | - public function testProcessNonExistingUser(): void { |
|
38 | - $data = $this->getBasicLoginData(); |
|
39 | - $this->userManager->expects($this->once()) |
|
40 | - ->method('get') |
|
41 | - ->with($this->username) |
|
42 | - ->willReturn(null); |
|
43 | - |
|
44 | - $result = $this->cmd->process($data); |
|
45 | - |
|
46 | - $this->assertTrue($result->isSuccess()); |
|
47 | - } |
|
48 | - |
|
49 | - public function testProcessDisabledUser(): void { |
|
50 | - $data = $this->getBasicLoginData(); |
|
51 | - $this->userManager->expects($this->once()) |
|
52 | - ->method('get') |
|
53 | - ->with($this->username) |
|
54 | - ->willReturn($this->user); |
|
55 | - $this->user->expects($this->once()) |
|
56 | - ->method('isEnabled') |
|
57 | - ->willReturn(false); |
|
58 | - |
|
59 | - $result = $this->cmd->process($data); |
|
60 | - |
|
61 | - $this->assertFalse($result->isSuccess()); |
|
62 | - $this->assertSame(LoginController::LOGIN_MSG_USERDISABLED, $result->getErrorMessage()); |
|
63 | - } |
|
64 | - |
|
65 | - public function testProcess(): void { |
|
66 | - $data = $this->getBasicLoginData(); |
|
67 | - $this->userManager->expects($this->once()) |
|
68 | - ->method('get') |
|
69 | - ->with($this->username) |
|
70 | - ->willReturn($this->user); |
|
71 | - $this->user->expects($this->once()) |
|
72 | - ->method('isEnabled') |
|
73 | - ->willReturn(true); |
|
74 | - |
|
75 | - $result = $this->cmd->process($data); |
|
76 | - |
|
77 | - $this->assertTrue($result->isSuccess()); |
|
78 | - } |
|
19 | + /** @var IUserManager|MockObject */ |
|
20 | + private $userManager; |
|
21 | + |
|
22 | + /** @var LoggerInterface|MockObject */ |
|
23 | + private $logger; |
|
24 | + |
|
25 | + protected function setUp(): void { |
|
26 | + parent::setUp(); |
|
27 | + |
|
28 | + $this->userManager = $this->createMock(IUserManager::class); |
|
29 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
30 | + |
|
31 | + $this->cmd = new UserDisabledCheckCommand( |
|
32 | + $this->userManager, |
|
33 | + $this->logger |
|
34 | + ); |
|
35 | + } |
|
36 | + |
|
37 | + public function testProcessNonExistingUser(): void { |
|
38 | + $data = $this->getBasicLoginData(); |
|
39 | + $this->userManager->expects($this->once()) |
|
40 | + ->method('get') |
|
41 | + ->with($this->username) |
|
42 | + ->willReturn(null); |
|
43 | + |
|
44 | + $result = $this->cmd->process($data); |
|
45 | + |
|
46 | + $this->assertTrue($result->isSuccess()); |
|
47 | + } |
|
48 | + |
|
49 | + public function testProcessDisabledUser(): void { |
|
50 | + $data = $this->getBasicLoginData(); |
|
51 | + $this->userManager->expects($this->once()) |
|
52 | + ->method('get') |
|
53 | + ->with($this->username) |
|
54 | + ->willReturn($this->user); |
|
55 | + $this->user->expects($this->once()) |
|
56 | + ->method('isEnabled') |
|
57 | + ->willReturn(false); |
|
58 | + |
|
59 | + $result = $this->cmd->process($data); |
|
60 | + |
|
61 | + $this->assertFalse($result->isSuccess()); |
|
62 | + $this->assertSame(LoginController::LOGIN_MSG_USERDISABLED, $result->getErrorMessage()); |
|
63 | + } |
|
64 | + |
|
65 | + public function testProcess(): void { |
|
66 | + $data = $this->getBasicLoginData(); |
|
67 | + $this->userManager->expects($this->once()) |
|
68 | + ->method('get') |
|
69 | + ->with($this->username) |
|
70 | + ->willReturn($this->user); |
|
71 | + $this->user->expects($this->once()) |
|
72 | + ->method('isEnabled') |
|
73 | + ->willReturn(true); |
|
74 | + |
|
75 | + $result = $this->cmd->process($data); |
|
76 | + |
|
77 | + $this->assertTrue($result->isSuccess()); |
|
78 | + } |
|
79 | 79 | } |
@@ -15,34 +15,34 @@ |
||
15 | 15 | use PHPUnit\Framework\MockObject\MockObject; |
16 | 16 | |
17 | 17 | class PreLoginHookCommandTest extends ALoginTestCommand { |
18 | - /** @var IUserManager|MockObject */ |
|
19 | - private $userManager; |
|
20 | - |
|
21 | - protected function setUp(): void { |
|
22 | - parent::setUp(); |
|
23 | - |
|
24 | - $this->userManager = $this->createMock(Manager::class); |
|
25 | - |
|
26 | - $this->cmd = new PreLoginHookCommand( |
|
27 | - $this->userManager |
|
28 | - ); |
|
29 | - } |
|
30 | - |
|
31 | - public function testProcess(): void { |
|
32 | - $data = $this->getBasicLoginData(); |
|
33 | - $this->userManager->expects($this->once()) |
|
34 | - ->method('emit') |
|
35 | - ->with( |
|
36 | - '\OC\User', |
|
37 | - 'preLogin', |
|
38 | - [ |
|
39 | - $this->username, |
|
40 | - $this->password, |
|
41 | - ] |
|
42 | - ); |
|
43 | - |
|
44 | - $result = $this->cmd->process($data); |
|
45 | - |
|
46 | - $this->assertTrue($result->isSuccess()); |
|
47 | - } |
|
18 | + /** @var IUserManager|MockObject */ |
|
19 | + private $userManager; |
|
20 | + |
|
21 | + protected function setUp(): void { |
|
22 | + parent::setUp(); |
|
23 | + |
|
24 | + $this->userManager = $this->createMock(Manager::class); |
|
25 | + |
|
26 | + $this->cmd = new PreLoginHookCommand( |
|
27 | + $this->userManager |
|
28 | + ); |
|
29 | + } |
|
30 | + |
|
31 | + public function testProcess(): void { |
|
32 | + $data = $this->getBasicLoginData(); |
|
33 | + $this->userManager->expects($this->once()) |
|
34 | + ->method('emit') |
|
35 | + ->with( |
|
36 | + '\OC\User', |
|
37 | + 'preLogin', |
|
38 | + [ |
|
39 | + $this->username, |
|
40 | + $this->password, |
|
41 | + ] |
|
42 | + ); |
|
43 | + |
|
44 | + $result = $this->cmd->process($data); |
|
45 | + |
|
46 | + $this->assertTrue($result->isSuccess()); |
|
47 | + } |
|
48 | 48 | } |
@@ -15,60 +15,60 @@ |
||
15 | 15 | use PHPUnit\Framework\MockObject\MockObject; |
16 | 16 | |
17 | 17 | class FinishRememberedLoginCommandTest extends ALoginTestCommand { |
18 | - /** @var Session|MockObject */ |
|
19 | - private $userSession; |
|
20 | - /** @var IConfig|MockObject */ |
|
21 | - private $config; |
|
22 | - |
|
23 | - protected function setUp(): void { |
|
24 | - parent::setUp(); |
|
25 | - |
|
26 | - $this->userSession = $this->createMock(Session::class); |
|
27 | - $this->config = $this->createMock(IConfig::class); |
|
28 | - |
|
29 | - $this->cmd = new FinishRememberedLoginCommand( |
|
30 | - $this->userSession, |
|
31 | - $this->config |
|
32 | - ); |
|
33 | - } |
|
34 | - |
|
35 | - public function testProcessNotRememberedLogin(): void { |
|
36 | - $data = $this->getLoggedInLoginData(); |
|
37 | - $data->setRememberLogin(false); |
|
38 | - $this->userSession->expects($this->never()) |
|
39 | - ->method('createRememberMeToken'); |
|
40 | - |
|
41 | - $result = $this->cmd->process($data); |
|
42 | - |
|
43 | - $this->assertTrue($result->isSuccess()); |
|
44 | - } |
|
45 | - |
|
46 | - public function testProcess(): void { |
|
47 | - $data = $this->getLoggedInLoginData(); |
|
48 | - $this->config->expects($this->once()) |
|
49 | - ->method('getSystemValueBool') |
|
50 | - ->with('auto_logout', false) |
|
51 | - ->willReturn(false); |
|
52 | - $this->userSession->expects($this->once()) |
|
53 | - ->method('createRememberMeToken') |
|
54 | - ->with($this->user); |
|
55 | - |
|
56 | - $result = $this->cmd->process($data); |
|
57 | - |
|
58 | - $this->assertTrue($result->isSuccess()); |
|
59 | - } |
|
60 | - |
|
61 | - public function testProcessNotRemeberedLoginWithAutologout(): void { |
|
62 | - $data = $this->getLoggedInLoginData(); |
|
63 | - $this->config->expects($this->once()) |
|
64 | - ->method('getSystemValueBool') |
|
65 | - ->with('auto_logout', false) |
|
66 | - ->willReturn(true); |
|
67 | - $this->userSession->expects($this->never()) |
|
68 | - ->method('createRememberMeToken'); |
|
69 | - |
|
70 | - $result = $this->cmd->process($data); |
|
71 | - |
|
72 | - $this->assertTrue($result->isSuccess()); |
|
73 | - } |
|
18 | + /** @var Session|MockObject */ |
|
19 | + private $userSession; |
|
20 | + /** @var IConfig|MockObject */ |
|
21 | + private $config; |
|
22 | + |
|
23 | + protected function setUp(): void { |
|
24 | + parent::setUp(); |
|
25 | + |
|
26 | + $this->userSession = $this->createMock(Session::class); |
|
27 | + $this->config = $this->createMock(IConfig::class); |
|
28 | + |
|
29 | + $this->cmd = new FinishRememberedLoginCommand( |
|
30 | + $this->userSession, |
|
31 | + $this->config |
|
32 | + ); |
|
33 | + } |
|
34 | + |
|
35 | + public function testProcessNotRememberedLogin(): void { |
|
36 | + $data = $this->getLoggedInLoginData(); |
|
37 | + $data->setRememberLogin(false); |
|
38 | + $this->userSession->expects($this->never()) |
|
39 | + ->method('createRememberMeToken'); |
|
40 | + |
|
41 | + $result = $this->cmd->process($data); |
|
42 | + |
|
43 | + $this->assertTrue($result->isSuccess()); |
|
44 | + } |
|
45 | + |
|
46 | + public function testProcess(): void { |
|
47 | + $data = $this->getLoggedInLoginData(); |
|
48 | + $this->config->expects($this->once()) |
|
49 | + ->method('getSystemValueBool') |
|
50 | + ->with('auto_logout', false) |
|
51 | + ->willReturn(false); |
|
52 | + $this->userSession->expects($this->once()) |
|
53 | + ->method('createRememberMeToken') |
|
54 | + ->with($this->user); |
|
55 | + |
|
56 | + $result = $this->cmd->process($data); |
|
57 | + |
|
58 | + $this->assertTrue($result->isSuccess()); |
|
59 | + } |
|
60 | + |
|
61 | + public function testProcessNotRemeberedLoginWithAutologout(): void { |
|
62 | + $data = $this->getLoggedInLoginData(); |
|
63 | + $this->config->expects($this->once()) |
|
64 | + ->method('getSystemValueBool') |
|
65 | + ->with('auto_logout', false) |
|
66 | + ->willReturn(true); |
|
67 | + $this->userSession->expects($this->never()) |
|
68 | + ->method('createRememberMeToken'); |
|
69 | + |
|
70 | + $result = $this->cmd->process($data); |
|
71 | + |
|
72 | + $this->assertTrue($result->isSuccess()); |
|
73 | + } |
|
74 | 74 | } |
@@ -14,48 +14,48 @@ |
||
14 | 14 | use PHPUnit\Framework\MockObject\MockObject; |
15 | 15 | |
16 | 16 | class UidLoginCommandTest extends ALoginTestCommand { |
17 | - /** @var Manager|MockObject */ |
|
18 | - private $userManager; |
|
19 | - |
|
20 | - protected function setUp(): void { |
|
21 | - parent::setUp(); |
|
22 | - |
|
23 | - $this->userManager = $this->createMock(Manager::class); |
|
24 | - |
|
25 | - $this->cmd = new UidLoginCommand( |
|
26 | - $this->userManager |
|
27 | - ); |
|
28 | - } |
|
29 | - |
|
30 | - public function testProcessFailingLogin(): void { |
|
31 | - $data = $this->getBasicLoginData(); |
|
32 | - $this->userManager->expects($this->once()) |
|
33 | - ->method('checkPasswordNoLogging') |
|
34 | - ->with( |
|
35 | - $this->username, |
|
36 | - $this->password |
|
37 | - ) |
|
38 | - ->willReturn(false); |
|
39 | - |
|
40 | - $result = $this->cmd->process($data); |
|
41 | - |
|
42 | - $this->assertTrue($result->isSuccess()); |
|
43 | - $this->assertFalse($data->getUser()); |
|
44 | - } |
|
45 | - |
|
46 | - public function testProcess(): void { |
|
47 | - $data = $this->getBasicLoginData(); |
|
48 | - $this->userManager->expects($this->once()) |
|
49 | - ->method('checkPasswordNoLogging') |
|
50 | - ->with( |
|
51 | - $this->username, |
|
52 | - $this->password |
|
53 | - ) |
|
54 | - ->willReturn($this->user); |
|
55 | - |
|
56 | - $result = $this->cmd->process($data); |
|
57 | - |
|
58 | - $this->assertTrue($result->isSuccess()); |
|
59 | - $this->assertEquals($this->user, $data->getUser()); |
|
60 | - } |
|
17 | + /** @var Manager|MockObject */ |
|
18 | + private $userManager; |
|
19 | + |
|
20 | + protected function setUp(): void { |
|
21 | + parent::setUp(); |
|
22 | + |
|
23 | + $this->userManager = $this->createMock(Manager::class); |
|
24 | + |
|
25 | + $this->cmd = new UidLoginCommand( |
|
26 | + $this->userManager |
|
27 | + ); |
|
28 | + } |
|
29 | + |
|
30 | + public function testProcessFailingLogin(): void { |
|
31 | + $data = $this->getBasicLoginData(); |
|
32 | + $this->userManager->expects($this->once()) |
|
33 | + ->method('checkPasswordNoLogging') |
|
34 | + ->with( |
|
35 | + $this->username, |
|
36 | + $this->password |
|
37 | + ) |
|
38 | + ->willReturn(false); |
|
39 | + |
|
40 | + $result = $this->cmd->process($data); |
|
41 | + |
|
42 | + $this->assertTrue($result->isSuccess()); |
|
43 | + $this->assertFalse($data->getUser()); |
|
44 | + } |
|
45 | + |
|
46 | + public function testProcess(): void { |
|
47 | + $data = $this->getBasicLoginData(); |
|
48 | + $this->userManager->expects($this->once()) |
|
49 | + ->method('checkPasswordNoLogging') |
|
50 | + ->with( |
|
51 | + $this->username, |
|
52 | + $this->password |
|
53 | + ) |
|
54 | + ->willReturn($this->user); |
|
55 | + |
|
56 | + $result = $this->cmd->process($data); |
|
57 | + |
|
58 | + $this->assertTrue($result->isSuccess()); |
|
59 | + $this->assertEquals($this->user, $data->getUser()); |
|
60 | + } |
|
61 | 61 | } |
@@ -14,34 +14,34 @@ |
||
14 | 14 | use PHPUnit\Framework\MockObject\MockObject; |
15 | 15 | |
16 | 16 | class ClearLostPasswordTokensCommandTest extends ALoginTestCommand { |
17 | - /** @var IConfig|MockObject */ |
|
18 | - private $config; |
|
19 | - |
|
20 | - protected function setUp(): void { |
|
21 | - parent::setUp(); |
|
22 | - |
|
23 | - $this->config = $this->createMock(IConfig::class); |
|
24 | - |
|
25 | - $this->cmd = new ClearLostPasswordTokensCommand( |
|
26 | - $this->config |
|
27 | - ); |
|
28 | - } |
|
29 | - |
|
30 | - public function testProcess(): void { |
|
31 | - $data = $this->getLoggedInLoginData(); |
|
32 | - $this->user->expects($this->once()) |
|
33 | - ->method('getUID') |
|
34 | - ->willReturn($this->username); |
|
35 | - $this->config->expects($this->once()) |
|
36 | - ->method('deleteUserValue') |
|
37 | - ->with( |
|
38 | - $this->username, |
|
39 | - 'core', |
|
40 | - 'lostpassword' |
|
41 | - ); |
|
42 | - |
|
43 | - $result = $this->cmd->process($data); |
|
44 | - |
|
45 | - $this->assertTrue($result->isSuccess()); |
|
46 | - } |
|
17 | + /** @var IConfig|MockObject */ |
|
18 | + private $config; |
|
19 | + |
|
20 | + protected function setUp(): void { |
|
21 | + parent::setUp(); |
|
22 | + |
|
23 | + $this->config = $this->createMock(IConfig::class); |
|
24 | + |
|
25 | + $this->cmd = new ClearLostPasswordTokensCommand( |
|
26 | + $this->config |
|
27 | + ); |
|
28 | + } |
|
29 | + |
|
30 | + public function testProcess(): void { |
|
31 | + $data = $this->getLoggedInLoginData(); |
|
32 | + $this->user->expects($this->once()) |
|
33 | + ->method('getUID') |
|
34 | + ->willReturn($this->username); |
|
35 | + $this->config->expects($this->once()) |
|
36 | + ->method('deleteUserValue') |
|
37 | + ->with( |
|
38 | + $this->username, |
|
39 | + 'core', |
|
40 | + 'lostpassword' |
|
41 | + ); |
|
42 | + |
|
43 | + $result = $this->cmd->process($data); |
|
44 | + |
|
45 | + $this->assertTrue($result->isSuccess()); |
|
46 | + } |
|
47 | 47 | } |
@@ -15,89 +15,89 @@ |
||
15 | 15 | use Test\TestCase; |
16 | 16 | |
17 | 17 | abstract class ALoginTestCommand extends TestCase { |
18 | - /** @var IRequest|MockObject */ |
|
19 | - protected $request; |
|
20 | - |
|
21 | - /** @var string */ |
|
22 | - protected $username = 'user123'; |
|
23 | - |
|
24 | - /** @var string */ |
|
25 | - protected $password = '123456'; |
|
26 | - |
|
27 | - /** @var string */ |
|
28 | - protected $redirectUrl = '/apps/contacts'; |
|
29 | - |
|
30 | - /** @var string */ |
|
31 | - protected $timezone = 'Europe/Vienna'; |
|
32 | - |
|
33 | - protected $timeZoneOffset = '2'; |
|
34 | - |
|
35 | - /** @var IUser|MockObject */ |
|
36 | - protected $user; |
|
37 | - |
|
38 | - /** @var ALoginTestCommand */ |
|
39 | - protected $cmd; |
|
40 | - |
|
41 | - protected function setUp(): void { |
|
42 | - parent::setUp(); |
|
43 | - |
|
44 | - $this->request = $this->createMock(IRequest::class); |
|
45 | - $this->user = $this->createMock(IUser::class); |
|
46 | - } |
|
47 | - |
|
48 | - protected function getBasicLoginData(): LoginData { |
|
49 | - return new LoginData( |
|
50 | - $this->request, |
|
51 | - $this->username, |
|
52 | - $this->password |
|
53 | - ); |
|
54 | - } |
|
55 | - |
|
56 | - protected function getInvalidLoginData(): LoginData { |
|
57 | - return new LoginData( |
|
58 | - $this->request, |
|
59 | - $this->username, |
|
60 | - $this->password |
|
61 | - ); |
|
62 | - } |
|
63 | - |
|
64 | - protected function getFailedLoginData(): LoginData { |
|
65 | - $data = new LoginData( |
|
66 | - $this->request, |
|
67 | - $this->username, |
|
68 | - $this->password |
|
69 | - ); |
|
70 | - $data->setUser(false); |
|
71 | - return $data; |
|
72 | - } |
|
73 | - |
|
74 | - protected function getLoggedInLoginData(): LoginData { |
|
75 | - $basic = $this->getBasicLoginData(); |
|
76 | - $basic->setUser($this->user); |
|
77 | - return $basic; |
|
78 | - } |
|
79 | - |
|
80 | - protected function getLoggedInLoginDataWithRedirectUrl(): LoginData { |
|
81 | - $data = new LoginData( |
|
82 | - $this->request, |
|
83 | - $this->username, |
|
84 | - $this->password, |
|
85 | - $this->redirectUrl |
|
86 | - ); |
|
87 | - $data->setUser($this->user); |
|
88 | - return $data; |
|
89 | - } |
|
90 | - |
|
91 | - protected function getLoggedInLoginDataWithTimezone(): LoginData { |
|
92 | - $data = new LoginData( |
|
93 | - $this->request, |
|
94 | - $this->username, |
|
95 | - $this->password, |
|
96 | - null, |
|
97 | - $this->timezone, |
|
98 | - $this->timeZoneOffset |
|
99 | - ); |
|
100 | - $data->setUser($this->user); |
|
101 | - return $data; |
|
102 | - } |
|
18 | + /** @var IRequest|MockObject */ |
|
19 | + protected $request; |
|
20 | + |
|
21 | + /** @var string */ |
|
22 | + protected $username = 'user123'; |
|
23 | + |
|
24 | + /** @var string */ |
|
25 | + protected $password = '123456'; |
|
26 | + |
|
27 | + /** @var string */ |
|
28 | + protected $redirectUrl = '/apps/contacts'; |
|
29 | + |
|
30 | + /** @var string */ |
|
31 | + protected $timezone = 'Europe/Vienna'; |
|
32 | + |
|
33 | + protected $timeZoneOffset = '2'; |
|
34 | + |
|
35 | + /** @var IUser|MockObject */ |
|
36 | + protected $user; |
|
37 | + |
|
38 | + /** @var ALoginTestCommand */ |
|
39 | + protected $cmd; |
|
40 | + |
|
41 | + protected function setUp(): void { |
|
42 | + parent::setUp(); |
|
43 | + |
|
44 | + $this->request = $this->createMock(IRequest::class); |
|
45 | + $this->user = $this->createMock(IUser::class); |
|
46 | + } |
|
47 | + |
|
48 | + protected function getBasicLoginData(): LoginData { |
|
49 | + return new LoginData( |
|
50 | + $this->request, |
|
51 | + $this->username, |
|
52 | + $this->password |
|
53 | + ); |
|
54 | + } |
|
55 | + |
|
56 | + protected function getInvalidLoginData(): LoginData { |
|
57 | + return new LoginData( |
|
58 | + $this->request, |
|
59 | + $this->username, |
|
60 | + $this->password |
|
61 | + ); |
|
62 | + } |
|
63 | + |
|
64 | + protected function getFailedLoginData(): LoginData { |
|
65 | + $data = new LoginData( |
|
66 | + $this->request, |
|
67 | + $this->username, |
|
68 | + $this->password |
|
69 | + ); |
|
70 | + $data->setUser(false); |
|
71 | + return $data; |
|
72 | + } |
|
73 | + |
|
74 | + protected function getLoggedInLoginData(): LoginData { |
|
75 | + $basic = $this->getBasicLoginData(); |
|
76 | + $basic->setUser($this->user); |
|
77 | + return $basic; |
|
78 | + } |
|
79 | + |
|
80 | + protected function getLoggedInLoginDataWithRedirectUrl(): LoginData { |
|
81 | + $data = new LoginData( |
|
82 | + $this->request, |
|
83 | + $this->username, |
|
84 | + $this->password, |
|
85 | + $this->redirectUrl |
|
86 | + ); |
|
87 | + $data->setUser($this->user); |
|
88 | + return $data; |
|
89 | + } |
|
90 | + |
|
91 | + protected function getLoggedInLoginDataWithTimezone(): LoginData { |
|
92 | + $data = new LoginData( |
|
93 | + $this->request, |
|
94 | + $this->username, |
|
95 | + $this->password, |
|
96 | + null, |
|
97 | + $this->timezone, |
|
98 | + $this->timeZoneOffset |
|
99 | + ); |
|
100 | + $data->setUser($this->user); |
|
101 | + return $data; |
|
102 | + } |
|
103 | 103 | } |
@@ -14,33 +14,33 @@ |
||
14 | 14 | use PHPUnit\Framework\MockObject\MockObject; |
15 | 15 | |
16 | 16 | class UpdateLastPasswordConfirmCommandTest extends ALoginTestCommand { |
17 | - /** @var ISession|MockObject */ |
|
18 | - private $session; |
|
19 | - |
|
20 | - protected function setUp(): void { |
|
21 | - parent::setUp(); |
|
22 | - |
|
23 | - $this->session = $this->createMock(ISession::class); |
|
24 | - |
|
25 | - $this->cmd = new UpdateLastPasswordConfirmCommand( |
|
26 | - $this->session |
|
27 | - ); |
|
28 | - } |
|
29 | - |
|
30 | - public function testProcess(): void { |
|
31 | - $data = $this->getLoggedInLoginData(); |
|
32 | - $this->user->expects($this->once()) |
|
33 | - ->method('getLastLogin') |
|
34 | - ->willReturn(1234); |
|
35 | - $this->session->expects($this->once()) |
|
36 | - ->method('set') |
|
37 | - ->with( |
|
38 | - 'last-password-confirm', |
|
39 | - 1234 |
|
40 | - ); |
|
41 | - |
|
42 | - $result = $this->cmd->process($data); |
|
43 | - |
|
44 | - $this->assertTrue($result->isSuccess()); |
|
45 | - } |
|
17 | + /** @var ISession|MockObject */ |
|
18 | + private $session; |
|
19 | + |
|
20 | + protected function setUp(): void { |
|
21 | + parent::setUp(); |
|
22 | + |
|
23 | + $this->session = $this->createMock(ISession::class); |
|
24 | + |
|
25 | + $this->cmd = new UpdateLastPasswordConfirmCommand( |
|
26 | + $this->session |
|
27 | + ); |
|
28 | + } |
|
29 | + |
|
30 | + public function testProcess(): void { |
|
31 | + $data = $this->getLoggedInLoginData(); |
|
32 | + $this->user->expects($this->once()) |
|
33 | + ->method('getLastLogin') |
|
34 | + ->willReturn(1234); |
|
35 | + $this->session->expects($this->once()) |
|
36 | + ->method('set') |
|
37 | + ->with( |
|
38 | + 'last-password-confirm', |
|
39 | + 1234 |
|
40 | + ); |
|
41 | + |
|
42 | + $result = $this->cmd->process($data); |
|
43 | + |
|
44 | + $this->assertTrue($result->isSuccess()); |
|
45 | + } |
|
46 | 46 | } |