Files
upstream-seaweedfs/weed/server/filer_server_tus_concat_test.go
upstream-mirror 89f5be005d
Some checks failed
go: build dev binaries / cleanup (push) Successful in 4s
Codespell / Check for spelling errors (push) Failing after 3s
docker: build dev containers / build-rust-binaries (amd64, x86_64-unknown-linux-musl) (push) Failing after 3s
docker: build dev containers / build-dev-containers (push) Has been skipped
docker: build dev containers / build-rust-binaries (arm64, true, aarch64-unknown-linux-musl) (push) Failing after 3s
End to End / FUSE Mount (push) Failing after 2s
EC Integration Tests / EC Integration Tests (push) Failing after 30s
FUSE DLM Integration Tests / FUSE DLM Integration Tests (push) Failing after 3s
FUSE Volume Server Failover Tests / FUSE Volume Server Failover (push) Failing after 3s
FUSE Integration Tests / FUSE Integration Testing (push) Failing after 2s
FUSE P2P Peer Chunk Sharing Integration Tests / FUSE P2P Peer Chunk Sharing (push) Failing after 3s
go: build binary / Go Vet (push) Failing after 2s
go: build binary / Go Vet 32-bit (push) Failing after 3s
go: build binary / Build (push) Failing after 4s
go: build binary / Build cross-platform (freebsd/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (darwin/arm64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/arm64) (push) Failing after 3s
go: build binary / Test (push) Failing after 2s
go: build binary / Test 32-bit (push) Failing after 3s
helm: lint and test charts / lint-test (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (11) (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (17) (push) Failing after 3s
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Failing after 2s
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Failing after 3s
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Has been skipped
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Has been skipped
Java Client Unit Tests / Java Unit Tests (11) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (17) (push) Failing after 2s
Java Client Unit Tests / Java Unit Tests (21) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (8) (push) Failing after 3s
Kafka Quick Test (Load Test with Schema Registry) / Kafka Client Load Test (Quick) (push) Failing after 3s
Kafka Gateway Tests / Kafka Unit Tests (unit-tests-1) (push) Failing after 11s
Kafka Gateway Tests / Kafka Integration Tests (Critical) (integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka End-to-End Tests (with SMQ) (e2e-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Consumer Group Tests (Highly Isolated) (consumer-group-1) (push) Failing after 2s
Kafka Gateway Tests / Kafka Client Compatibility (with SMQ) (client-compat-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka SMQ Integration Tests (Full Stack) (smq-integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Protocol Tests (Isolated) (protocol-1) (push) Failing after 3s
KMS Tests / KMS Provider Integration Tests (push) Failing after 2s
KMS Tests / S3 KMS End-to-End Tests (push) Failing after 3s
Master Cold Start Tests / Master Cold Start Tests (push) Failing after 4s
Metadata Subscribe Integration Tests / Metadata Subscribe Integration Tests (push) Failing after 3s
Multi-Master Tests / Multi-Master Failover Tests (push) Failing after 3s
Performance / CPU and Heap Profile (push) Failing after 2s
Performance / S3 Read/Write Benchmark (rust volume) (push) Failing after 3s
pjdfstest POSIX Compliance / pjdfstest (push) Failing after 2s
Plugin Worker Integration Tests / Plugin Worker: erasure_coding (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: vacuum (push) Failing after 3s
Rust Volume Server Tests / Rust Integration Tests (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 1) (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 1) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 3) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Distributed Tests (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Performance Tests (push) Failing after 3s
Performance / Throughput Benchmark (go volume) (push) Failing after 3s
Performance / Throughput Benchmark (rust volume) (push) Failing after 2s
Performance / S3 Read/Write Benchmark (go volume) (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: volume_balance (push) Failing after 3s
PostgreSQL Gateway Tests / PostgreSQL Basic Tests (push) Failing after 3s
Rust Volume Server Tests / Rust Unit Tests (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 3) (push) Failing after 3s
Rust Plugin Worker Tests / Rust Plugin Worker Build and Unit Tests (push) Failing after 3s
rust: build dev volume server binaries / cleanup (push) Successful in 3s
S3 ETag and ACL Tests / S3 ETag + ACL Integration Tests (push) Failing after 3s
S3 IAM Integration Tests / IAM Unit Tests (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (advanced) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (basic) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (group) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (policy-enforcement) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (sts) (push) Failing after 4s
S3 Keycloak Integration Tests / S3 Keycloak Integration Tests (push) Failing after 3s
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.11) (push) Failing after 3s
S3 PyArrow Parquet Tests / Go Unit Tests (Implicit Directory) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.12) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-amd64, x86_64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-arm64, aarch64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-linux (linux-amd64, x86_64-unknown-linux-gnu) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.9) (push) Has been cancelled
S3 Proxy Signature Tests / S3 Proxy Signature Verification Tests (push) Has been cancelled
S3 SDK V2 Route Disambiguation Tests / S3 SDK V2 Routing Tests (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (quick) (push) Has been cancelled
S3 SSE Tests / S3 SSE Compatibility Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Metadata Persistence Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Copy Operations Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Multipart Upload Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Performance Test (push) Has been cancelled
S3 SSE Tests / S3 Volume Encryption Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (comprehensive) (push) Has been cancelled
Spark Integration Tests / Spark Integration Tests (push) Failing after 2s
Telemetry Integration Tests / telemetry-integration-test (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 1) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 1) (push) Failing after 3s
Ceph S3 tests / Basic S3 tests (KV store) (push) Has been cancelled
Ceph S3 tests / S3 Versioning & Object Lock tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Unit Tests (push) Failing after 3s
Ceph S3 tests / S3 CORS tests (push) Has been cancelled
Ceph S3 tests / SeaweedFS Custom S3 Copy tests (push) Has been cancelled
Ceph S3 tests / Basic S3 tests (SQL store) (push) Has been cancelled
test s3 over https using aws-cli / awscli-tests (push) Has been cancelled
TLS Rotation Integration Tests / TLS Rotation Integration Tests (push) Has been cancelled
Vacuum Integration Tests / Vacuum Integration Tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Variables Integration Tests (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (advanced-policy) (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (basic-policy) (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (contextual-policy) (push) Failing after 4s
S3 Policy Integration Tests / Trusted Proxy Detection Tests (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Shell Integration Tests (push) Failing after 3s
Samba on FUSE Integration / samba-integration (push) Failing after 2s
SFTP Integration Tests / SFTP Integration Testing (push) Failing after 3s
terraform: validate and test modules / fmt, validate, plan-level tests (push) Failing after 3s
terraform: validate and test modules / local cluster smoke test (real weed) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 3) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 2) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 2) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 3) (push) Failing after 5s
mount: windows conformance / WinFsp conformance (push) Has been cancelled
mount: windows / Mount on Windows (push) Has been cancelled
snapshot of https://github.com/seaweedfs/seaweedfs.git (master, 2026-09-16; blobs > 131072B omitted)
2026-09-16 03:23:42 +05:00

346 lines
15 KiB
Go

package weed_server
import (
"context"
"encoding/base64"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
"github.com/seaweedfs/seaweedfs/weed/filer"
"github.com/seaweedfs/seaweedfs/weed/util"
)
const (
tusTestPartialAID = "11111111-1111-1111-1111-111111111111"
tusTestPartialBID = "22222222-2222-2222-2222-222222222222"
)
// seedTusChunk writes a chunk marker entry into a session directory.
func seedTusChunk(t *testing.T, fs *FilerServer, store *renameTestStore, uploadID string, offset, size int64, fileId string) {
t.Helper()
entry := &filer.Entry{
FullPath: util.FullPath(fs.tusChunkPath(uploadID, offset, size, fileId)),
Attr: filer.Attr{Crtime: time.Unix(1700000000, 0)},
}
if err := store.InsertEntry(context.Background(), entry); err != nil {
t.Fatalf("seed chunk for %s: %v", uploadID, err)
}
}
func tusRequest(method, path string, headers map[string]string, body string) *http.Request {
var req *http.Request
if body == "" {
req = httptest.NewRequest(method, path, http.NoBody)
} else {
req = httptest.NewRequest(method, path, strings.NewReader(body))
}
req.Header.Set("Tus-Resumable", TusVersion)
for k, v := range headers {
req.Header.Set(k, v)
}
return req
}
// TestFilerServer_tusPatchHandler_PartialSkipsCompletion verifies a completed
// partial upload keeps its session and does not land at the target path, while
// the same flow without Upload-Concat completes normally.
func TestFilerServer_tusPatchHandler_PartialSkipsCompletion(t *testing.T) {
tests := []struct {
name string
concat string
expectEntry bool
}{
{"plain upload completes", "", true},
{"partial upload retained", TusConcatPartial, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fs, store := newTusTestServer(t, nil)
targetPath := "/buckets/data/file.bin"
seedTusSession(t, fs, store, TusSession{ID: tusTestUploadID, TargetPath: targetPath, Size: 0, Concat: tt.concat})
req := tusRequest(http.MethodPatch, "/.tus/.uploads/"+tusTestUploadID, map[string]string{
"Authorization": "Bearer " + signFilerToken(t, tusTestWriteKey, nil, nil),
"Content-Type": "application/offset+octet-stream",
"Upload-Offset": "0",
}, "")
rec := httptest.NewRecorder()
fs.tusHandler(rec, req)
if rec.Code != http.StatusNoContent {
t.Fatalf("PATCH = %d, want %d; body=%q", rec.Code, http.StatusNoContent, rec.Body.String())
}
_, entryErr := store.FindEntry(context.Background(), util.FullPath(targetPath))
_, sessionErr := store.FindEntry(context.Background(), util.FullPath(fs.tusSessionInfoPath(tusTestUploadID)))
if tt.expectEntry && (entryErr != nil || sessionErr == nil) {
t.Fatalf("plain upload: entry err=%v, session err=%v; want entry present and session removed", entryErr, sessionErr)
}
if !tt.expectEntry && (entryErr == nil || sessionErr != nil) {
t.Fatalf("partial upload: entry err=%v, session err=%v; want no entry and session retained", entryErr, sessionErr)
}
})
}
}
// TestFilerServer_tusHeadHandler_EchoesUploadConcat verifies HEAD reports the
// stored Upload-Concat value for partial sessions and omits it otherwise.
func TestFilerServer_tusHeadHandler_EchoesUploadConcat(t *testing.T) {
fs, store := newTusTestServer(t, map[string]string{tusTestUploadID: "/buckets/data/plain.bin"})
seedTusSession(t, fs, store, TusSession{ID: tusTestPartialAID, TargetPath: "/buckets/data/part.bin", Size: 1, Concat: TusConcatPartial})
head := func(uploadID string) *httptest.ResponseRecorder {
req := tusRequest(http.MethodHead, "/.tus/.uploads/"+uploadID, map[string]string{
"Authorization": "Bearer " + signFilerToken(t, tusTestReadKey, nil, nil),
}, "")
rec := httptest.NewRecorder()
fs.tusHandler(rec, req)
return rec
}
partialRec := head(tusTestPartialAID)
if partialRec.Code != http.StatusOK || partialRec.Header().Get("Upload-Concat") != TusConcatPartial {
t.Fatalf("partial HEAD = %d, Upload-Concat=%q; want 200 with %q", partialRec.Code, partialRec.Header().Get("Upload-Concat"), TusConcatPartial)
}
plainRec := head(tusTestUploadID)
if plainRec.Code != http.StatusOK || plainRec.Header().Get("Upload-Concat") != "" {
t.Fatalf("plain HEAD = %d, Upload-Concat=%q; want 200 without the header", plainRec.Code, plainRec.Header().Get("Upload-Concat"))
}
}
// TestFilerServer_tusConcatFinal_AssemblesPartials drives a full concatenation:
// two completed partials, referenced as a path and as an absolute URL, land as
// one entry with re-based chunks, and the consumed sessions are removed.
func TestFilerServer_tusConcatFinal_AssemblesPartials(t *testing.T) {
fs, store := newTusTestServer(t, nil)
targetPath := "/buckets/data/final.bin"
fidA, fidB := "3,01637037d6", "4,02637037d6"
seedTusSession(t, fs, store, TusSession{ID: tusTestPartialAID, TargetPath: targetPath, Size: 8, Concat: TusConcatPartial})
seedTusChunk(t, fs, store, tusTestPartialAID, 0, 8, fidA)
seedTusSession(t, fs, store, TusSession{ID: tusTestPartialBID, TargetPath: targetPath, Size: 4, Concat: TusConcatPartial})
seedTusChunk(t, fs, store, tusTestPartialBID, 0, 4, fidB)
req := tusRequest(http.MethodPost, "/.tus"+targetPath, map[string]string{
"Authorization": "Bearer " + signFilerToken(t, tusTestWriteKey, nil, nil),
"Upload-Concat": "final;/.tus/.uploads/" + tusTestPartialAID + " http://example.com/.tus/.uploads/" + tusTestPartialBID,
"Upload-Metadata": "content-type " + base64.StdEncoding.EncodeToString([]byte("text/plain")),
}, "")
rec := httptest.NewRecorder()
fs.tusHandler(rec, req)
if rec.Code != http.StatusCreated {
t.Fatalf("final POST = %d, want %d; body=%q", rec.Code, http.StatusCreated, rec.Body.String())
}
if location := rec.Header().Get("Location"); !strings.HasPrefix(location, "/.tus/.uploads/") {
t.Fatalf("Location = %q, want an upload URL", location)
}
entry, err := store.FindEntry(context.Background(), util.FullPath(targetPath))
if err != nil {
t.Fatalf("final entry not created: %v", err)
}
if entry.Mime != "text/plain" {
t.Errorf("entry mime = %q, want %q", entry.Mime, "text/plain")
}
chunks := entry.GetChunks()
if len(chunks) != 2 {
t.Fatalf("entry chunks = %d, want 2", len(chunks))
}
if chunks[0].FileId != fidA || chunks[0].Offset != 0 || chunks[0].Size != 8 {
t.Errorf("chunk[0] = %s@%d+%d, want %s@0+8", chunks[0].FileId, chunks[0].Offset, chunks[0].Size, fidA)
}
if chunks[1].FileId != fidB || chunks[1].Offset != 8 || chunks[1].Size != 4 {
t.Errorf("chunk[1] = %s@%d+%d, want %s@8+4", chunks[1].FileId, chunks[1].Offset, chunks[1].Size, fidB)
}
for _, uploadID := range []string{tusTestPartialAID, tusTestPartialBID} {
if _, err := store.FindEntry(context.Background(), util.FullPath(fs.tusSessionInfoPath(uploadID))); err == nil {
t.Errorf("partial session %s still present after concatenation", uploadID)
}
}
}
// TestFilerServer_tusConcatFinal_Validation covers the final upload request
// guards: header misuse, unusable references, unfinished or foreign partials.
func TestFilerServer_tusConcatFinal_Validation(t *testing.T) {
uploadsRef := func(uploadID string) string { return "/.tus/.uploads/" + uploadID }
completePartial := func(fs *FilerServer, store *renameTestStore, t *testing.T, uploadID, targetPath string, size int64) {
seedTusSession(t, fs, store, TusSession{ID: uploadID, TargetPath: targetPath, Size: size, Concat: TusConcatPartial})
seedTusChunk(t, fs, store, uploadID, 0, size, "3,01637037d6")
}
tests := []struct {
name string
seed func(t *testing.T, fs *FilerServer, store *renameTestStore)
headers map[string]string
body string
prefixes []string
expectStatus int
}{
{
name: "upload length rejected",
headers: map[string]string{"Upload-Concat": "final;" + uploadsRef(tusTestPartialAID), "Upload-Length": "12"},
expectStatus: http.StatusBadRequest,
},
{
name: "body rejected",
headers: map[string]string{"Upload-Concat": "final;" + uploadsRef(tusTestPartialAID)},
body: "x",
expectStatus: http.StatusForbidden,
},
{
name: "reference outside uploads prefix",
headers: map[string]string{"Upload-Concat": "final;/elsewhere/" + tusTestPartialAID},
expectStatus: http.StatusBadRequest,
},
{
name: "duplicate reference",
headers: map[string]string{"Upload-Concat": "final;" + uploadsRef(tusTestPartialAID) + " " + uploadsRef(tusTestPartialAID)},
expectStatus: http.StatusBadRequest,
},
{
name: "empty reference list",
headers: map[string]string{"Upload-Concat": "final;"},
expectStatus: http.StatusBadRequest,
},
{
name: "missing partial",
headers: map[string]string{"Upload-Concat": "final;" + uploadsRef(tusTestPartialAID)},
expectStatus: http.StatusNotFound,
},
{
name: "non-partial session rejected",
seed: func(t *testing.T, fs *FilerServer, store *renameTestStore) {
seedTusSession(t, fs, store, TusSession{ID: tusTestPartialAID, TargetPath: "/buckets/data/a.bin", Size: 1})
},
headers: map[string]string{"Upload-Concat": "final;" + uploadsRef(tusTestPartialAID)},
expectStatus: http.StatusBadRequest,
},
{
name: "unfinished partial rejected",
seed: func(t *testing.T, fs *FilerServer, store *renameTestStore) {
seedTusSession(t, fs, store, TusSession{ID: tusTestPartialAID, TargetPath: "/buckets/data/a.bin", Size: 4, Concat: TusConcatPartial})
},
headers: map[string]string{"Upload-Concat": "final;" + uploadsRef(tusTestPartialAID)},
expectStatus: http.StatusBadRequest,
},
{
name: "cross-prefix partial denied",
seed: func(t *testing.T, fs *FilerServer, store *renameTestStore) {
completePartial(fs, store, t, tusTestPartialAID, "/buckets/secret/victim.bin", 4)
},
headers: map[string]string{"Upload-Concat": "final;" + uploadsRef(tusTestPartialAID)},
prefixes: []string{"/buckets/data"},
expectStatus: http.StatusUnauthorized,
},
{
name: "combined size over maximum",
seed: func(t *testing.T, fs *FilerServer, store *renameTestStore) {
completePartial(fs, store, t, tusTestPartialAID, "/buckets/data/a.bin", TusDefaultMaxSize)
seedTusSession(t, fs, store, TusSession{ID: tusTestPartialBID, TargetPath: "/buckets/data/b.bin", Size: 1, Concat: TusConcatPartial})
},
headers: map[string]string{"Upload-Concat": "final;" + uploadsRef(tusTestPartialAID) + " " + uploadsRef(tusTestPartialBID)},
expectStatus: http.StatusRequestEntityTooLarge,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fs, store := newTusTestServer(t, nil)
if tt.seed != nil {
tt.seed(t, fs, store)
}
headers := map[string]string{
"Authorization": "Bearer " + signFilerToken(t, tusTestWriteKey, tt.prefixes, nil),
}
for k, v := range tt.headers {
headers[k] = v
}
req := tusRequest(http.MethodPost, "/.tus/buckets/data/final.bin", headers, tt.body)
rec := httptest.NewRecorder()
fs.tusHandler(rec, req)
if rec.Code != tt.expectStatus {
t.Fatalf("final POST = %d, want %d; body=%q", rec.Code, tt.expectStatus, rec.Body.String())
}
if _, err := store.FindEntry(context.Background(), util.FullPath("/buckets/data/final.bin")); err == nil {
t.Fatal("rejected concatenation still created the target entry")
}
})
}
}
// TestFilerServer_tusConcatFinal_ClaimedPartialRejected verifies a partial
// already claimed by a concurrent final cannot be consumed again, and that the
// foreign claim is left in place.
func TestFilerServer_tusConcatFinal_ClaimedPartialRejected(t *testing.T) {
fs, store := newTusTestServer(t, nil)
seedTusSession(t, fs, store, TusSession{ID: tusTestPartialAID, TargetPath: "/buckets/data/a.bin", Size: 4, Concat: TusConcatPartial})
seedTusChunk(t, fs, store, tusTestPartialAID, 0, 4, "3,01637037d6")
markerPath := util.FullPath(fs.tusSessionConsumedPath(tusTestPartialAID))
if err := store.InsertEntry(context.Background(), &filer.Entry{FullPath: markerPath}); err != nil {
t.Fatalf("seed consumed marker: %v", err)
}
req := tusRequest(http.MethodPost, "/.tus/buckets/data/final.bin", map[string]string{
"Authorization": "Bearer " + signFilerToken(t, tusTestWriteKey, nil, nil),
"Upload-Concat": "final;/.tus/.uploads/" + tusTestPartialAID,
}, "")
rec := httptest.NewRecorder()
fs.tusHandler(rec, req)
if rec.Code != http.StatusConflict {
t.Fatalf("final POST = %d, want %d; body=%q", rec.Code, http.StatusConflict, rec.Body.String())
}
if _, err := store.FindEntry(context.Background(), markerPath); err != nil {
t.Fatal("foreign claim was released by the losing request")
}
}
// TestFilerServer_tusDeleteHandler_ConsumedSessionKeepsChunks verifies deleting
// a consumed session removes its metadata without freeing its chunks. The test
// filer has no chunk deletion queue, so an attempt to free chunks would panic.
func TestFilerServer_tusDeleteHandler_ConsumedSessionKeepsChunks(t *testing.T) {
fs, store := newTusTestServer(t, nil)
seedTusSession(t, fs, store, TusSession{ID: tusTestPartialAID, TargetPath: "/buckets/data/a.bin", Size: 4, Concat: TusConcatPartial})
seedTusChunk(t, fs, store, tusTestPartialAID, 0, 4, "3,01637037d6")
if err := store.InsertEntry(context.Background(), &filer.Entry{FullPath: util.FullPath(fs.tusSessionConsumedPath(tusTestPartialAID))}); err != nil {
t.Fatalf("seed consumed marker: %v", err)
}
req := tusRequest(http.MethodDelete, "/.tus/.uploads/"+tusTestPartialAID, map[string]string{
"Authorization": "Bearer " + signFilerToken(t, tusTestWriteKey, nil, nil),
}, "")
rec := httptest.NewRecorder()
fs.tusHandler(rec, req)
if rec.Code != http.StatusNoContent {
t.Fatalf("DELETE = %d, want %d; body=%q", rec.Code, http.StatusNoContent, rec.Body.String())
}
if _, err := store.FindEntry(context.Background(), util.FullPath(fs.tusSessionInfoPath(tusTestPartialAID))); err == nil {
t.Fatal("consumed session metadata still present after DELETE")
}
}
// TestFilerServer_tusPatchHandler_FinalRejected verifies PATCH against a final
// upload URL is refused, per the concatenation extension.
func TestFilerServer_tusPatchHandler_FinalRejected(t *testing.T) {
fs, store := newTusTestServer(t, nil)
seedTusSession(t, fs, store, TusSession{ID: tusTestUploadID, TargetPath: "/buckets/data/final.bin", Size: 4, Concat: "final;/.tus/.uploads/" + tusTestPartialAID})
req := tusRequest(http.MethodPatch, "/.tus/.uploads/"+tusTestUploadID, map[string]string{
"Authorization": "Bearer " + signFilerToken(t, tusTestWriteKey, nil, nil),
"Content-Type": "application/offset+octet-stream",
"Upload-Offset": "0",
}, "")
rec := httptest.NewRecorder()
fs.tusHandler(rec, req)
if rec.Code != http.StatusForbidden {
t.Fatalf("PATCH final = %d, want %d; body=%q", rec.Code, http.StatusForbidden, rec.Body.String())
}
}