2016-09-03 04:24:22 +05:30
|
|
|
<?php
|
2019-02-21 01:28:52 +05:30
|
|
|
namespace api\tests\functional\sessionserver;
|
2016-09-03 04:24:22 +05:30
|
|
|
|
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\SessionServerRoute;
|
|
|
|
use api\tests\functional\_steps\AuthserverSteps;
|
|
|
|
use api\tests\functional\_steps\OauthSteps;
|
|
|
|
use api\tests\FunctionalTester;
|
2019-12-21 04:56:06 +05:30
|
|
|
use function Ramsey\Uuid\v4 as uuid;
|
2016-09-03 04:24:22 +05:30
|
|
|
|
|
|
|
class JoinCest {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var SessionServerRoute
|
|
|
|
*/
|
|
|
|
private $route;
|
|
|
|
|
|
|
|
public function _before(AuthserverSteps $I) {
|
|
|
|
$this->route = new SessionServerRoute($I);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function joinByLegacyAuthserver(AuthserverSteps $I) {
|
|
|
|
$I->wantTo('join to server, using legacy authserver access token');
|
2017-01-24 04:30:08 +05:30
|
|
|
[$accessToken] = $I->amAuthenticated();
|
2016-09-03 04:24:22 +05:30
|
|
|
$this->route->join([
|
|
|
|
'accessToken' => $accessToken,
|
|
|
|
'selectedProfile' => 'df936908-b2e1-544d-96f8-2977ec213022',
|
2019-12-21 04:56:06 +05:30
|
|
|
'serverId' => uuid(),
|
2016-09-03 04:24:22 +05:30
|
|
|
]);
|
|
|
|
$this->expectSuccessResponse($I);
|
|
|
|
}
|
|
|
|
|
2016-09-05 20:25:38 +05:30
|
|
|
public function joinByPassJsonInPost(AuthserverSteps $I) {
|
|
|
|
$I->wantTo('join to server, passing data in body as encoded json');
|
2017-01-24 04:30:08 +05:30
|
|
|
[$accessToken] = $I->amAuthenticated();
|
2016-09-05 20:25:38 +05:30
|
|
|
$this->route->join(json_encode([
|
|
|
|
'accessToken' => $accessToken,
|
|
|
|
'selectedProfile' => 'df936908-b2e1-544d-96f8-2977ec213022',
|
2019-12-21 04:56:06 +05:30
|
|
|
'serverId' => uuid(),
|
2016-09-05 20:25:38 +05:30
|
|
|
]));
|
|
|
|
$this->expectSuccessResponse($I);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function joinByOauth2Token(OauthSteps $I) {
|
|
|
|
$I->wantTo('join to server, using modern oAuth2 generated token');
|
2017-09-19 22:36:16 +05:30
|
|
|
$accessToken = $I->getAccessToken([P::MINECRAFT_SERVER_SESSION]);
|
2016-09-03 04:24:22 +05:30
|
|
|
$this->route->join([
|
|
|
|
'accessToken' => $accessToken,
|
|
|
|
'selectedProfile' => 'df936908-b2e1-544d-96f8-2977ec213022',
|
2019-12-21 04:56:06 +05:30
|
|
|
'serverId' => uuid(),
|
2016-09-03 04:24:22 +05:30
|
|
|
]);
|
|
|
|
$this->expectSuccessResponse($I);
|
|
|
|
}
|
|
|
|
|
2017-10-20 17:32:52 +05:30
|
|
|
public function joinByOauth2TokenWithNotDashedUUID(OauthSteps $I) {
|
|
|
|
$I->wantTo('join to server, using modern oAuth2 generated token and non dashed uuid');
|
|
|
|
$accessToken = $I->getAccessToken([P::MINECRAFT_SERVER_SESSION]);
|
|
|
|
$this->route->join([
|
|
|
|
'accessToken' => $accessToken,
|
|
|
|
'selectedProfile' => 'df936908b2e1544d96f82977ec213022',
|
2019-12-21 04:56:06 +05:30
|
|
|
'serverId' => uuid(),
|
2017-10-20 17:32:52 +05:30
|
|
|
]);
|
|
|
|
$this->expectSuccessResponse($I);
|
|
|
|
}
|
|
|
|
|
2016-09-03 04:24:22 +05:30
|
|
|
public function joinByModernOauth2TokenWithoutPermission(OauthSteps $I) {
|
|
|
|
$I->wantTo('join to server, using moder oAuth2 generated token, but without minecraft auth permission');
|
2017-09-19 22:36:16 +05:30
|
|
|
$accessToken = $I->getAccessToken(['account_info', 'account_email']);
|
2016-09-03 04:24:22 +05:30
|
|
|
$this->route->join([
|
|
|
|
'accessToken' => $accessToken,
|
|
|
|
'selectedProfile' => 'df936908-b2e1-544d-96f8-2977ec213022',
|
2019-12-21 04:56:06 +05:30
|
|
|
'serverId' => uuid(),
|
2016-09-03 04:24:22 +05:30
|
|
|
]);
|
|
|
|
$I->seeResponseCodeIs(401);
|
|
|
|
$I->seeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'ForbiddenOperationException',
|
|
|
|
'errorMessage' => 'The token does not have required scope.',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function joinWithExpiredToken(FunctionalTester $I) {
|
|
|
|
$I->wantTo('join to some server with expired accessToken');
|
|
|
|
$this->route->join([
|
|
|
|
'accessToken' => '6042634a-a1e2-4aed-866c-c661fe4e63e2',
|
|
|
|
'selectedProfile' => 'df936908-b2e1-544d-96f8-2977ec213022',
|
2019-12-21 04:56:06 +05:30
|
|
|
'serverId' => uuid(),
|
2016-09-03 04:24:22 +05:30
|
|
|
]);
|
|
|
|
$I->seeResponseCodeIs(401);
|
|
|
|
$I->seeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'ForbiddenOperationException',
|
|
|
|
'errorMessage' => 'Expired access_token.',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function wrongArguments(FunctionalTester $I) {
|
|
|
|
$I->wantTo('get error on wrong amount of arguments');
|
|
|
|
$this->route->join([
|
|
|
|
'wrong' => 'argument',
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseCodeIs(400);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'IllegalArgumentException',
|
|
|
|
'errorMessage' => 'credentials can not be null.',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function joinWithWrongAccessToken(FunctionalTester $I) {
|
|
|
|
$I->wantTo('join to some server with wrong accessToken');
|
|
|
|
$this->route->join([
|
2019-12-21 04:56:06 +05:30
|
|
|
'accessToken' => uuid(),
|
2016-09-03 04:24:22 +05:30
|
|
|
'selectedProfile' => 'df936908-b2e1-544d-96f8-2977ec213022',
|
2019-12-21 04:56:06 +05:30
|
|
|
'serverId' => uuid(),
|
2016-09-03 04:24:22 +05:30
|
|
|
]);
|
|
|
|
$I->seeResponseCodeIs(401);
|
|
|
|
$I->seeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'ForbiddenOperationException',
|
|
|
|
'errorMessage' => 'Invalid access_token.',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2016-11-04 22:03:57 +05:30
|
|
|
public function joinWithNilUuids(FunctionalTester $I) {
|
|
|
|
$I->wantTo('join to some server with nil accessToken and selectedProfile');
|
|
|
|
$this->route->join([
|
|
|
|
'accessToken' => '00000000-0000-0000-0000-000000000000',
|
|
|
|
'selectedProfile' => 'df936908-b2e1-544d-96f8-2977ec213022',
|
2019-12-21 04:56:06 +05:30
|
|
|
'serverId' => uuid(),
|
2016-11-04 22:03:57 +05:30
|
|
|
]);
|
|
|
|
$I->canSeeResponseCodeIs(400);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'IllegalArgumentException',
|
|
|
|
'errorMessage' => 'credentials can not be null.',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-06-12 02:57:02 +05:30
|
|
|
public function joinByAccountMarkedForDeletion(FunctionalTester $I) {
|
|
|
|
$this->route->join([
|
|
|
|
'accessToken' => '239ba889-7020-4383-8d99-cd8c8aab4a2f',
|
|
|
|
'selectedProfile' => '6383de63-8f85-4ed5-92b7-5401a1fa68cd',
|
|
|
|
'serverId' => uuid(),
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseCodeIs(401);
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'ForbiddenOperationException',
|
|
|
|
'errorMessage' => 'Invalid credentials',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2023-11-17 00:51:26 +05:30
|
|
|
private function expectSuccessResponse(FunctionalTester $I): void {
|
|
|
|
$I->seeResponseCodeIs(204);
|
|
|
|
$I->canSeeResponseEquals('');
|
2016-09-03 04:24:22 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|