Files
RenewCMS/features/image_upload_rules.feature
T

66 lines
3.4 KiB
Gherkin

Feature: Allowed image types and the size limit are a domain rule
As the maintainer of RenewCMS
I want the image content-type allow-list and the maximum upload size enforced by
CreateImageUseCase before it ever calls image.Repository.Create
So that persistence stops deciding what counts as a valid image, the rule lives in
internal/domain/image where it can be asserted with errors.Is, and no bytes are ever
written to UPLOAD_DIR or the database for a rejected upload
Background:
Given internal/domain/image defines the sentinel errors image.ErrImageTypeNotAllowed
and image.ErrImageTooLarge
And internal/domain/image defines the allowed content types image/png, image/jpeg,
image/webp and image/svg+xml, and a maximum size of 10485760 bytes (10 MiB)
And CreateImageUseCase.CreateImage checks input.ContentType against the allowed list
and input.Size against the maximum before calling imageRepository.Create, returning
the matching sentinel and calling the repository not at all when either check fails
And ImageRepository.Create no longer rejects an unrecognized content type itself; it
only maps an already-allowed content type to a file extension
And no image HTTP endpoint is mounted in api/router.go as of this slice, so this
behavior is observable only through CreateImageUseCase
Scenario Outline: CreateImage accepts every allowed content type within the size limit
Given an empty image repository fake
When CreateImage is called with content type <content_type> and a size of
10485760 bytes
Then the image repository's Create is called once
And the result is the created image, with no error
Examples:
| content_type |
| image/png |
| image/jpeg |
| image/webp |
| image/svg+xml |
Scenario: CreateImage rejects a disallowed content type before reaching the repository
Given an empty image repository fake
When CreateImage is called with content type "application/pdf" and a size of 1024 bytes
Then the result is image.ErrImageTypeNotAllowed, asserted with errors.Is
And the image repository's Create is never called
Scenario: CreateImage rejects a file that exceeds the size limit
Given an empty image repository fake
When CreateImage is called with content type "image/png" and a size of
10485761 bytes
Then the result is image.ErrImageTooLarge, asserted with errors.Is
And the image repository's Create is never called
Scenario: A file exactly at the size limit is accepted, one byte over is not
Given an empty image repository fake
When CreateImage is called with content type "image/png" and a size of
10485760 bytes
Then the image repository's Create is called once with no error
When CreateImage is called again with content type "image/png" and a size of
10485761 bytes
Then the result is image.ErrImageTooLarge, asserted with errors.Is
And the image repository's Create is still called exactly once in total
Scenario: A repository failure unrelated to type or size still propagates unchanged
Given an image repository fake configured to fail its next Create call with a
generic repository error
When CreateImage is called with content type "image/png" and a size of 1024 bytes
Then the image repository's Create is called once
And the result is that generic error, unchanged