Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions apps/oauth2/lib/Controller/LoginRedirectorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ public function authorize($client_id,
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') {
Expand Down
22 changes: 21 additions & 1 deletion apps/oauth2/tests/Controller/LoginRedirectorControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@

namespace OCA\OAuth2\Tests\Controller;

use OCA\Files_Sharing\Tests\TestCase;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's weird. I guess it was not intended to use OCA\Files_Sharing\Tests\TestCase as base class for LoginRedirectorControllerTest.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully it's unrelated but a lot of tests failed related to sharing. Restarted the test a few hours ago but job is still pending. Probably the CI want's a weekend too.

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
Expand Down Expand Up @@ -114,4 +116,22 @@ public function testAuthorizeWrongResponseType() {
$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());
}
}