mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-12 15:53:46 -04:00
fix(upload): return 404 for a database the team cannot open
The backup upload returned a hard-coded 500 when the database uuid was unknown or belonged to another team. It now returns 404 with the same JSON error shape that the import form reads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6eeea653fe
commit
de75bbe004
@@ -0,0 +1,6 @@
|
||||
---
|
||||
type: fixed
|
||||
---
|
||||
Server error when a backup was uploaded in `Import Backup` for a database that the team cannot open
|
||||
|
||||
- The upload now answers with `Database not found`
|
||||
@@ -24,7 +24,7 @@ class UploadController extends BaseController
|
||||
$databaseIdentifier = request()->route('databaseUuid');
|
||||
$resource = getResourceByUuid($databaseIdentifier, data_get(auth()->user()->currentTeam(), 'id'));
|
||||
if (is_null($resource)) {
|
||||
return response()->json(['error' => 'You do not have permission for this database'], 500);
|
||||
return response()->json(['error' => 'Database not found.'], 404);
|
||||
}
|
||||
|
||||
$this->authorize('uploadBackup', $resource);
|
||||
|
||||
@@ -174,7 +174,12 @@ test('member gets 403 from POST /upload/backup and no file lands on disk', funct
|
||||
expect(File::exists($uploadDir.'/restore'))->toBeFalse();
|
||||
});
|
||||
|
||||
test('user from different team hits null-resource branch with 500', function () {
|
||||
test('user from different team gets 404 from POST /upload/backup and no file lands on disk', function () {
|
||||
$uploadDir = storage_path('app/upload/'.$this->database->uuid);
|
||||
if (File::exists($uploadDir)) {
|
||||
File::deleteDirectory($uploadDir);
|
||||
}
|
||||
|
||||
$otherTeam = Team::factory()->create();
|
||||
$otherUser = User::factory()->create();
|
||||
$otherUser->teams()->attach($otherTeam, ['role' => 'admin']);
|
||||
@@ -182,9 +187,31 @@ test('user from different team hits null-resource branch with 500', function ()
|
||||
$this->actingAs($otherUser);
|
||||
session(['currentTeam' => $otherTeam]);
|
||||
|
||||
$response = $this->post(route('upload.backup', ['databaseUuid' => $this->database->uuid]));
|
||||
$response = $this->withHeader('Accept', 'application/json')
|
||||
->post(route('upload.backup', ['databaseUuid' => $this->database->uuid]));
|
||||
|
||||
$response->assertStatus(500);
|
||||
$response->assertNotFound();
|
||||
$response->assertJsonMissing(['error' => 'You do not have permission for this database']);
|
||||
|
||||
expect(File::exists($uploadDir.'/restore'))->toBeFalse();
|
||||
});
|
||||
|
||||
test('unknown database uuid gets 404 from POST /upload/backup and no file lands on disk', function () {
|
||||
$unknownUuid = (string) Str::uuid();
|
||||
$uploadDir = storage_path('app/upload/'.$unknownUuid);
|
||||
if (File::exists($uploadDir)) {
|
||||
File::deleteDirectory($uploadDir);
|
||||
}
|
||||
|
||||
$this->actingAs($this->admin);
|
||||
session(['currentTeam' => $this->team]);
|
||||
|
||||
$response = $this->withHeader('Accept', 'application/json')
|
||||
->post(route('upload.backup', ['databaseUuid' => $unknownUuid]));
|
||||
|
||||
$response->assertNotFound();
|
||||
|
||||
expect(File::exists($uploadDir.'/restore'))->toBeFalse();
|
||||
});
|
||||
|
||||
test('unauthenticated request is redirected to login', function () {
|
||||
|
||||
Reference in New Issue
Block a user