| @@ -92,6 +92,36 @@ func TestHealthz(t *testing.T) { · 91 unmodified lines |
| 92 | 92 | }) |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | +func TestManagementResponseExposesPluginSupportHeaderForCORS(t *testing.T) { |
| 96 | + t.Setenv("MANAGEMENT_PASSWORD", "test-management-key") |
| 97 | + |
| 98 | + server := newTestServer(t) |
| 99 | + req := httptest.NewRequest(http.MethodGet, "/v0/management/config", nil) |
| 100 | + req.Header.Set("Origin", "http://127.0.0.1:5173") |
| 101 | + rr := httptest.NewRecorder() |
| 102 | + server.engine.ServeHTTP(rr, req) |
| 103 | + |
| 104 | + if rr.Code != http.StatusUnauthorized { |
| 105 | + t.Fatalf("status = %d, want %d body=%s", rr.Code, http.StatusUnauthorized, rr.Body.String()) |
| 106 | + } |
| 107 | + if got := rr.Header().Get("X-CPA-SUPPORT-PLUGIN"); got != pluginhost.SupportPluginHeaderValue() { |
| 108 | + t.Fatalf("X-CPA-SUPPORT-PLUGIN = %q, want %q", got, pluginhost.SupportPluginHeaderValue()) |
| 109 | + } |
| 110 | + |
| 111 | + exposedHeaders := make(map[string]struct{}) |
| 112 | + for _, headerName := range strings.Split(rr.Header().Get("Access-Control-Expose-Headers"), ",") { |
| 113 | + headerName = strings.ToLower(strings.TrimSpace(headerName)) |
| 114 | + if headerName != "" { |
| 115 | + exposedHeaders[headerName] = struct{}{} |
| 116 | + } |
| 117 | + } |
| 118 | + for _, headerName := range corsExposedResponseHeaders { |
| 119 | + if _, ok := exposedHeaders[strings.ToLower(headerName)]; !ok { |
| 120 | + t.Fatalf("Access-Control-Expose-Headers missing %s: %q", headerName, rr.Header().Get("Access-Control-Expose-Headers")) |
| 121 | + } |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 95 | 125 | func TestNewServerWithPluginHostInjectsHandlerInterceptors(t *testing.T) { |
| 96 | 126 | host := pluginhost.New() |
| 97 | 127 | server := newTestServerWithOptions(t, WithPluginHost(host)) |