Skip to content

fix(ocdav): return 400 with a body when a TUS upload creation has an invalid name#655

Open
michaelstingl wants to merge 1 commit into
opencloud-eu:mainfrom
michaelstingl:fix/2803-tus-invalid-name-status
Open

fix(ocdav): return 400 with a body when a TUS upload creation has an invalid name#655
michaelstingl wants to merge 1 commit into
opencloud-eu:mainfrom
michaelstingl:fix/2803-tus-invalid-name-status

Conversation

@michaelstingl

@michaelstingl michaelstingl commented Jun 1, 2026

Copy link
Copy Markdown

Description

Align the TUS upload-creation handler (tus.go) with the other write handlers: on a name-validation failure, return 400 Bad Request with the reason in the body instead of a bare 412.

Warning

This changes a status the OpenCloud acceptance suite pins, so it needs a matching update to the OpenCloud acceptance tests; until then api-integration fails. The scenario coreApiWebdavUploadTUS/uploadFile.feature "upload a file with invalid-name" asserts 412; moving it to 400 is the only change needed there, since its other checks (no Location, file not created) stay valid. The same applies to the missing-length scenario in lowLevelCreationExtension.feature if that branch is aligned too.

Related Issue

Motivation and Context

With a bare 412 and no body, clients cannot show the user why an upload was rejected. The linked issue has the details.

How Has This Been Tested?

  • go build, go vet, go test -race of the ocdav package, and the pinned golangci-lint v2.10.1 (GOOS=linux GOARCH=amd64): all pass, 0 lint issues
  • unit: a new whitebox ginkgo spec drives handleTusPost with a backslash filename and asserts 400 plus the reason in the body; red on the unpatched handler (412), green with the fix
  • over HTTP on a local revad stack, patched vs unpatched: the create returns 412 with an empty body unpatched and 400 with name validation failed: must not contain \ patched, while a clean name returns 201 in both

Screenshots (if appropriate):

n/a. Server-side status and response-body change.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added (the existing coreApiWebdavUploadTUS/uploadFile.feature scenario pins the old 412 and needs a matching update in OpenCloud to move it to 400)
  • Documentation added (n/a — reva generates the changelog from the PR title + Type:* label via ready-release-go; no fragment needed)

🤖 drafted with Claude Code, reviewed before submitting.

…invalid name

The TUS upload creation handler rejected a name that failed validation with a
bare 412 Precondition Failed and no body, while PUT, MOVE, COPY and MKCOL return
400 Bad Request with the validation error marshalled into the body. Clients
could not tell the user why the upload was rejected, and 412 reads as a header
precondition rather than an invalid name. Return 400 with the error body, the
same way the sibling write handlers do.

Fixes: opencloud-eu#654
@rhafer

rhafer commented Jun 3, 2026

Copy link
Copy Markdown
Member

created opencloud-eu/opencloud#2889 for having a look at the tests ...

rhafer pushed a commit to rhafer/opencloud that referenced this pull request Jun 3, 2026
opencloud-eu/reva#655 changes the TUS create response for an invalid name
from 412 to 400. Update the invalid-name scenario to match.

Each example now carries its own expected status in an <http-status-code>
column. Names that fail ValidateName expect 400. The three folder/file rows
stay 412: filename() applies path.Base first, so "folder/file" becomes the
valid leaf "file" and never reaches the changed branch.

lowLevelCreationExtension.feature is unchanged; its missing-Upload-Length
case still returns 412.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

bug(ocdav): TUS create returns a bare 412 on an invalid name; PUT/MOVE/COPY/MKCOL return 400 with a message

2 participants