2016-02-23 03:19:46 +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;
|
2016-02-23 03:19:46 +05:30
|
|
|
|
2019-02-21 01:28:52 +05:30
|
|
|
use api\tests\functional\_steps\OauthSteps;
|
2016-02-23 03:19:46 +05:30
|
|
|
|
2017-06-12 17:04:39 +05:30
|
|
|
class RefreshTokenCest {
|
2016-02-23 03:19:46 +05:30
|
|
|
|
2019-09-22 02:47:21 +05:30
|
|
|
public function refreshToken(OauthSteps $I) {
|
|
|
|
$I->wantTo('refresh token without passing the desired scopes');
|
2016-02-23 03:19:46 +05:30
|
|
|
$refreshToken = $I->getRefreshToken();
|
2019-09-22 02:47:21 +05:30
|
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
|
|
'grant_type' => 'refresh_token',
|
|
|
|
'refresh_token' => $refreshToken,
|
|
|
|
'client_id' => 'ely',
|
|
|
|
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
|
|
|
]);
|
2016-11-29 04:27:58 +05:30
|
|
|
$this->canSeeRefreshTokenSuccess($I);
|
2016-02-23 03:19:46 +05:30
|
|
|
}
|
|
|
|
|
2019-09-22 02:47:21 +05:30
|
|
|
public function refreshTokenWithSameScopes(OauthSteps $I) {
|
|
|
|
$refreshToken = $I->getRefreshToken(['minecraft_server_session']);
|
|
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
|
|
'grant_type' => 'refresh_token',
|
|
|
|
'refresh_token' => $refreshToken,
|
|
|
|
'client_id' => 'ely',
|
|
|
|
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
|
|
|
'scope' => 'minecraft_server_session offline_access',
|
|
|
|
]);
|
2016-11-29 04:27:58 +05:30
|
|
|
$this->canSeeRefreshTokenSuccess($I);
|
|
|
|
}
|
|
|
|
|
2019-09-22 02:47:21 +05:30
|
|
|
public function refreshTokenTwice(OauthSteps $I) {
|
|
|
|
$I->wantTo('refresh token two times in a row and ensure, that token isn\'t rotating');
|
|
|
|
$refreshToken = $I->getRefreshToken(['minecraft_server_session']);
|
|
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
|
|
'grant_type' => 'refresh_token',
|
|
|
|
'refresh_token' => $refreshToken,
|
|
|
|
'client_id' => 'ely',
|
|
|
|
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
|
|
|
'scope' => 'minecraft_server_session',
|
|
|
|
]);
|
2016-11-29 04:27:58 +05:30
|
|
|
$this->canSeeRefreshTokenSuccess($I);
|
|
|
|
|
2019-09-22 02:47:21 +05:30
|
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
|
|
'grant_type' => 'refresh_token',
|
|
|
|
'refresh_token' => $refreshToken,
|
|
|
|
'client_id' => 'ely',
|
|
|
|
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
|
|
|
'scope' => 'minecraft_server_session',
|
|
|
|
]);
|
2016-11-29 04:27:58 +05:30
|
|
|
$this->canSeeRefreshTokenSuccess($I);
|
2016-02-23 03:19:46 +05:30
|
|
|
}
|
|
|
|
|
2019-09-22 02:47:21 +05:30
|
|
|
public function passInvalidRefreshToken(OauthSteps $I) {
|
|
|
|
$I->wantToTest('behaviour of the server when invalid refresh token passed');
|
|
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
|
|
'grant_type' => 'refresh_token',
|
|
|
|
'refresh_token' => 'some-invalid-refresh-token',
|
|
|
|
'client_id' => 'ely',
|
|
|
|
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseCodeIs(401);
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'invalid_request',
|
|
|
|
'message' => 'The refresh token is invalid.',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requireNewScopes(OauthSteps $I) {
|
|
|
|
$I->wantToTest('behavior when required the new scope that was not issued with original token');
|
|
|
|
$refreshToken = $I->getRefreshToken(['minecraft_server_session']);
|
|
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
|
|
'grant_type' => 'refresh_token',
|
|
|
|
'refresh_token' => $refreshToken,
|
|
|
|
'client_id' => 'ely',
|
|
|
|
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
|
|
|
'scope' => 'minecraft_server_session account_email',
|
|
|
|
]);
|
2016-02-23 03:19:46 +05:30
|
|
|
$I->canSeeResponseCodeIs(400);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'invalid_scope',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2016-11-29 04:27:58 +05:30
|
|
|
private function canSeeRefreshTokenSuccess(OauthSteps $I) {
|
|
|
|
$I->canSeeResponseCodeIs(200);
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'token_type' => 'Bearer',
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.access_token');
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.expires_in');
|
|
|
|
$I->cantSeeResponseJsonMatchesJsonPath('$.refresh_token');
|
|
|
|
}
|
|
|
|
|
2016-02-23 03:19:46 +05:30
|
|
|
}
|