27 lines
1.0 KiB
Go
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())
|
|
}
|
|
}
|