2017-01-05 04:31:31 +05:30
|
|
|
<?php
|
2019-09-22 02:47:21 +05:30
|
|
|
declare(strict_types=1);
|
|
|
|
|
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\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
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function issueTokenWithPublicScopes(FunctionalTester $I): void {
|
2019-09-22 02:47:21 +05:30
|
|
|
$I->wantTo('issue token as not trusted client and require only public scopes');
|
|
|
|
// We don't have any public scopes yet for this grant, so the test runs with an empty set
|
|
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
|
|
'grant_type' => 'client_credentials',
|
|
|
|
'client_id' => 'ely',
|
|
|
|
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
|
|
|
'scope' => '',
|
|
|
|
]);
|
|
|
|
$this->assertSuccessResponse($I);
|
2017-01-05 04:31:31 +05:30
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function issueTokenWithInternalScopesAsNotTrustedClient(FunctionalTester $I): void {
|
2019-09-22 02:47:21 +05:30
|
|
|
$I->wantTo('issue token as not trusted client and require some internal scope');
|
|
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
|
|
'grant_type' => 'client_credentials',
|
|
|
|
'client_id' => 'ely',
|
|
|
|
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
|
|
|
'scope' => 'block_account',
|
|
|
|
]);
|
2017-01-05 04:31:31 +05:30
|
|
|
$I->canSeeResponseCodeIs(400);
|
2019-09-22 02:47:21 +05:30
|
|
|
$I->canSeeResponseIsJson();
|
2017-01-05 04:31:31 +05:30
|
|
|
$I->canSeeResponseContainsJson([
|
2019-09-22 02:47:21 +05:30
|
|
|
'error' => 'invalid_scope',
|
2017-01-05 04:31:31 +05:30
|
|
|
]);
|
2019-09-22 02:47:21 +05:30
|
|
|
}
|
2017-01-05 04:31:31 +05:30
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function issueTokenWithInternalScopesAsTrustedClient(FunctionalTester $I): void {
|
2019-09-22 02:47:21 +05:30
|
|
|
$I->wantTo('issue token as trusted client and require some internal scope');
|
|
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
|
|
'grant_type' => 'client_credentials',
|
|
|
|
'client_id' => 'trusted-client',
|
|
|
|
'client_secret' => 'tXBbyvMcyaOgHMOAXBpN2EC7uFoJAaL9',
|
|
|
|
'scope' => 'block_account',
|
2017-01-05 04:31:31 +05:30
|
|
|
]);
|
2019-09-22 02:47:21 +05:30
|
|
|
$this->assertSuccessResponse($I);
|
|
|
|
}
|
2017-01-05 04:31:31 +05:30
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function issueTokenByPassingInvalidClientId(FunctionalTester $I): void {
|
2019-09-22 02:47:21 +05:30
|
|
|
$I->wantToTest('behavior on passing invalid client_id');
|
|
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
|
|
'grant_type' => 'client_credentials',
|
|
|
|
'client_id' => 'invalid-client',
|
|
|
|
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
|
|
|
'scope' => 'block_account',
|
|
|
|
]);
|
2017-01-05 04:31:31 +05:30
|
|
|
$I->canSeeResponseCodeIs(401);
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'invalid_client',
|
|
|
|
]);
|
2019-09-22 02:47:21 +05:30
|
|
|
}
|
2017-01-05 04:31:31 +05:30
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function issueTokenByPassingInvalidClientSecret(FunctionalTester $I): void {
|
2017-01-05 04:31:31 +05:30
|
|
|
$I->wantTo('check behavior on passing invalid client_secret');
|
2019-09-22 02:47:21 +05:30
|
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
|
|
'grant_type' => 'client_credentials',
|
|
|
|
'client_id' => 'trusted-client',
|
|
|
|
'client_secret' => 'invalid-secret',
|
|
|
|
'scope' => 'block_account',
|
|
|
|
]);
|
2017-01-05 04:31:31 +05:30
|
|
|
$I->canSeeResponseCodeIs(401);
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'invalid_client',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-09-22 02:47:21 +05:30
|
|
|
private function assertSuccessResponse(FunctionalTester $I): void {
|
2017-01-05 04:31:31 +05:30
|
|
|
$I->canSeeResponseCodeIs(200);
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'token_type' => 'Bearer',
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.access_token');
|
2019-12-13 18:30:51 +05:30
|
|
|
$I->cantSeeResponseJsonMatchesJsonPath('$.expires_in');
|
2019-09-22 02:47:21 +05:30
|
|
|
$I->cantSeeResponseJsonMatchesJsonPath('$.refresh_token');
|
2017-01-05 04:31:31 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|