From c64f386365476478332aaa1f7a9275a658d60cbc Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Fri, 18 Dec 2020 11:12:34 +0100 Subject: [PATCH] Fix incorrect response in case when user's profile for provided UUID can't be found --- .../session/controllers/SessionController.php | 8 ++++---- .../functional/sessionserver/ProfileCest.php | 18 ++++-------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/api/modules/session/controllers/SessionController.php b/api/modules/session/controllers/SessionController.php index 54abede..fb1fc6c 100644 --- a/api/modules/session/controllers/SessionController.php +++ b/api/modules/session/controllers/SessionController.php @@ -110,11 +110,10 @@ class SessionController extends Controller { /** * @param string $uuid * - * @return array - * @throws ForbiddenOperationException + * @return array|null * @throws IllegalArgumentException */ - public function actionProfile(string $uuid): array { + public function actionProfile(string $uuid): ?array { try { $uuid = Uuid::fromString($uuid)->toString(); } catch (\InvalidArgumentException $e) { @@ -124,7 +123,8 @@ class SessionController extends Controller { /** @var Account|null $account */ $account = Account::find()->excludeDeleted()->andWhere(['uuid' => $uuid])->one(); if ($account === null) { - throw new ForbiddenOperationException('Invalid uuid.'); + Yii::$app->response->setStatusCode(204); + return null; } return (new Textures($account))->getMinecraftResponse(); diff --git a/api/tests/functional/sessionserver/ProfileCest.php b/api/tests/functional/sessionserver/ProfileCest.php index f152304..74cda66 100644 --- a/api/tests/functional/sessionserver/ProfileCest.php +++ b/api/tests/functional/sessionserver/ProfileCest.php @@ -49,24 +49,14 @@ class ProfileCest { public function getProfileWithNonexistentUuid(FunctionalTester $I) { $I->wantTo('get info about nonexistent uuid'); $this->route->profile(v4()); - $I->canSeeResponseCodeIs(401); - $I->canSeeResponseIsJson(); - $I->seeResponseIsJson(); - $I->canSeeResponseContainsJson([ - 'error' => 'ForbiddenOperationException', - 'errorMessage' => 'Invalid uuid.', - ]); + $I->canSeeResponseCodeIs(204); + $I->canSeeResponseEquals(''); } public function getProfileOfAccountMarkedForDeletion(FunctionalTester $I) { $this->route->profile('6383de63-8f85-4ed5-92b7-5401a1fa68cd'); - $I->canSeeResponseCodeIs(401); - $I->canSeeResponseIsJson(); - $I->seeResponseIsJson(); - $I->canSeeResponseContainsJson([ - 'error' => 'ForbiddenOperationException', - 'errorMessage' => 'Invalid uuid.', - ]); + $I->canSeeResponseCodeIs(204); + $I->canSeeResponseEquals(''); } }