feat: add browser upload queue and trusted sessions with bounded projections
This commit is contained in:
1 parent
84d52390f9
commit
b90aef79d0
79 files changed
+1962
-196
No files matched your search
@@ -2,6 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -85,6 +86,51 @@ func TestWebUploadCreatesAndRevisesSpecifiedPath(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebUploadCreateOnlyJSON(t *testing.T) {
|
||||
s, token, domain := configFixture(t)
|
||||
upload := func(payload string, authenticated bool) *httptest.ResponseRecorder {
|
||||
var body bytes.Buffer
|
||||
writer := multipart.NewWriter(&body)
|
||||
writer.WriteField("path", "/uploads/日本語 #1.txt")
|
||||
file, _ := writer.CreateFormFile("file", "日本語 #1.txt")
|
||||
file.Write([]byte(payload))
|
||||
writer.Close()
|
||||
r := httptest.NewRequest("POST", "http://localhost/v/upload", &body)
|
||||
r.Header.Set("Content-Type", writer.FormDataContentType())
|
||||
r.Header.Set("Accept", "application/json")
|
||||
r.Header.Set("If-None-Match", "*")
|
||||
if authenticated {
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
}
|
||||
w := httptest.NewRecorder()
|
||||
s.handleUpload(w, r)
|
||||
return w
|
||||
}
|
||||
if w := upload("denied", false); w.Code != 403 {
|
||||
t.Fatalf("unauthorized: %d", w.Code)
|
||||
}
|
||||
w := upload("original", true)
|
||||
var result map[string]string
|
||||
if w.Code != 201 || json.Unmarshal(w.Body.Bytes(), &result) != nil || result["path"] != "/uploads/日本語 #1.txt" || result["revision_uuid"] == "" {
|
||||
t.Fatalf("JSON upload %d %s", w.Code, w.Body.String())
|
||||
}
|
||||
if w = upload("overwrite", true); w.Code != 412 {
|
||||
t.Fatalf("duplicate: %d %s", w.Code, w.Body.String())
|
||||
}
|
||||
object, err := s.store.ResolvePathInDomain(domain, result["path"])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
revisions, err := s.store.ListRevisions(object)
|
||||
if err != nil || len(revisions) != 1 {
|
||||
t.Fatalf("unexpected revisions %d %v", len(revisions), err)
|
||||
}
|
||||
rev, err := s.store.GetRevision(revisions[0].UUID)
|
||||
if err != nil || rev.Body != "original" {
|
||||
t.Fatal("overwritten", err)
|
||||
}
|
||||
}
|
||||
|
||||
func mustServerDomainUUID(t *testing.T, st *store.Store) string {
|
||||
t.Helper()
|
||||
domain, err := st.GetDefaultDomain()
|
||||
|
||||
Reference in new issue
Block a user