Document engine redistribution requirements; exclude upstream engine assets and keep the viewer disabled by default.
42 lines
1.5 KiB
Go
42 lines
1.5 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())
|
|
}
|
|
}
|
|
|
|
func TestNormalizePathGeckoWebsocket(t *testing.T) {
|
|
for _, path := range []string{"/_/api/v1/extension/organizer.feeds/browser/", "/_/api/v1/extension/organizer.feeds/browser/wisp/"} {
|
|
w := httptest.NewRecorder()
|
|
NormalizePath(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != path {
|
|
t.Fatal(r.URL.Path)
|
|
}
|
|
w.WriteHeader(401)
|
|
})).ServeHTTP(w, httptest.NewRequest("GET", path, nil))
|
|
if w.Code != 401 || w.Header().Get("Location") != "" {
|
|
t.Fatal("redirected browser endpoint", w.Code)
|
|
}
|
|
}
|
|
}
|