diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-03-17 19:38:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-17 19:38:22 +0100 |
commit | 7e1bee338953ed1b892f2924db21cf63da1c304e (patch) | |
tree | a4903b8da4f4c4a0583de93faaf175db07992b0a | |
parent | 50ec8631c6ed78518a6e26359945b6215fdf294c (diff) | |
parent | 509af24bc94ec18a57b922d65bdcc484144db736 (diff) | |
download | nextcloud-server-7e1bee338953ed1b892f2924db21cf63da1c304e.tar.gz nextcloud-server-7e1bee338953ed1b892f2924db21cf63da1c304e.zip |
Merge pull request #19964 from nextcloud/bug/19963/invalid-constructor-template-response
Fix invalid instantiation of TemplateResponse if client not found
-rw-r--r-- | apps/oauth2/lib/Controller/LoginRedirectorController.php | 7 | ||||
-rw-r--r-- | apps/oauth2/tests/Controller/LoginRedirectorControllerTest.php | 22 |
2 files changed, 24 insertions, 5 deletions
diff --git a/apps/oauth2/lib/Controller/LoginRedirectorController.php b/apps/oauth2/lib/Controller/LoginRedirectorController.php index 8700ce10172..b5568b824d3 100644 --- a/apps/oauth2/lib/Controller/LoginRedirectorController.php +++ b/apps/oauth2/lib/Controller/LoginRedirectorController.php @@ -85,11 +85,10 @@ class LoginRedirectorController extends Controller { try { $client = $this->clientMapper->getByIdentifier($client_id); } catch (ClientNotFoundException $e) { - $response = new TemplateResponse('core', '404', 'guest'); - $response->setParams([ + $params = [ 'content' => $this->l->t('Your client is not authorized to connect. Please inform the administrator of your client.'), - ]); - return $response; + ]; + return new TemplateResponse('core', '404', $params, 'guest'); } if ($response_type !== 'code') { diff --git a/apps/oauth2/tests/Controller/LoginRedirectorControllerTest.php b/apps/oauth2/tests/Controller/LoginRedirectorControllerTest.php index a2dfd048dda..9bea0b328cb 100644 --- a/apps/oauth2/tests/Controller/LoginRedirectorControllerTest.php +++ b/apps/oauth2/tests/Controller/LoginRedirectorControllerTest.php @@ -24,15 +24,17 @@ namespace OCA\OAuth2\Tests\Controller; -use OCA\Files_Sharing\Tests\TestCase; use OCA\OAuth2\Controller\LoginRedirectorController; use OCA\OAuth2\Db\Client; use OCA\OAuth2\Db\ClientMapper; +use OCA\OAuth2\Exceptions\ClientNotFoundException; use OCP\AppFramework\Http\RedirectResponse; +use OCP\AppFramework\Http\TemplateResponse; use OCP\IL10N; use OCP\IRequest; use OCP\ISession; use OCP\IURLGenerator; +use Test\TestCase; /** * @group DB @@ -114,4 +116,22 @@ class LoginRedirectorControllerTest extends TestCase { $expected = new RedirectResponse('http://foo.bar?error=unsupported_response_type&state=MyState'); $this->assertEquals($expected, $this->loginRedirectorController->authorize('MyClientId', 'MyState', 'wrongcode')); } + + public function testClientNotFound() { + $clientNotFound = new ClientNotFoundException('could not find client test123', 0); + $this->clientMapper + ->expects($this->once()) + ->method('getByIdentifier') + ->willThrowException($clientNotFound); + $this->session + ->expects($this->never()) + ->method('set'); + + $response = $this->loginRedirectorController->authorize('MyClientId', 'MyState', 'wrongcode'); + $this->assertInstanceOf(TemplateResponse::class, $response); + + /** @var TemplateResponse $response */ + $this->assertEquals('404', $response->getTemplateName()); + $this->assertEquals('guest', $response->getRenderAs()); + } } |