|
11 | 11 | use OC\Core\Controller\ClientFlowLoginV2Controller; |
12 | 12 | use OC\Core\Data\LoginFlowV2Credentials; |
13 | 13 | use OC\Core\Db\LoginFlowV2; |
| 14 | +use OC\Core\Exception\LoginFlowV2ClientForbiddenException; |
14 | 15 | use OC\Core\Exception\LoginFlowV2NotFoundException; |
15 | 16 | use OC\Core\Service\LoginFlowV2Service; |
16 | 17 | use OCP\AppFramework\Http; |
@@ -56,6 +57,12 @@ protected function setUp(): void { |
56 | 57 | $this->random = $this->createMock(ISecureRandom::class); |
57 | 58 | $this->defaults = $this->createMock(Defaults::class); |
58 | 59 | $this->l = $this->createMock(IL10N::class); |
| 60 | + $this->l |
| 61 | + ->expects($this->any()) |
| 62 | + ->method('t') |
| 63 | + ->willReturnCallback(function ($text, $parameters = []) { |
| 64 | + return vsprintf($text, $parameters); |
| 65 | + }); |
59 | 66 | $this->controller = new ClientFlowLoginV2Controller( |
60 | 67 | 'core', |
61 | 68 | $this->request, |
@@ -150,6 +157,22 @@ public function testShowAuthPickerInvalidLoginToken(): void { |
150 | 157 | $this->assertSame(Http::STATUS_FORBIDDEN, $result->getStatus()); |
151 | 158 | } |
152 | 159 |
|
| 160 | + public function testShowAuthPickerForbiddenUserClient() { |
| 161 | + $this->session->method('get') |
| 162 | + ->with('client.flow.v2.login.token') |
| 163 | + ->willReturn('loginToken'); |
| 164 | + |
| 165 | + $this->loginFlowV2Service->method('getByLoginToken') |
| 166 | + ->with('loginToken') |
| 167 | + ->willThrowException(new LoginFlowV2ClientForbiddenException()); |
| 168 | + |
| 169 | + $result = $this->controller->showAuthPickerPage(); |
| 170 | + |
| 171 | + $this->assertInstanceOf(Http\StandaloneTemplateResponse::class, $result); |
| 172 | + $this->assertSame(Http::STATUS_FORBIDDEN, $result->getStatus()); |
| 173 | + $this->assertSame('Please use original client', $result->getParams()['message']); |
| 174 | + } |
| 175 | + |
153 | 176 | public function testShowAuthPickerValidLoginToken(): void { |
154 | 177 | $this->session->method('get') |
155 | 178 | ->with('client.flow.v2.login.token') |
@@ -206,6 +229,29 @@ public function testGrantPageInvalidLoginToken(): void { |
206 | 229 | $this->assertSame(Http::STATUS_FORBIDDEN, $result->getStatus()); |
207 | 230 | } |
208 | 231 |
|
| 232 | + public function testGrantPageForbiddenUserClient() { |
| 233 | + $this->session->method('get') |
| 234 | + ->willReturnCallback(function ($name) { |
| 235 | + if ($name === 'client.flow.v2.state.token') { |
| 236 | + return 'stateToken'; |
| 237 | + } |
| 238 | + if ($name === 'client.flow.v2.login.token') { |
| 239 | + return 'loginToken'; |
| 240 | + } |
| 241 | + return null; |
| 242 | + }); |
| 243 | + |
| 244 | + $this->loginFlowV2Service->method('getByLoginToken') |
| 245 | + ->with('loginToken') |
| 246 | + ->willThrowException(new LoginFlowV2ClientForbiddenException()); |
| 247 | + |
| 248 | + $result = $this->controller->grantPage('stateToken'); |
| 249 | + |
| 250 | + $this->assertInstanceOf(Http\StandaloneTemplateResponse::class, $result); |
| 251 | + $this->assertSame(Http::STATUS_FORBIDDEN, $result->getStatus()); |
| 252 | + $this->assertSame('Please use original client', $result->getParams()['message']); |
| 253 | + } |
| 254 | + |
209 | 255 | public function testGrantPageValid(): void { |
210 | 256 | $this->session->method('get') |
211 | 257 | ->willReturnCallback(function ($name) { |
@@ -266,6 +312,29 @@ public function testGenerateAppPassworInvalidLoginToken(): void { |
266 | 312 | $this->assertSame(Http::STATUS_FORBIDDEN, $result->getStatus()); |
267 | 313 | } |
268 | 314 |
|
| 315 | + public function testGenerateAppPasswordForbiddenUserClient() { |
| 316 | + $this->session->method('get') |
| 317 | + ->willReturnCallback(function ($name) { |
| 318 | + if ($name === 'client.flow.v2.state.token') { |
| 319 | + return 'stateToken'; |
| 320 | + } |
| 321 | + if ($name === 'client.flow.v2.login.token') { |
| 322 | + return 'loginToken'; |
| 323 | + } |
| 324 | + return null; |
| 325 | + }); |
| 326 | + |
| 327 | + $this->loginFlowV2Service->method('getByLoginToken') |
| 328 | + ->with('loginToken') |
| 329 | + ->willThrowException(new LoginFlowV2ClientForbiddenException()); |
| 330 | + |
| 331 | + $result = $this->controller->generateAppPassword('stateToken'); |
| 332 | + |
| 333 | + $this->assertInstanceOf(Http\StandaloneTemplateResponse::class, $result); |
| 334 | + $this->assertSame(Http::STATUS_FORBIDDEN, $result->getStatus()); |
| 335 | + $this->assertSame('Please use original client', $result->getParams()['message']); |
| 336 | + } |
| 337 | + |
269 | 338 | public function testGenerateAppPassworValid(): void { |
270 | 339 | $this->session->method('get') |
271 | 340 | ->willReturnCallback(function ($name) { |
|
0 commit comments