(t *testing.T)
| 20 | ) |
| 21 | |
| 22 | func TestCORSHeaders(t *testing.T) { |
| 23 | // Create test config with JWT private key |
| 24 | testSeed := make([]byte, ed25519.SeedSize) |
| 25 | _, err := rand.Read(testSeed) |
| 26 | require.NoError(t, err) |
| 27 | |
| 28 | cfg := config.NewConfig() |
| 29 | cfg.JWTPrivateKey = hex.EncodeToString(testSeed) |
| 30 | |
| 31 | // Create test services |
| 32 | db := database.NewTestDB(t) |
| 33 | registryService := service.NewRegistryService(db, cfg) |
| 34 | |
| 35 | shutdownTelemetry, metrics, err := telemetry.InitMetrics("test") |
| 36 | assert.NoError(t, err) |
| 37 | defer func() { _ = shutdownTelemetry(nil) }() |
| 38 | |
| 39 | versionInfo := &v0.VersionBody{ |
| 40 | Version: "test", |
| 41 | GitCommit: "test", |
| 42 | BuildTime: "test", |
| 43 | } |
| 44 | |
| 45 | // Create server |
| 46 | _ = api.NewServer(cfg, registryService, metrics, versionInfo) |
| 47 | |
| 48 | tests := []struct { |
| 49 | name string |
| 50 | method string |
| 51 | path string |
| 52 | expectCORS bool |
| 53 | checkPreflight bool |
| 54 | }{ |
| 55 | { |
| 56 | name: "GET request should have CORS headers", |
| 57 | method: http.MethodGet, |
| 58 | path: "/v0/health", |
| 59 | expectCORS: true, |
| 60 | }, |
| 61 | { |
| 62 | name: "POST request should have CORS headers", |
| 63 | method: http.MethodPost, |
| 64 | path: "/v0/servers", |
| 65 | expectCORS: true, |
| 66 | }, |
| 67 | { |
| 68 | name: "OPTIONS preflight request should succeed", |
| 69 | method: http.MethodOptions, |
| 70 | path: "/v0/servers", |
| 71 | expectCORS: true, |
| 72 | checkPreflight: true, |
| 73 | }, |
| 74 | { |
| 75 | name: "PUT request should have CORS headers", |
| 76 | method: http.MethodPut, |
| 77 | path: "/v0/servers/test", |
| 78 | expectCORS: true, |
| 79 | }, |
nothing calls this directly
no test coverage detected
searching dependent graphs…