mirror of
https://github.com/pterodactyl/panel.git
synced 2026-06-13 08:10:52 -05:00
This expands upon previous work done to better disconnect users from SFTP when different events occur within Pterodactyl. This new logic also accounts for password changes and their account being deleted entirely from the system. These events now trigger background jobs that will reach out to every node they are associated with to ensure they're disconnected if currently connected.
65 lines
1.9 KiB
PHP
65 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Pterodactyl\Tests\Integration\Services\Users;
|
|
|
|
use Pterodactyl\Models\User;
|
|
use Pterodactyl\Models\Subuser;
|
|
use Illuminate\Support\Facades\Bus;
|
|
use Pterodactyl\Jobs\RevokeSftpAccessJob;
|
|
use Pterodactyl\Exceptions\DisplayException;
|
|
use Pterodactyl\Services\Users\UserDeletionService;
|
|
use Pterodactyl\Tests\Integration\IntegrationTestCase;
|
|
|
|
class UserDeletionServiceTest extends IntegrationTestCase
|
|
{
|
|
public function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
Bus::fake([RevokeSftpAccessJob::class]);
|
|
}
|
|
|
|
public function testExceptionReturnedIfUserAssignedToServers(): void
|
|
{
|
|
$server = $this->createServerModel();
|
|
|
|
$this->expectException(DisplayException::class);
|
|
$this->expectExceptionMessage(__('admin/user.exceptions.user_has_servers'));
|
|
|
|
$this->app->make(UserDeletionService::class)->handle($server->user);
|
|
|
|
$this->assertModelExists($server->user);
|
|
|
|
Bus::assertNotDispatched(RevokeSftpAccessJob::class);
|
|
}
|
|
|
|
public function testUserIsDeleted(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$this->app->make(UserDeletionService::class)->handle($user);
|
|
|
|
$this->assertModelMissing($user);
|
|
|
|
Bus::assertNotDispatched(RevokeSftpAccessJob::class);
|
|
}
|
|
|
|
public function testUserIsDeletedAndAccessRevoked(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$server1 = $this->createServerModel();
|
|
$server2 = $this->createServerModel(['node_id' => $server1->node_id]);
|
|
|
|
Subuser::factory()->for($server1)->for($user)->create();
|
|
Subuser::factory()->for($server2)->for($user)->create();
|
|
|
|
$this->app->make(UserDeletionService::class)->handle($user);
|
|
|
|
$this->assertModelMissing($user);
|
|
|
|
Bus::assertDispatchedTimes(RevokeSftpAccessJob::class);
|
|
Bus::assertDispatched(fn (RevokeSftpAccessJob $job) => $job->user === $user->uuid && $job->target->is($server1->node));
|
|
}
|
|
}
|