2017-01-05 04:31:31 +05:30
|
|
|
<?php
|
2019-02-21 01:28:52 +05:30
|
|
|
namespace api\tests\functional\oauth;
|
2017-01-05 04:31:31 +05:30
|
|
|
|
2019-02-21 01:28:52 +05:30
|
|
|
use api\tests\_pages\OauthRoute;
|
|
|
|
use api\tests\functional\_steps\OauthSteps;
|
|
|
|
use api\tests\FunctionalTester;
|
2017-01-05 04:31:31 +05:30
|
|
|
|
2017-06-12 17:04:39 +05:30
|
|
|
class ClientCredentialsCest {
|
2017-01-05 04:31:31 +05:30
|
|
|
|
|
|
|
/**
|
|
|
|
* @var OauthRoute
|
|
|
|
*/
|
|
|
|
private $route;
|
|
|
|
|
|
|
|
public function _before(FunctionalTester $I) {
|
|
|
|
$this->route = new OauthRoute($I);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIssueTokenWithWrongArgs(FunctionalTester $I) {
|
|
|
|
$I->wantTo('check behavior on on request without any credentials');
|
|
|
|
$this->route->issueToken($this->buildParams());
|
|
|
|
$I->canSeeResponseCodeIs(400);
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'invalid_request',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$I->wantTo('check behavior on passing invalid client_id');
|
|
|
|
$this->route->issueToken($this->buildParams(
|
|
|
|
'invalid-client',
|
|
|
|
'invalid-secret',
|
|
|
|
['invalid-scope']
|
|
|
|
));
|
|
|
|
$I->canSeeResponseCodeIs(401);
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'invalid_client',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$I->wantTo('check behavior on passing invalid client_secret');
|
|
|
|
$this->route->issueToken($this->buildParams(
|
|
|
|
'ely',
|
|
|
|
'invalid-secret',
|
|
|
|
['invalid-scope']
|
|
|
|
));
|
|
|
|
$I->canSeeResponseCodeIs(401);
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'invalid_client',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$I->wantTo('check behavior on passing invalid client_secret');
|
|
|
|
$this->route->issueToken($this->buildParams(
|
|
|
|
'ely',
|
|
|
|
'invalid-secret',
|
|
|
|
['invalid-scope']
|
|
|
|
));
|
|
|
|
$I->canSeeResponseCodeIs(401);
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'invalid_client',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIssueTokenWithPublicScopes(OauthSteps $I) {
|
2019-07-15 04:29:56 +05:30
|
|
|
// TODO: we don't have any public scopes yet for this grant, so the test runs with an empty set
|
2017-01-05 04:31:31 +05:30
|
|
|
$this->route->issueToken($this->buildParams(
|
|
|
|
'ely',
|
|
|
|
'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
|
|
|
[]
|
|
|
|
));
|
|
|
|
$I->canSeeResponseCodeIs(200);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'token_type' => 'Bearer',
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.access_token');
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.expires_in');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIssueTokenWithInternalScopes(OauthSteps $I) {
|
|
|
|
$this->route->issueToken($this->buildParams(
|
|
|
|
'ely',
|
|
|
|
'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
2017-09-19 22:36:16 +05:30
|
|
|
['account_block']
|
2017-01-05 04:31:31 +05:30
|
|
|
));
|
|
|
|
$I->canSeeResponseCodeIs(400);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'invalid_scope',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->route->issueToken($this->buildParams(
|
|
|
|
'trusted-client',
|
|
|
|
'tXBbyvMcyaOgHMOAXBpN2EC7uFoJAaL9',
|
2017-09-19 22:36:16 +05:30
|
|
|
['account_block']
|
2017-01-05 04:31:31 +05:30
|
|
|
));
|
|
|
|
$I->canSeeResponseCodeIs(200);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'token_type' => 'Bearer',
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.access_token');
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.expires_in');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildParams($clientId = null, $clientSecret = null, array $scopes = null) {
|
|
|
|
$params = ['grant_type' => 'client_credentials'];
|
|
|
|
if ($clientId !== null) {
|
|
|
|
$params['client_id'] = $clientId;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($clientSecret !== null) {
|
|
|
|
$params['client_secret'] = $clientSecret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($scopes !== null) {
|
|
|
|
$params['scope'] = implode(',', $scopes);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $params;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|