Files
pages/internal/server/middleware/normalize_test.go
T
Anya Tokugawa 19e12f96a8
Build and publish container images / images (push) Successful in 13m39s
Release container images / release (push) Successful in 18s
Add private CardDAV synchronization and contact revision recovery
2026-11-02 08:41:15 +09:00

27 lines
1.0 KiB
Go

package middleware
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestNormalizePathDAVCollections(t *testing.T) {
for _, path := range []string{"/_/api/v1/caldav/", "/_/api/v1/caldav/tasks/", "/_/api/v1/caldav/tasks/default/", "/_/api/v1/caldav/calendar-id/", "/_/api/v1/carddav/", "/_/api/v1/carddav/actor/contacts/"} {
mux := http.NewServeMux()
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(401) })
for _, method := range []string{"GET", "OPTIONS", "PROPFIND", "REPORT"} {
w := httptest.NewRecorder()
NormalizePath(mux).ServeHTTP(w, httptest.NewRequest(method, path, nil))
if w.Code != 401 || w.Header().Get("Location") != "" {
t.Fatalf("%s %s: %d %v", method, path, w.Code, w.Header())
}
}
}
w := httptest.NewRecorder()
NormalizePath(http.NotFoundHandler()).ServeHTTP(w, httptest.NewRequest("GET", "/wiki/path/", nil))
if w.Code != 301 || w.Header().Get("Location") != "/wiki/path" {
t.Fatal("Wiki canonicalization changed", w.Code, w.Header())
}
}