Skip to content

Commit

Permalink
Show warning in case the server cuts out auth header
Browse files Browse the repository at this point in the history
  • Loading branch information
VicDeo committed Jan 21, 2020
1 parent 7196bf6 commit ef61fff
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
]
Expand Down
15 changes: 15 additions & 0 deletions js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
);
}
});
});
11 changes: 11 additions & 0 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,15 @@ private function sendErrorResponse($message) {
]
);
}

/**
* Checks if the server configured properly
*
* @return string[]
*/
public function test() {
return [
'authHeaderFound' => $this->request->getHeader('Authorization') !== null
];
}
}
20 changes: 19 additions & 1 deletion tests/Unit/Controller/SettingsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
}
}

0 comments on commit ef61fff

Please sign in to comment.