(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestCSPMiddleware(t *testing.T) { |
| 12 | |
| 13 | testCases := []struct { |
| 14 | name string |
| 15 | }{ |
| 16 | { |
| 17 | name: "success", |
| 18 | }, |
| 19 | } |
| 20 | |
| 21 | for _, tc := range testCases { |
| 22 | |
| 23 | t.Run(tc.name, func(t *testing.T) { |
| 24 | |
| 25 | assert := assert.New(t) |
| 26 | |
| 27 | next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 28 | ctx := r.Context() |
| 29 | |
| 30 | nonces := GetNonces(ctx) |
| 31 | twNonce := GetTwNonce(ctx) |
| 32 | htmxNonce := GetHtmxNonce(ctx) |
| 33 | responseTargetsNonce := GetResponseTargetsNonce(ctx) |
| 34 | |
| 35 | assert.Equal(nonces.Tw, twNonce) |
| 36 | assert.Len(twNonce, 32) |
| 37 | |
| 38 | assert.Equal(nonces.Htmx, htmxNonce) |
| 39 | assert.Len(htmxNonce, 32) |
| 40 | |
| 41 | assert.Equal(nonces.ResponseTargets, responseTargetsNonce) |
| 42 | assert.Len(responseTargetsNonce, 32) |
| 43 | |
| 44 | }) |
| 45 | |
| 46 | middleware := CSPMiddleware(next) |
| 47 | |
| 48 | recorder := httptest.NewRecorder() |
| 49 | request := httptest.NewRequest("GET", "/", nil) |
| 50 | |
| 51 | middleware.ServeHTTP(recorder, request) |
| 52 | |
| 53 | csp := recorder.Header().Get("Content-Security-Policy") |
| 54 | |
| 55 | assert.NotEmpty(csp) |
| 56 | |
| 57 | }) |
| 58 | } |
| 59 | |
| 60 | } |
nothing calls this directly
no test coverage detected