Skip to content

Commit 8ad47d6

Browse files
committed
Fix no origin test with CORS
It seems the middleware does not send back any headers when the origin header is missing.
1 parent e6ad677 commit 8ad47d6

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

api/httpmw/cors_test.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,14 @@ func TestCors(t *testing.T) {
104104
// Should always set some kind of allowed origin, if allowed.
105105
require.Equal(t, test.allowedOrigin, rw.Header().Get(httpmw.AccessControlAllowOriginHeader))
106106

107-
// OPTIONS should echo back the request method and headers and we
108-
// should never get to our handler as the middleware short-circuits
109-
// with a 200.
110-
if method == http.MethodOptions {
107+
// OPTIONS should echo back the request method and headers (if there
108+
// is an origin header set) and we should never get to our handler as
109+
// the middleware short-circuits with a 200.
110+
if method == http.MethodOptions && test.origin == "" {
111+
require.Equal(t, "", rw.Header().Get(httpmw.AccessControlAllowMethodsHeader))
112+
require.Equal(t, "", rw.Header().Get(httpmw.AccessControlAllowHeadersHeader))
113+
require.Equal(t, http.StatusOK, rw.Code)
114+
} else if method == http.MethodOptions {
111115
require.Equal(t, http.MethodGet, rw.Header().Get(httpmw.AccessControlAllowMethodsHeader))
112116
require.Equal(t, test.allowedHeaders, rw.Header().Get(httpmw.AccessControlAllowHeadersHeader))
113117
require.Equal(t, http.StatusOK, rw.Code)

0 commit comments

Comments
 (0)