From f99ac0ecdec86184c39c5f124f7a3659dc61375e Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 6 Nov 2020 22:33:39 -0800 Subject: [PATCH] Fix some failing test cases --- .../Api/Client/Servers/SubuserController.php | 2 +- .../Api/Client/Server/Subuser/DeleteSubuserTest.php | 12 ++++++++++-- .../Api/Client/Server/WebsocketControllerTest.php | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Api/Client/Servers/SubuserController.php b/app/Http/Controllers/Api/Client/Servers/SubuserController.php index f51503d0f..d2806a653 100644 --- a/app/Http/Controllers/Api/Client/Servers/SubuserController.php +++ b/app/Http/Controllers/Api/Client/Servers/SubuserController.php @@ -163,7 +163,7 @@ class SubuserController extends ClientApiController $this->repository->delete($subuser->id); try { - $this->serverRepository->revokeJTIs([md5($subuser->user_id . $server->uuid)]); + $this->serverRepository->setServer($server)->revokeJTIs([md5($subuser->user_id . $server->uuid)]); } catch (DaemonConnectionException $exception) { // Don't block this request if we can't connect to the Wings instance. Log::warning($exception, ['user_id' => $subuser->user_id, 'server_id' => $server->id]); diff --git a/tests/Integration/Api/Client/Server/Subuser/DeleteSubuserTest.php b/tests/Integration/Api/Client/Server/Subuser/DeleteSubuserTest.php index 3118baa24..144db42d4 100644 --- a/tests/Integration/Api/Client/Server/Subuser/DeleteSubuserTest.php +++ b/tests/Integration/Api/Client/Server/Subuser/DeleteSubuserTest.php @@ -2,10 +2,12 @@ namespace Pterodactyl\Tests\Integration\Api\Client\Server\Subuser; +use Mockery; use Ramsey\Uuid\Uuid; use Pterodactyl\Models\User; use Pterodactyl\Models\Subuser; use Pterodactyl\Models\Permission; +use Pterodactyl\Repositories\Wings\DaemonServerRepository; use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase; class DeleteSubuserTest extends ClientApiIntegrationTestCase @@ -23,6 +25,8 @@ class DeleteSubuserTest extends ClientApiIntegrationTestCase */ public function testCorrectSubuserIsDeletedFromServer() { + $this->swap(DaemonServerRepository::class, $mock = Mockery::mock(DaemonServerRepository::class)); + [$user, $server] = $this->generateTestAccount(); /** @var \Pterodactyl\Models\User $differentUser */ @@ -37,9 +41,11 @@ class DeleteSubuserTest extends ClientApiIntegrationTestCase Subuser::query()->forceCreate([ 'user_id' => $subuser->id, 'server_id' => $server->id, - 'permissions' => [ Permission::ACTION_WEBSOCKET_CONNECT ], + 'permissions' => [Permission::ACTION_WEBSOCKET_CONNECT], ]); + $mock->expects('setServer->revokeJTIs')->with([md5($subuser->id . $server->uuid)])->andReturnUndefined(); + $this->actingAs($user)->deleteJson($this->link($server) . "/users/{$subuser->uuid}")->assertNoContent(); // Try the same test, but this time with a UUID that if cast to an int (shouldn't) line up with @@ -51,9 +57,11 @@ class DeleteSubuserTest extends ClientApiIntegrationTestCase Subuser::query()->forceCreate([ 'user_id' => $subuser->id, 'server_id' => $server->id, - 'permissions' => [ Permission::ACTION_WEBSOCKET_CONNECT ], + 'permissions' => [Permission::ACTION_WEBSOCKET_CONNECT], ]); + $mock->expects('setServer->revokeJTIs')->with([md5($subuser->id . $server->uuid)])->andReturnUndefined(); + $this->actingAs($user)->deleteJson($this->link($server) . "/users/{$subuser->uuid}")->assertNoContent(); } } diff --git a/tests/Integration/Api/Client/Server/WebsocketControllerTest.php b/tests/Integration/Api/Client/Server/WebsocketControllerTest.php index 0d8851d3a..734dfcf2f 100644 --- a/tests/Integration/Api/Client/Server/WebsocketControllerTest.php +++ b/tests/Integration/Api/Client/Server/WebsocketControllerTest.php @@ -63,7 +63,7 @@ class WebsocketControllerTest extends ClientApiIntegrationTestCase $this->assertSame($server->node->getConnectionAddress(), $token->getClaim('aud')); $this->assertSame(CarbonImmutable::now()->getTimestamp(), $token->getClaim('iat')); $this->assertSame(CarbonImmutable::now()->subMinutes(5)->getTimestamp(), $token->getClaim('nbf')); - $this->assertSame(CarbonImmutable::now()->addMinutes(15)->getTimestamp(), $token->getClaim('exp')); + $this->assertSame(CarbonImmutable::now()->addMinutes(10)->getTimestamp(), $token->getClaim('exp')); $this->assertSame($user->id, $token->getClaim('user_id')); $this->assertSame($server->uuid, $token->getClaim('server_uuid')); $this->assertSame(['*'], $token->getClaim('permissions'));