Staff upload a file for a tenant as a draft (streamed to an S3 bucket, hashed on the way, never buffered whole), publish it, or delete it; the tenant lists its published documents and gets a five-minute presigned download link. Uploads, publications and downloads are audited, a download under the person the portal names. Migration 0008 adds the documents table; internal/storage wraps minio-go (Hetzner Object Storage, the bucket is created in its region when missing). Without DOCUMENTS_S3_* the routes answer 503 and the rest of the registry is unaffected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
package storage
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestContentDisposition(t *testing.T) {
|
|
got := ContentDisposition(`Prüfbericht "Q3".pdf`)
|
|
want := `attachment; filename="Pr_fbericht _Q3_.pdf"; filename*=UTF-8''Pr%C3%BCfbericht%20%22Q3%22.pdf`
|
|
if got != want {
|
|
t.Fatalf("got %s\nwant %s", got, want)
|
|
}
|
|
}
|
|
|
|
func TestConfigured(t *testing.T) {
|
|
if (Config{}).Configured() {
|
|
t.Fatal("empty config is configured")
|
|
}
|
|
if !(Config{Endpoint: "https://x", Bucket: "b", AccessKey: "a", SecretKey: "s"}).Configured() {
|
|
t.Fatal("full config not configured")
|
|
}
|
|
}
|
|
|
|
func TestNewS3_rejectsBadEndpoint(t *testing.T) {
|
|
if _, err := NewS3(context.Background(), Config{Endpoint: "::nope", Bucket: "b", AccessKey: "a", SecretKey: "s"}); err == nil {
|
|
t.Fatal("bad endpoint accepted")
|
|
}
|
|
}
|
|
|
|
func TestMemory(t *testing.T) {
|
|
ctx := context.Background()
|
|
m := NewMemory()
|
|
if err := m.Put(ctx, "k", strings.NewReader("hello"), -1, "text/plain"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if string(m.Objects["k"]) != "hello" || m.Types["k"] != "text/plain" {
|
|
t.Fatalf("stored %q %q", m.Objects["k"], m.Types["k"])
|
|
}
|
|
u, err := m.PresignGet(ctx, "k", "a b.pdf", time.Minute)
|
|
if err != nil || !strings.Contains(u, "filename=a+b.pdf") {
|
|
t.Fatalf("presign %q %v", u, err)
|
|
}
|
|
if _, err := m.PresignGet(ctx, "missing", "x", time.Minute); err == nil {
|
|
t.Fatal("presign of a missing object")
|
|
}
|
|
if err := m.Delete(ctx, "k"); err != nil || len(m.Objects) != 0 {
|
|
t.Fatalf("delete %v", err)
|
|
}
|
|
m.FailPut = errors.New("boom")
|
|
if err := m.Put(ctx, "k", strings.NewReader("x"), 1, ""); err == nil {
|
|
t.Fatal("FailPut ignored")
|
|
}
|
|
}
|