Set content-disposition 'attachment' for both local and S3 downloads. Added a bunch of tests. Fixes #1148.

This commit is contained in:
Andrew Herron
2026-07-30 17:21:51 +10:00
committed by Gregor Vostrak
parent ed3ba0135b
commit 453d5ed066
7 changed files with 287 additions and 3 deletions

View File

@@ -90,4 +90,35 @@ class ExportEndpointTest extends ApiEndpointTestAbstract
$response->assertJsonPath('success', true);
$this->assertStringContainsString($filepath, $response->json('download_url'));
}
public function test_export_requests_the_download_url_as_an_attachment(): void
{
// Arrange
$user = $this->createUserWithPermission([
'export',
]);
$filepath = 'exports/export_test.zip';
$this->mock(ExportService::class, function (MockInterface $mock) use (&$user, $filepath): void {
$mock->shouldReceive('export')
->withArgs(function (Organization $organization) use (&$user): bool {
return $organization->is($user->organization);
})
->andReturn($filepath)
->once();
});
Passport::actingAs($user->user);
$capturedOptions = $this->captureTemporaryUrlOptions();
// Act
$response = $this->postJson(route('api.v1.export.export', [
'organization' => $user->organization->getKey(),
]));
// Assert
$response->assertStatus(200);
$options = $capturedOptions();
$this->assertIsArray($options);
$this->assertSame('attachment; filename="export_test.zip"', $options['ResponseContentDisposition'] ?? null);
$this->assertSame('https://storage.fake/'.$filepath, $response->json('download_url'));
}
}