MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / TestWithCORS

Method TestWithCORS

server/server_test.go:107–143  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

105}
106
107func (s *ServerTestSuite) TestWithCORS() {
108 tests := []struct {
109 name string
110 corsAllowOrigin string
111 expectedOrigin string
112 expectedMethods string
113 }{
114 {
115 name: "WithCORSOrigin",
116 corsAllowOrigin: "https://example.com",
117 expectedOrigin: "https://example.com",
118 expectedMethods: "GET, OPTIONS",
119 },
120 {
121 name: "NoCORSOrigin",
122 corsAllowOrigin: "",
123 expectedOrigin: "",
124 expectedMethods: "",
125 },
126 }
127
128 for _, tt := range tests {
129 s.Run(tt.name, func() {
130 s.config().CORSAllowOrigin = tt.corsAllowOrigin
131
132 s.router().GET("/test", s.router().WithCORS(s.mockHandler))
133
134 req := httptest.NewRequest(http.MethodGet, "/test", nil)
135 rw := httptest.NewRecorder()
136
137 s.router().ServeHTTP(rw, req)
138
139 s.Equal(tt.expectedOrigin, rw.Header().Get(httpheaders.AccessControlAllowOrigin))
140 s.Equal(tt.expectedMethods, rw.Header().Get(httpheaders.AccessControlAllowMethods))
141 })
142 }
143}
144
145func (s *ServerTestSuite) TestWithSecret() {
146 tests := []struct {

Callers

nothing calls this directly

Calls 6

RunMethod · 0.80
WithCORSMethod · 0.80
NewRequestMethod · 0.80
ServeHTTPMethod · 0.80
GetMethod · 0.65
GETMethod · 0.45

Tested by

no test coverage detected