diff --git a/appinfo/routes.php b/appinfo/routes.php index b41c3229..47c11ece 100755 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -33,6 +33,7 @@ # Routes for admin settings ['name' => 'settings#addClient', 'url' => '/clients', 'verb' => 'POST'], ['name' => 'settings#deleteClient', 'url' => '/clients/{id}/delete', 'verb' => 'POST'], + ['name' => 'settings#test', 'url' => '/test', 'verb' => 'POST'], # Routes for personal settings ['name' => 'settings#revokeAuthorization', 'url' => '/clients/{id}/revoke', 'verb' => 'POST'] ] diff --git a/js/settings.js b/js/settings.js index cabe9084..c7f9e8d1 100644 --- a/js/settings.js +++ b/js/settings.js @@ -27,4 +27,19 @@ $(document).ready(function () { } }, false); } + + var testToken = Math.random().toString(); + $.ajax({ + type: 'POST', + url: OC.generateUrl('apps/oauth2/test'), + headers: { + 'Authorization': 'Bearer ' + testToken + } + }).done(function(data){ + if (data.authHeaderFound !== true) { + OC.Notification.show( + 'Oauth2 will not work properly as your webserver does not pass Authorization header to PHP.' + ); + } + }); }); diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 95a67d0a..65c1dd25 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -219,4 +219,15 @@ private function sendErrorResponse($message) { ] ); } + + /** + * Checks if the server configured properly + * + * @return bool[] + */ + public function test() { + return [ + 'authHeaderFound' => $this->request->getHeader('Authorization') !== null + ]; + } } diff --git a/tests/Unit/Controller/SettingsControllerTest.php b/tests/Unit/Controller/SettingsControllerTest.php index e5a88695..8d17e2fd 100755 --- a/tests/Unit/Controller/SettingsControllerTest.php +++ b/tests/Unit/Controller/SettingsControllerTest.php @@ -41,7 +41,7 @@ class SettingsControllerTest extends TestCase { /** @var string $name */ private $appName; - /** @var IRequest */ + /** @var IRequest | \PHPUnit\Framework\MockObject\MockObject */ private $request; /** @var SettingsController $controller */ @@ -257,4 +257,22 @@ public function testRevokeAuthorization() { $this->assertEquals(0, \count($this->accessTokenMapper->findAll())); $this->assertEquals(0, \count($this->refreshTokenMapper->findAll())); } + + public function healthDataProvider() { + return [ + ['someToken', ['authHeaderFound' => true]], + [null, ['authHeaderFound' => false]] + ]; + } + + /** + * @dataProvider healthDataProvider + * @param string $authHeader + * @param array $expectedResult + */ + public function testTest($authHeader, $expectedResult) { + $this->request->method('getHeader')->willReturn($authHeader); + $result = $this->controller->test(); + $this->assertEquals($result, $expectedResult); + } }