51 lines
1.7 KiB
Go
51 lines
1.7 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestTaskReferencesRoundTripAndLegacyUpdate(t *testing.T) {
|
|
s, token, domain, actor := taskFixture(t)
|
|
task := newTaskRecord("task", "**Bold** and `code`")
|
|
task.References = []string{"https://example.test/doc", "/files/資料.pdf"}
|
|
w := taskRequest(s, token, "POST", "items", task, "")
|
|
if w.Code != 201 {
|
|
t.Fatal(w.Code, w.Body)
|
|
}
|
|
task.References = nil
|
|
task.Title = "Updated"
|
|
w = taskRequest(s, token, "PUT", "items/"+task.UUID, task, `"1"`)
|
|
if w.Code != 200 {
|
|
t.Fatal(w.Code, w.Body)
|
|
}
|
|
got, err := s.store.GetTask(context.Background(), domain, actor, task.UUID)
|
|
if err != nil || len(got.References) != 2 {
|
|
t.Fatal(got, err)
|
|
}
|
|
raw, _ := json.Marshal(got)
|
|
var body map[string]any
|
|
json.Unmarshal(raw, &body)
|
|
body["references"] = []string{}
|
|
w = taskRequest(s, token, "PUT", "items/"+task.UUID, body, `"2"`)
|
|
if w.Code != 200 {
|
|
t.Fatal(w.Code, w.Body)
|
|
}
|
|
got, err = s.store.GetTask(context.Background(), domain, actor, task.UUID)
|
|
if err != nil || len(got.References) != 0 {
|
|
t.Fatal("references not cleared", got, err)
|
|
}
|
|
for _, ref := range []string{"javascript:alert(1)", "data:text/html,hi", "//evil.test/x", "/\\evil.test/x", "https://user:pass@example.test", "https://example.test/\nheader"} {
|
|
bad := newTaskRecord("task", "bad")
|
|
bad.References = []string{ref}
|
|
if w = taskRequest(s, token, "POST", "items", bad, ""); w.Code != 422 {
|
|
t.Fatal("unsafe reference accepted", ref, w.Code)
|
|
}
|
|
}
|
|
widgets := []map[string]any{{"id": "tomorrow-schedule", "width": 6, "height": 4}, {"id": "commands", "width": 6, "height": 3}}
|
|
if w = taskRequest(s, token, "PUT", "dashboard", map[string]any{"version": 0, "widgets": widgets}, ""); w.Code != 200 {
|
|
t.Fatal(w.Code, w.Body)
|
|
}
|
|
}
|