MCPcopy
hub / github.com/modelcontextprotocol/registry / TestCORSHeaders

Function TestCORSHeaders

internal/api/cors_test.go:22–134  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

20)
21
22func 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 },

Callers

nothing calls this directly

Calls 6

NewConfigFunction · 0.92
NewTestDBFunction · 0.92
NewRegistryServiceFunction · 0.92
InitMetricsFunction · 0.92
NewServerFunction · 0.92
SetMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…