2016-02-23 03:19:46 +05:30
|
|
|
<?php
|
2019-02-21 01:28:52 +05:30
|
|
|
namespace api\tests\functional\oauth;
|
2016-02-23 03:19:46 +05:30
|
|
|
|
2017-09-19 22:36:16 +05:30
|
|
|
use api\components\OAuth2\Storage\ScopeStorage as S;
|
2019-08-02 05:59:20 +05:30
|
|
|
use api\rbac\Permissions as P;
|
2019-02-21 01:28:52 +05:30
|
|
|
use api\tests\_pages\OauthRoute;
|
|
|
|
use api\tests\functional\_steps\OauthSteps;
|
|
|
|
use api\tests\FunctionalTester;
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* @var OauthRoute
|
|
|
|
*/
|
|
|
|
private $route;
|
|
|
|
|
|
|
|
public function _before(FunctionalTester $I) {
|
|
|
|
$this->route = new OauthRoute($I);
|
|
|
|
}
|
2017-02-05 17:56:44 +05:30
|
|
|
|
|
|
|
public function testInvalidRefreshToken(OauthSteps $I) {
|
|
|
|
$this->route->issueToken($this->buildParams(
|
|
|
|
'some-invalid-refresh-token',
|
|
|
|
'ely',
|
|
|
|
'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM'
|
|
|
|
));
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'invalid_request',
|
|
|
|
'message' => 'The refresh token is invalid.',
|
|
|
|
]);
|
|
|
|
}
|
2016-02-23 03:19:46 +05:30
|
|
|
|
2016-05-10 17:37:32 +05:30
|
|
|
public function testRefreshToken(OauthSteps $I) {
|
2016-02-23 03:19:46 +05:30
|
|
|
$refreshToken = $I->getRefreshToken();
|
|
|
|
$this->route->issueToken($this->buildParams(
|
|
|
|
$refreshToken,
|
|
|
|
'ely',
|
|
|
|
'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM'
|
|
|
|
));
|
2016-11-29 04:27:58 +05:30
|
|
|
$this->canSeeRefreshTokenSuccess($I);
|
2016-02-23 03:19:46 +05:30
|
|
|
}
|
|
|
|
|
2016-05-10 17:37:32 +05:30
|
|
|
public function testRefreshTokenWithSameScopes(OauthSteps $I) {
|
2017-09-19 22:36:16 +05:30
|
|
|
$refreshToken = $I->getRefreshToken([P::MINECRAFT_SERVER_SESSION]);
|
2016-02-23 03:19:46 +05:30
|
|
|
$this->route->issueToken($this->buildParams(
|
|
|
|
$refreshToken,
|
|
|
|
'ely',
|
|
|
|
'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
2017-09-19 22:36:16 +05:30
|
|
|
[P::MINECRAFT_SERVER_SESSION, S::OFFLINE_ACCESS]
|
2016-02-23 03:19:46 +05:30
|
|
|
));
|
2016-11-29 04:27:58 +05:30
|
|
|
$this->canSeeRefreshTokenSuccess($I);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRefreshTokenTwice(OauthSteps $I) {
|
2017-09-19 22:36:16 +05:30
|
|
|
$refreshToken = $I->getRefreshToken([P::MINECRAFT_SERVER_SESSION]);
|
2016-11-29 04:27:58 +05:30
|
|
|
$this->route->issueToken($this->buildParams(
|
|
|
|
$refreshToken,
|
|
|
|
'ely',
|
|
|
|
'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
2017-09-19 22:36:16 +05:30
|
|
|
[P::MINECRAFT_SERVER_SESSION, S::OFFLINE_ACCESS]
|
2016-11-29 04:27:58 +05:30
|
|
|
));
|
|
|
|
$this->canSeeRefreshTokenSuccess($I);
|
|
|
|
|
|
|
|
$this->route->issueToken($this->buildParams(
|
|
|
|
$refreshToken,
|
|
|
|
'ely',
|
|
|
|
'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
2017-09-19 22:36:16 +05:30
|
|
|
[P::MINECRAFT_SERVER_SESSION, S::OFFLINE_ACCESS]
|
2016-11-29 04:27:58 +05:30
|
|
|
));
|
|
|
|
$this->canSeeRefreshTokenSuccess($I);
|
2016-02-23 03:19:46 +05:30
|
|
|
}
|
|
|
|
|
2016-05-10 17:37:32 +05:30
|
|
|
public function testRefreshTokenWithNewScopes(OauthSteps $I) {
|
2017-09-19 22:36:16 +05:30
|
|
|
$refreshToken = $I->getRefreshToken([P::MINECRAFT_SERVER_SESSION]);
|
2016-02-23 03:19:46 +05:30
|
|
|
$this->route->issueToken($this->buildParams(
|
|
|
|
$refreshToken,
|
|
|
|
'ely',
|
|
|
|
'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
2017-09-19 22:36:16 +05:30
|
|
|
[P::MINECRAFT_SERVER_SESSION, S::OFFLINE_ACCESS, 'account_email']
|
2016-02-23 03:19:46 +05:30
|
|
|
));
|
|
|
|
$I->canSeeResponseCodeIs(400);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'invalid_scope',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildParams($refreshToken = null, $clientId = null, $clientSecret = null, $scopes = []) {
|
|
|
|
$params = ['grant_type' => 'refresh_token'];
|
|
|
|
if ($refreshToken !== null) {
|
|
|
|
$params['refresh_token'] = $refreshToken;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($clientId !== null) {
|
|
|
|
$params['client_id'] = $clientId;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($clientSecret !== null) {
|
|
|
|
$params['client_secret'] = $clientSecret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($scopes)) {
|
|
|
|
if (is_array($scopes)) {
|
|
|
|
$scopes = implode(',', $scopes);
|
|
|
|
}
|
|
|
|
|
|
|
|
$params['scope'] = $scopes;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $params;
|
|
|
|
}
|
|
|
|
|
2016-11-29 04:27:58 +05:30
|
|
|
private function canSeeRefreshTokenSuccess(OauthSteps $I) {
|
|
|
|
$I->canSeeResponseCodeIs(200);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$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
|
|
|
}
|