2021-07-11 19:15:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Tests\Integration\Api\Client\Server\Backup;
|
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
use Mockery\MockInterface;
|
2021-07-11 19:15:39 +00:00
|
|
|
use Illuminate\Http\Response;
|
|
|
|
use Pterodactyl\Models\Backup;
|
|
|
|
use Pterodactyl\Models\Permission;
|
2022-05-29 21:07:54 +00:00
|
|
|
use Illuminate\Support\Facades\Event;
|
|
|
|
use Pterodactyl\Events\ActivityLogged;
|
2021-07-11 19:15:39 +00:00
|
|
|
use Pterodactyl\Repositories\Wings\DaemonBackupRepository;
|
|
|
|
use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
|
|
|
|
|
|
|
|
class DeleteBackupTest extends ClientApiIntegrationTestCase
|
|
|
|
{
|
2022-10-14 16:59:20 +00:00
|
|
|
private MockInterface $repository;
|
2021-07-11 19:15:39 +00:00
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->repository = $this->mock(DaemonBackupRepository::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUserWithoutPermissionCannotDeleteBackup()
|
|
|
|
{
|
|
|
|
[$user, $server] = $this->generateTestAccount([Permission::ACTION_BACKUP_CREATE]);
|
|
|
|
|
|
|
|
$backup = Backup::factory()->create(['server_id' => $server->id]);
|
|
|
|
|
|
|
|
$this->actingAs($user)->deleteJson($this->link($backup))
|
|
|
|
->assertStatus(Response::HTTP_FORBIDDEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that a backup can be deleted for a server and that it is properly updated
|
|
|
|
* in the database. Once deleted there should also be a corresponding record in the
|
2022-05-29 21:07:54 +00:00
|
|
|
* activity logs table for this API call.
|
2021-07-11 19:15:39 +00:00
|
|
|
*/
|
|
|
|
public function testBackupCanBeDeleted()
|
|
|
|
{
|
2022-05-29 21:07:54 +00:00
|
|
|
Event::fake([ActivityLogged::class]);
|
|
|
|
|
2021-07-11 19:15:39 +00:00
|
|
|
[$user, $server] = $this->generateTestAccount([Permission::ACTION_BACKUP_DELETE]);
|
|
|
|
|
|
|
|
/** @var \Pterodactyl\Models\Backup $backup */
|
|
|
|
$backup = Backup::factory()->create(['server_id' => $server->id]);
|
|
|
|
|
2022-05-29 21:07:54 +00:00
|
|
|
$this->repository->expects('setServer->delete')->with(
|
2023-02-23 19:30:16 +00:00
|
|
|
\Mockery::on(function ($value) use ($backup) {
|
2022-05-29 21:07:54 +00:00
|
|
|
return $value instanceof Backup && $value->uuid === $backup->uuid;
|
|
|
|
})
|
|
|
|
)->andReturn(new Response());
|
2021-07-11 19:15:39 +00:00
|
|
|
|
|
|
|
$this->actingAs($user)->deleteJson($this->link($backup))->assertStatus(Response::HTTP_NO_CONTENT);
|
|
|
|
|
|
|
|
$backup->refresh();
|
2022-05-29 21:07:54 +00:00
|
|
|
$this->assertSoftDeleted($backup);
|
2021-07-11 19:15:39 +00:00
|
|
|
|
2022-06-18 18:25:24 +00:00
|
|
|
$this->assertActivityFor('server:backup.delete', $user, [$backup, $backup->server]);
|
2021-07-11 19:15:39 +00:00
|
|
|
|
2022-05-29 21:07:54 +00:00
|
|
|
$this->actingAs($user)->deleteJson($this->link($backup))->assertStatus(Response::HTTP_NOT_FOUND);
|
2021-07-11 19:15:39 +00:00
|
|
|
}
|
|
|
|
}
|