Skip to content

Commit 54474ff

Browse files
committed
feat: add e2e tests to OPTIONS skip
1 parent 22405f1 commit 54474ff

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

e2e/container/nginx.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ http {
4242
ngx.status = ngx.HTTP_OK
4343
return ngx.say(claim_str)
4444
end
45-
ngx.status = ngx.HTTP_UNAUTHORIZED
45+
ngx.status = ngx.HTTP_ACCEPTED
4646
local response = {
47-
message = "Unauthorized"
47+
message = "Validation by passed"
4848
}
4949
return ngx.say(cjson.encode(response))
5050
}

e2e/e2e_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,20 @@ func TestNginxContainer(t *testing.T) {
167167
assert.Equal("{\"message\":\"invalid token\"}\n", string(body))
168168
})
169169

170+
t.Run("Should ignore validation when method is OPTIONS", func(t *testing.T) {
171+
t.Parallel()
172+
assert := assertTestify.New(t)
173+
assert.NoError(err)
174+
body, statusCode, err := request_test.Do(request_test.Params{
175+
Method: http.MethodOptions,
176+
URL: URL,
177+
HeaderKey: "Authorization",
178+
})
179+
assert.NoError(err)
180+
assert.Equal(http.StatusAccepted, statusCode)
181+
assert.Equal("{\"message\":\"Validation by passed\"}\n", string(body))
182+
})
183+
170184
t.Run("Should return success when a valid JWKS is provided", func(t *testing.T) {
171185
t.Parallel()
172186
assert := assertTestify.New(t)

e2e/request/request.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@ import (
66
)
77

88
type Params struct {
9+
Method string
910
URL string
1011
HeaderKey string
1112
HeaderValue string
1213
}
1314

1415
func Do(params Params) (body []byte, statusCode int, err error) {
1516
client := http.Client{}
16-
req, err := http.NewRequest(http.MethodGet, params.URL, nil)
17+
18+
method := http.MethodGet
19+
if params.Method != "" {
20+
method = params.Method
21+
}
22+
23+
req, err := http.NewRequest(method, params.URL, nil)
1724
if err != nil {
1825
return nil, statusCode, err
1926
}

0 commit comments

Comments
 (0)