The web UI sends JSON. The guard accepts the web UI origin for a JSON request, because a browser must do a preflight to send it cross-origin.
(t *testing.T)
| 88 | // The web UI sends JSON. The guard accepts the web UI origin for a JSON |
| 89 | // request, because a browser must do a preflight to send it cross-origin. |
| 90 | func TestLoopbackGuard_WebUIJSON(t *testing.T) { |
| 91 | r := guardEngine(nil) |
| 92 | req := httptest.NewRequest(http.MethodPost, "/patterns/name", nil) |
| 93 | req.Host = "localhost:8080" |
| 94 | req.Header.Set("Content-Type", "application/json; charset=utf-8") |
| 95 | req.Header.Set("Origin", "http://127.0.0.1:5173") |
| 96 | w := httptest.NewRecorder() |
| 97 | r.ServeHTTP(w, req) |
| 98 | if w.Code != http.StatusOK { |
| 99 | t.Errorf("got %d, want %d", w.Code, http.StatusOK) |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // The guard lets a preflight and the Swagger documents through from any |
| 104 | // Host. It accepts the Host of a CORS origin, but only for that host. |
nothing calls this directly
no test coverage detected