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

Method TestWithSecret

server/server_test.go:145–189  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

143}
144
145func (s *ServerTestSuite) TestWithSecret() {
146 tests := []struct {
147 name string
148 secret string
149 authHeader string
150 expectStatus int
151 }{
152 {
153 name: "ValidSecret",
154 secret: "test-secret",
155 authHeader: "Bearer test-secret",
156 expectStatus: http.StatusOK,
157 },
158 {
159 name: "InvalidSecret",
160 secret: "foo-secret",
161 authHeader: "Bearer wrong-secret",
162 expectStatus: http.StatusForbidden,
163 },
164 {
165 name: "NoSecretConfigured",
166 secret: "",
167 authHeader: "",
168 expectStatus: http.StatusOK,
169 },
170 }
171
172 for _, tt := range tests {
173 s.Run(tt.name, func() {
174 s.config().Secret = tt.secret
175
176 s.router().GET("/test", s.router().WithReportError(s.router().WithSecret(s.mockHandler)))
177
178 req := httptest.NewRequest(http.MethodGet, "/test", nil)
179 if tt.authHeader != "" {
180 req.Header.Set(httpheaders.Authorization, tt.authHeader)
181 }
182 rw := httptest.NewRecorder()
183
184 s.router().ServeHTTP(rw, req)
185
186 s.Equal(tt.expectStatus, rw.Code)
187 })
188 }
189}
190
191func (s *ServerTestSuite) TestIntoSuccess() {
192 mockHandler := func(reqID string, rw server.ResponseWriter, r *http.Request) *server.Error {

Callers

nothing calls this directly

Calls 7

RunMethod · 0.80
WithReportErrorMethod · 0.80
WithSecretMethod · 0.80
NewRequestMethod · 0.80
ServeHTTPMethod · 0.80
GETMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected