Skip to content

fix: extension de arquivo non persiste ao subir - #35

Merged
AsierCL merged 1 commit into
Gradox2:mainfrom
manu-pc:fix/issue-fileextension
Nov 2, 2026
Merged

AsierCL merged 1 commit into
Gradox2:mainfrom
manu-pc:fix/issue-fileextension

Conversation

@manu-pc

@manu-pc manu-pc commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

engade unha columna varchar(255) original_filename a files e a temp_files, con script de migración V9__file_original_filename.sql

FileServiceImpl.downloadFile e FileProposalServiceImpl.getFileDownloadLink crean Content-Disposition empregando o campo de original_filename para manter o nome de arquivo co que subiu o usuario contribuidor (e polo tanto preserva a terminación de arquivo)

@AsierCL
AsierCL merged commit ff6bce6 into Gradox2:main Nov 2, 2026
1 check passed
AsierCL added a commit that referenced this pull request Nov 5, 2026
* test: share one FK-ordered database cleaner across integration tests

The test profile shares a single in-memory H2 across test classes, so every
class has to clean up after the previous one. AuthRateLimitIntegrationTest only
deleted users, which broke as soon as GovernanceRulesIntegrationTest ran right
before it in CI (file_proposal FK). GlobalJourneyIntegrationTest had the full
ordered list; AuthRateLimit got a copy. Two lists drift.

Move the order into TestDatabaseCleaner and use it from all three classes.

Verified: 129/129 in default order and with -Dsurefire.runOrder=reversealphabetical;
GovernanceRulesIntegrationTest -> AuthRateLimitIntegrationTest passes.

* fix(upload): sanitize the client filename before persisting it

The original filename comes from the client and is stored in
original_filename varchar(255); it also travels in the Content-Disposition of
the download URL. Two cases broke:

- a name longer than the column made the upload fail with 409
  DATA_INTEGRITY_ERROR (found while verifying #35);
- a name with path components ('../../etc/notas.pdf') was stored as-is.

FileNames.sanitize keeps the last path segment, drops control characters and
truncates to 255 characters preserving the extension. It is applied on upload
and again when building the Content-Disposition, so rows stored before this
change are also safe.

Tests (new OriginalFilenameIntegrationTest) assert the visible effect: the
filename declared in the signed download URL.

Verified RED first: long name -> 409, path kept. GREEN after the change.

* refactor(dev): check the environment guard before stripping quotes

The loader checked whether the key was already defined after doing the
quote-stripping work. Checking right after validating the key is equivalent and
skips work that was thrown away.

* docs: record the new filename tests and the shared test cleaner

- 126 -> 129 tests, 17 -> 18 suite classes.
- OriginalFilenameIntegrationTest documented (long name, path components,
  normal name) and what it actually asserts.
- The migration negative case is a manual probe, not an automated test.
- TestDatabaseCleaner is the single place for the FK-safe cleanup order.

* docs: keep the suite sections in numeric order

Section 18 was inserted before 17, and the previous fix attempt moved it past
the coverage summary. 15..18 now run in order and the summary stays last.
Found by the review of this same PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants