2016-09-06 15:26:39 +05:30
|
|
|
<?php
|
2019-02-21 01:28:52 +05:30
|
|
|
namespace api\tests\functional\_steps;
|
2016-09-06 15:26:39 +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\FunctionalTester;
|
2019-12-21 04:56:06 +05:30
|
|
|
use function Ramsey\Uuid\v4 as uuid;
|
2016-09-06 15:26:39 +05:30
|
|
|
|
2017-09-19 22:36:16 +05:30
|
|
|
class SessionServerSteps extends FunctionalTester {
|
2016-09-06 15:26:39 +05:30
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function amJoined($byLegacy = false): array {
|
2016-09-06 15:26:39 +05:30
|
|
|
$oauthSteps = new OauthSteps($this->scenario);
|
2017-09-19 22:36:16 +05:30
|
|
|
$accessToken = $oauthSteps->getAccessToken([P::MINECRAFT_SERVER_SESSION]);
|
2016-09-06 15:26:39 +05:30
|
|
|
$route = new SessionServerRoute($this);
|
2019-12-21 04:56:06 +05:30
|
|
|
$serverId = uuid();
|
2016-09-06 15:26:39 +05:30
|
|
|
$username = 'Admin';
|
|
|
|
|
|
|
|
if ($byLegacy) {
|
|
|
|
$route->joinLegacy([
|
2024-12-02 15:40:55 +05:30
|
|
|
'sessionId' => 'token:' . $accessToken . ':df936908-b2e1-544d-96f8-2977ec213022',
|
2016-09-06 15:26:39 +05:30
|
|
|
'user' => $username,
|
|
|
|
'serverId' => $serverId,
|
|
|
|
]);
|
|
|
|
|
2023-11-17 14:50:32 +05:30
|
|
|
$this->seeResponseCodeIs(200);
|
2016-09-06 15:26:39 +05:30
|
|
|
$this->canSeeResponseEquals('OK');
|
|
|
|
} else {
|
|
|
|
$route->join([
|
|
|
|
'accessToken' => $accessToken,
|
|
|
|
'selectedProfile' => 'df936908-b2e1-544d-96f8-2977ec213022',
|
|
|
|
'serverId' => $serverId,
|
|
|
|
]);
|
|
|
|
|
2023-11-17 00:51:26 +05:30
|
|
|
$this->seeResponseCodeIs(204);
|
2023-11-17 14:50:32 +05:30
|
|
|
$this->canSeeResponseEquals('');
|
2016-09-06 15:26:39 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return [$username, $serverId];
|
|
|
|
}
|
2018-04-18 02:17:25 +05:30
|
|
|
|
2021-03-03 19:34:42 +05:30
|
|
|
public function canSeeValidTexturesResponse(
|
|
|
|
string $expectedUsername,
|
|
|
|
string $expectedUuid,
|
2024-12-02 15:40:55 +05:30
|
|
|
bool $shouldBeSigned = false,
|
|
|
|
): void {
|
2016-09-08 15:37:43 +05:30
|
|
|
$this->seeResponseIsJson();
|
|
|
|
$this->canSeeResponseContainsJson([
|
|
|
|
'name' => $expectedUsername,
|
|
|
|
'id' => $expectedUuid,
|
|
|
|
'properties' => [
|
|
|
|
[
|
|
|
|
'name' => 'textures',
|
2021-03-03 19:34:42 +05:30
|
|
|
],
|
|
|
|
[
|
|
|
|
'name' => 'ely',
|
|
|
|
'value' => 'but why are you asking?',
|
2016-09-08 15:37:43 +05:30
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
2021-03-03 19:34:42 +05:30
|
|
|
if ($shouldBeSigned) {
|
|
|
|
$this->canSeeResponseJsonMatchesJsonPath('$.properties[?(@.name == "textures")].signature');
|
|
|
|
} else {
|
|
|
|
$this->cantSeeResponseJsonMatchesJsonPath('$.properties[?(@.name == "textures")].signature');
|
|
|
|
}
|
|
|
|
|
2016-09-08 15:37:43 +05:30
|
|
|
$this->canSeeResponseJsonMatchesJsonPath('$.properties[0].value');
|
2019-05-13 22:09:11 +05:30
|
|
|
$value = $this->grabDataFromResponseByJsonPath('$.properties[0].value')[0];
|
2024-12-02 15:40:55 +05:30
|
|
|
$decoded = json_decode(base64_decode((string)$value), true);
|
2016-09-08 15:37:43 +05:30
|
|
|
$this->assertArrayHasKey('timestamp', $decoded);
|
|
|
|
$this->assertArrayHasKey('textures', $decoded);
|
2019-02-26 04:56:02 +05:30
|
|
|
$this->assertSame($expectedUuid, $decoded['profileId']);
|
|
|
|
$this->assertSame($expectedUsername, $decoded['profileName']);
|
2016-09-08 15:37:43 +05:30
|
|
|
$textures = $decoded['textures'];
|
|
|
|
$this->assertArrayHasKey('SKIN', $textures);
|
|
|
|
$skinTextures = $textures['SKIN'];
|
|
|
|
$this->assertArrayHasKey('url', $skinTextures);
|
|
|
|
}
|
2016-09-06 15:26:39 +05:30
|
|
|
|
|
|
|
}
|