Editors upload files to a page (attach button, paste or drop); images go into the document as images and other files as download cards. Files are stored in a new attachments collection, so PocketBase's local or S3 storage applies, and docwell-server streams them after checking the reader's page access. Documents keep the file's API path. Because <img> tags cannot send the Authorization header, clients load files with a short-lived signed file token (?token=) instead of the session token. Uploads are limited by DOCWELL_MAX_UPLOAD_MB (default 50), their type is sniffed from the content, and only images, PDFs and media are served inline, so an uploaded HTML or SVG file never runs on the API's origin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
36 lines
862 B
Go
36 lines
862 B
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package auth
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestFileTokens(t *testing.T) {
|
|
now := time.Unix(1_800_000_000, 0)
|
|
f := NewFileTokens("secret", time.Hour)
|
|
f.now = func() time.Time { return now }
|
|
|
|
tok, exp := f.Issue("user1")
|
|
if !exp.Equal(now.Add(time.Hour)) {
|
|
t.Errorf("expires %v", exp)
|
|
}
|
|
if id, err := f.Parse(tok); err != nil || id != "user1" {
|
|
t.Fatalf("parse = %q, %v", id, err)
|
|
}
|
|
if _, err := f.Parse(tok[:len(tok)-1] + "x"); err == nil {
|
|
t.Error("a tampered signature must fail")
|
|
}
|
|
if _, err := NewFileTokens("other", time.Hour).Parse(tok); err == nil {
|
|
t.Error("another key must fail")
|
|
}
|
|
now = now.Add(2 * time.Hour)
|
|
if _, err := f.Parse(tok); err == nil {
|
|
t.Error("an expired token must fail")
|
|
}
|
|
if _, err := f.Parse("garbage"); err == nil {
|
|
t.Error("garbage must fail")
|
|
}
|
|
}
|