fix: use subject-independent identities for captured mail Wiki paths
Build and publish container images / images (push) Successful in 11m59s
Release container images / release (push) Successful in 25s

This commit is contained in:
Anya Tokugawa committed 2026-11-06 09:02:34 +09:00
1 parent 0b6343aff0
commit 3262f88005
7 files changed
+91 -11

No files matched your search

+41
View File
@@ -5,6 +5,8 @@ import (
"database/sql"
"encoding/json"
"errors"
"net/http/httptest"
"net/url"
"strings"
"testing"
"time"
@@ -15,6 +17,7 @@ import (
func TestTaskMailWikiCapture(t *testing.T) {
s, token, domain, actor := taskFixture(t)
s.mux.HandleFunc("/v/raw/", s.handleRawView)
ctx := context.Background()
p, err := s.store.TaskPreferences(ctx, domain, actor)
if err != nil {
@@ -51,6 +54,29 @@ func TestTaskMailWikiCapture(t *testing.T) {
if err != nil || !strings.Contains(rev.Body, "<script>bad()</script>") || strings.Contains(rev.Body, "{{children}}") {
t.Fatal(rev, err)
}
// Existing Japanese paths are not renamed or broken by receipt replay.
legacy := "/private/mail/日本語の件名 [list 123]--" + id
if _, err = s.store.DB.Exec(`UPDATE paths SET path=? WHERE domain_uuid=? AND object_uuid=?`, legacy, domain, response.Item.PageUUID); err != nil {
t.Fatal(err)
}
note := taskRequest(s, token, "GET", "items/"+id+"/note", nil, "")
var links struct {
URL string `json:"url"`
}
if err = json.Unmarshal(note.Body.Bytes(), &links); err != nil {
t.Fatal(err)
}
u, err := url.Parse(links.URL)
if err != nil || u.Path != legacy || u.RawQuery != "" || u.Fragment != "" {
t.Fatal("Japanese note URL", links.URL, err)
}
request := httptest.NewRequest("GET", "http://localhost/v/raw/path:"+links.URL, nil)
request.Header.Set("Authorization", "Bearer "+token)
rawResult := httptest.NewRecorder()
s.withAuthorization(s.mux).ServeHTTP(rawResult, request)
if rawResult.Code != 200 || rawResult.Body.String() != rev.Body {
t.Fatal("Japanese path fetch", rawResult.Code)
}
// A committed retry remains stable even if the preference changes.
p, err = s.store.TaskPreferences(ctx, domain, actor)
if err != nil {
@@ -63,6 +89,9 @@ func TestTaskMailWikiCapture(t *testing.T) {
if w = taskRequest(s, token, "POST", "capture", input, ""); w.Code != 201 || !strings.Contains(w.Body.String(), response.Item.PageUUID) {
t.Fatal(w.Code, w.Body)
}
if !strings.Contains(w.Body.String(), legacy) {
t.Fatal("retry changed existing path", w.Body)
}
input["wiki_body"] = "different"
if w = taskRequest(s, token, "POST", "capture", input, ""); w.Code != 412 {
t.Fatal(w.Code, w.Body)
@@ -74,6 +103,18 @@ func TestTaskMailWikiCapture(t *testing.T) {
}
}
func TestMailWikiPathDoesNotContainSubject(t *testing.T) {
id := uuid.NewString()
for _, title := range []string{"日本語", "[hogehoge 123] 件名", strings.Repeat("長い", 100), "?#/\\% []"} {
if got := store.TaskCaptureWikiPath("/mail", title, id); got != "/mail/mail-"+id {
t.Fatal(got)
}
}
if store.TaskCaptureWikiPath("/mail", "日本語", uuid.NewString()) == store.TaskCaptureWikiPath("/mail", "日本語", id) {
t.Fatal("different mails collided")
}
}
func TestTaskMailWikiRollbackAndAccess(t *testing.T) {
s, token, domain, actor := taskFixture(t)
ctx := context.Background()
+1
View File
@@ -16,6 +16,7 @@ func TestTaskCLIHTTPIntegration(t *testing.T) {
t.Skip("python3 not installed")
}
s, token, _, _ := taskFixture(t)
s.mux.HandleFunc("/v/raw/", s.handleRawView)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.Host = "localhost"
s.withAuthorization(s.mux).ServeHTTP(w, r)