mirror of
https://github.com/elyby/accounts.git
synced 2024-12-23 13:50:06 +05:30
Fixes #27. Serialize empty textures as an object
This commit is contained in:
parent
26b2168ae3
commit
b113beb78e
@ -36,6 +36,10 @@ return [
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function profile(string $username, bool $signed = false): ?array {
|
public function profile(string $username, bool $signed = false): ?array {
|
||||||
|
if ($username === 'NotSynchronized') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
$account = common\models\Account::findOne(['username' => $username]);
|
$account = common\models\Account::findOne(['username' => $username]);
|
||||||
$uuid = $account ? str_replace('-', '', $account->uuid) : '00000000000000000000000000000000';
|
$uuid = $account ? str_replace('-', '', $account->uuid) : '00000000000000000000000000000000';
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace api\tests\functional\sessionserver;
|
namespace api\tests\functional\sessionserver;
|
||||||
|
|
||||||
use api\tests\_pages\SessionServerRoute;
|
use api\tests\_pages\SessionServerRoute;
|
||||||
@ -34,6 +36,20 @@ class ProfileCest {
|
|||||||
$I->canSeeValidTexturesResponse('Admin', 'df936908b2e1544d96f82977ec213022', true);
|
$I->canSeeValidTexturesResponse('Admin', 'df936908b2e1544d96f82977ec213022', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getProfileWhichIsNotSynchronized(SessionServerSteps $I) {
|
||||||
|
$I->wantTo('get info about player textures by uuid');
|
||||||
|
$this->route->profile('7ff4a9dcd1774ea0ab567f31218004f9', true);
|
||||||
|
|
||||||
|
// Ensure that empty textures was serialized as an empty object
|
||||||
|
$I->seeResponseIsJson();
|
||||||
|
$I->canSeeResponseContainsJson([
|
||||||
|
'id' => '7ff4a9dcd1774ea0ab567f31218004f9',
|
||||||
|
]);
|
||||||
|
$texturesValue = $I->grabDataFromResponseByJsonPath('$.properties[0].value')[0];
|
||||||
|
$texturesJson = base64_decode($texturesValue);
|
||||||
|
$I->assertStringContainsString('"textures":{}', $texturesJson);
|
||||||
|
}
|
||||||
|
|
||||||
public function directCallWithoutUuidPart(FunctionalTester $I) {
|
public function directCallWithoutUuidPart(FunctionalTester $I) {
|
||||||
$I->wantTo('call profile route without passing uuid');
|
$I->wantTo('call profile route without passing uuid');
|
||||||
$this->route->profile('');
|
$this->route->profile('');
|
||||||
|
@ -3,6 +3,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace common\models;
|
namespace common\models;
|
||||||
|
|
||||||
|
use ArrayObject;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use common\components\SkinsSystemApi;
|
use common\components\SkinsSystemApi;
|
||||||
use GuzzleHttp\Client as GuzzleHttpClient;
|
use GuzzleHttp\Client as GuzzleHttpClient;
|
||||||
@ -22,7 +23,7 @@ class Textures {
|
|||||||
$profile = $this->getProfile($signed);
|
$profile = $this->getProfile($signed);
|
||||||
if ($profile === null) {
|
if ($profile === null) {
|
||||||
// This case shouldn't happen at all, but synchronization isn't perfect and sometimes
|
// This case shouldn't happen at all, but synchronization isn't perfect and sometimes
|
||||||
// information might be now updated. Provide fallback solution
|
// information might be not updated. Provide fallback solution
|
||||||
$profile = [
|
$profile = [
|
||||||
'name' => $this->account->username,
|
'name' => $this->account->username,
|
||||||
'id' => $uuid,
|
'id' => $uuid,
|
||||||
@ -33,7 +34,7 @@ class Textures {
|
|||||||
'timestamp' => Carbon::now()->getPreciseTimestamp(3),
|
'timestamp' => Carbon::now()->getPreciseTimestamp(3),
|
||||||
'profileId' => $uuid,
|
'profileId' => $uuid,
|
||||||
'profileName' => $this->account->username,
|
'profileName' => $this->account->username,
|
||||||
'textures' => [],
|
'textures' => new ArrayObject(), // Force {} rather than [] when json_encode
|
||||||
])),
|
])),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
17
common/tests/fixtures/data/accounts.php
vendored
17
common/tests/fixtures/data/accounts.php
vendored
@ -233,4 +233,21 @@ return [
|
|||||||
'password_changed_at' => 1591893532,
|
'password_changed_at' => 1591893532,
|
||||||
'deleted_at' => time(),
|
'deleted_at' => time(),
|
||||||
],
|
],
|
||||||
|
'not-synchronized-on-chrly-account' => [
|
||||||
|
'id' => 16,
|
||||||
|
'uuid' => '7ff4a9dc-d177-4ea0-ab56-7f31218004f9',
|
||||||
|
'username' => 'NotSynchronized',
|
||||||
|
'email' => 'not-synchronized@ely.by',
|
||||||
|
'password_hash' => '$2y$13$2rYkap5T6jG8z/mMK8a3Ou6aZxJcmAaTha6FEuujvHEmybSHRzW5e', # password_0
|
||||||
|
'password_hash_strategy' => \common\models\Account::PASS_HASH_STRATEGY_YII2,
|
||||||
|
'lang' => 'ru',
|
||||||
|
'status' => \common\models\Account::STATUS_ACTIVE,
|
||||||
|
'rules_agreement_version' => \common\LATEST_RULES_VERSION,
|
||||||
|
'otp_secret' => null,
|
||||||
|
'is_otp_enabled' => false,
|
||||||
|
'created_at' => 1670264178,
|
||||||
|
'updated_at' => 1670264178,
|
||||||
|
'password_changed_at' => 1670264178,
|
||||||
|
'deleted_at' => null,
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
Loading…
Reference in New Issue
Block a user