mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
* start updating to PHP 8.3 * taking off! Co-authored-by: ErickSkrauch <erickskrauch@yandex.ru> Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * dropped this Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * migrate to symfonymailer Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * this is so stupid 😭 Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * ah, free, at last. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * oh, Gabriel. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * now dawns thy reckoning. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * and thy gore shall GLISTEN before the temples of man. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * creature of steel. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * my gratitude upon thee for my freedom. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * but the crimes thy kind has committed against humanity Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * Upgrade PHP-CS-Fixer and do fix the codebase * First review round (maybe I have broken something) * are NOT forgotten. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * Enable parallel PHP-CS-Fixer runner * PHPStan level 1 * PHPStan level 2 * PHPStan level 3 * PHPStan level 4 * PHPStan level 5 * Levels 6 and 7 takes too much effort. Generate a baseline and fix them eventually * Resolve TODO's related to the php-mock * Drastically reduce baseline size with the Rector * More code modernization with help of the Rector * Update GitLab CI --------- Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> Co-authored-by: ErickSkrauch <erickskrauch@yandex.ru>
96 lines
4.0 KiB
PHP
96 lines
4.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace api\tests\functional\oauth;
|
|
|
|
use api\tests\functional\_steps\OauthSteps;
|
|
|
|
final class AccessTokenCest {
|
|
|
|
public function successfullyIssueTokenWithUrlEncodedBody(OauthSteps $I): void {
|
|
$I->wantTo('complete oauth flow and obtain access_token');
|
|
$authCode = $I->obtainAuthCode();
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
'grant_type' => 'authorization_code',
|
|
'code' => $authCode,
|
|
'client_id' => 'ely',
|
|
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
|
'redirect_uri' => 'http://ely.by',
|
|
]);
|
|
$I->canSeeResponseCodeIs(200);
|
|
$I->canSeeResponseContainsJson([
|
|
'token_type' => 'Bearer',
|
|
]);
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.access_token');
|
|
$I->cantSeeResponseJsonMatchesJsonPath('$.expires_in');
|
|
$I->cantSeeResponseJsonMatchesJsonPath('$.refresh_token');
|
|
}
|
|
|
|
public function successfullyIssueOfflineTokenWithJsonEncodedBody(OauthSteps $I): void {
|
|
$I->wantTo('complete oauth flow with offline_access scope and obtain access_token and refresh_token');
|
|
$authCode = $I->obtainAuthCode(['offline_access']);
|
|
$I->haveHttpHeader('Content-Type', 'application/json');
|
|
// @phpstan-ignore argument.type (it does accept string an we need it to ensure, that JSON passes)
|
|
$I->sendPOST('/api/oauth2/v1/token', json_encode([
|
|
'grant_type' => 'authorization_code',
|
|
'code' => $authCode,
|
|
'client_id' => 'ely',
|
|
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
|
'redirect_uri' => 'http://ely.by',
|
|
]));
|
|
$I->canSeeResponseCodeIs(200);
|
|
$I->canSeeResponseContainsJson([
|
|
'token_type' => 'Bearer',
|
|
]);
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.access_token');
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.expires_in');
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.refresh_token');
|
|
}
|
|
|
|
public function callEndpointWithByEmptyRequest(OauthSteps $I): void {
|
|
$I->wantTo('check behavior on on request without any params');
|
|
$I->sendPOST('/api/oauth2/v1/token');
|
|
$I->canSeeResponseCodeIs(400);
|
|
$I->canSeeResponseContainsJson([
|
|
'error' => 'unsupported_grant_type',
|
|
'message' => 'The authorization grant type is not supported by the authorization server.',
|
|
]);
|
|
}
|
|
|
|
public function issueTokenByPassingInvalidAuthCode(OauthSteps $I): void {
|
|
$I->wantTo('check behavior on passing invalid auth code');
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
'grant_type' => 'authorization_code',
|
|
'code' => 'wrong-auth-code',
|
|
'client_id' => 'ely',
|
|
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
|
'redirect_uri' => 'http://ely.by',
|
|
]);
|
|
$I->canSeeResponseCodeIs(400);
|
|
$I->canSeeResponseContainsJson([
|
|
'error' => 'invalid_grant',
|
|
'message' => 'The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token '
|
|
. 'is invalid, expired, revoked, does not match the redirection URI used in the authorization request, '
|
|
. 'or was issued to another client.',
|
|
]);
|
|
}
|
|
|
|
public function issueTokenByPassingInvalidRedirectUri(OauthSteps $I): void {
|
|
$I->wantTo('check behavior on passing invalid redirect_uri');
|
|
$authCode = $I->obtainAuthCode();
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
'grant_type' => 'authorization_code',
|
|
'code' => $authCode,
|
|
'client_id' => 'ely',
|
|
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
|
'redirect_uri' => 'http://some-other.domain',
|
|
]);
|
|
$I->canSeeResponseCodeIs(401);
|
|
$I->canSeeResponseContainsJson([
|
|
'error' => 'invalid_client',
|
|
'message' => 'Client authentication failed',
|
|
]);
|
|
}
|
|
|
|
}
|