oficina / base Public

Clone
git clone https://amadan.net/oficina/base

Plain git — no account needed to clone.

Download

Download this file

1package web
2
3import (
4 "io"
5 "log/slog"
6 "net/http"
7 "net/http/httptest"
8 "strings"
9 "testing"
10
11 "amadan.net/rastrillo/rastrillo"
12 _ "amadan.net/rastrillo/rastrillo/locales/en"
13)
14
15// Base runs under rastrillo's default Content-Security-Policy. With Oficina ID
16// on, connect's middleware replaces it, so formPolicy must be that same policy
17// with only the issuer added to form-action.
18func TestFormPolicyIsRastrillosWithTheIssuer(t *testing.T) {
19 out, closeAll, err := rastrillo.Handler(rastrillo.Options{Mux: http.NewServeMux(), Logger: slog.New(slog.NewTextHandler(io.Discard, nil))})
20 if err != nil {
21 t.Fatal(err)
22 }
23 defer closeAll()
24 w := httptest.NewRecorder()
25 out.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/nothing-here", nil))
26 def := w.Header().Get("Content-Security-Policy")
27 if !strings.HasSuffix(def, "form-action 'self'") {
28 t.Fatalf("rastrillo's default CSP changed shape: %q", def)
29 }
30 if got, want := formPolicy("https://id.oficina.works"), def+" https://id.oficina.works"; got != want {
31 t.Errorf("formPolicy:\n got %q\nwant %q", got, want)
32 }
33}
34