Beautiful Open-Source Form Builder
Fix exported signed file URLs (#1098)
Julien Nahum052b7447f2fc
diff --git a/api/app/Service/Forms/FormSubmissionFormatter.php b/api/app/Service/Forms/FormSubmissionFormatter.phpindex e7ae6a819..999c1271c 100644--- a/api/app/Service/Forms/FormSubmissionFormatter.php+++ b/api/app/Service/Forms/FormSubmissionFormatter.php@@ -348,8 +348,9 @@ class FormSubmissionFormatter// See: https://github.com/OpnForm/OpnForm/issues/1024$encodedFilename = FilenameUrlEncoder::encode($file);- return $this->useSignedUrlForFiles ? URL::signedRoute(+ return $this->useSignedUrlForFiles ? URL::temporarySignedRoute('open.forms.submissions.file',+ now()->addMinutes(config('vapor.signed_storage_url_expires_after', 5)),[$formId, $encodedFilename]) : route('open.forms.submissions.file', [$formId, $encodedFilename]);} catch (\Exception $e) {diff --git a/api/tests/Feature/Forms/FormSubmissionExportTest.php b/api/tests/Feature/Forms/FormSubmissionExportTest.phpindex 1f50bc8aa..d3b90c540 100644--- a/api/tests/Feature/Forms/FormSubmissionExportTest.php+++ b/api/tests/Feature/Forms/FormSubmissionExportTest.php@@ -2,6 +2,8 @@use App\Models\User;use App\Models\Forms\FormSubmission;+use App\Service\Storage\FileUploadPathService;+use Illuminate\Support\Facades\Storage;function parseCsvRows(string $content): array{@@ -320,3 +322,53 @@ it('does not include status column when partial submissions are disabled', funct$content = ob_get_clean();expect(str_contains($content, 'status'))->toBeFalse();});++it('exports file urls with expiration and a valid signature', function () {+ $user = $this->actingAsProUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace, [+ 'properties' => [+ [+ 'id' => 'file_field',+ 'name' => 'Upload',+ 'type' => 'files',+ 'required' => false,+ ],+ ],+ ]);++ Storage::fake();+ $fileName = 'test-signature.png';+ Storage::put(FileUploadPathService::getFileUploadPath($form->id, $fileName), 'signed file content');++ $form->submissions()->create([+ 'form_id' => $form->id,+ 'data' => [+ 'file_field' => [$fileName],+ ],+ 'status' => FormSubmission::STATUS_COMPLETED,+ ]);++ $response = $this->postJson(route('open.forms.submissions.export', [+ 'form' => $form,+ ]), [+ 'columns' => [+ 'file_field' => true,+ ],+ ]);++ $response->assertSuccessful();++ ob_start();+ $response->sendContent();+ $content = ob_get_clean();+ $rows = parseCsvRows($content);+ $fileColumnIndex = array_search('Upload', $rows[0], true);+ $exportedFileUrl = $rows[1][$fileColumnIndex];++ parse_str(parse_url($exportedFileUrl, PHP_URL_QUERY), $queryParameters);++ expect($queryParameters)->toHaveKeys(['expires', 'signature']);++ $this->get($exportedFileUrl)->assertOk();+});