Fix some failing test cases

This commit is contained in:
Dane Everitt 2020-11-06 22:33:39 -08:00
parent 625fd92130
commit f99ac0ecde
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 12 additions and 4 deletions

View file

@ -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]);

View file

@ -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();
}
}

View file

@ -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'));