@@ -15,7 +15,6 @@ import (
1515 "time"
1616
1717 "github.com/coreos/go-oidc/v3/oidc"
18− middlewareapi "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/middleware"
1918 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
2019 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/sessions"
2120 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/authentication/hmacauth"
@@ -54,7 +53,7 @@ func TestRobotsTxt(t *testing.T) {
5453 t.Fatal(err)
5554 }
5655 rw := httptest.NewRecorder()
57− req, _ := http.NewRequest(http.MethodGet, "/robots.txt", nil)
56+ req, _ := http.NewRequest("GET", "/robots.txt", nil)
5857 proxy.ServeHTTP(rw, req)
5958 assert.Equal(t, 200, rw.Code)
6059 assert.Equal(t, "User-agent: *\nDisallow: /\n", rw.Body.String())
@@ -241,7 +240,7 @@ func TestBasicAuthPassword(t *testing.T) {
241240
242241 // Save the required session
243242 rw := httptest.NewRecorder()
244− req, _ := http.NewRequest(http.MethodGet, "/", nil)
243+ req, _ := http.NewRequest("GET", "/", nil)
245244 err = proxy.sessionStore.Save(rw, req, &sessions.SessionState{
246245 Email: emailAddress,
247246 })
@@ -250,7 +249,7 @@ func TestBasicAuthPassword(t *testing.T) {
250249 // Extract the cookie value to inject into the test request
251250 cookie := rw.Header().Values("Set-Cookie")[0]
252251
253− req, _ = http.NewRequest(http.MethodGet, "/", nil)
252+ req, _ = http.NewRequest("GET", "/", nil)
254253 req.Header.Set("Cookie", cookie)
255254 rw = httptest.NewRecorder()
256255 proxy.ServeHTTP(rw, req)
@@ -300,14 +299,14 @@ func TestPassGroupsHeadersWithGroups(t *testing.T) {
300299
301300 // Save the required session
302301 rw := httptest.NewRecorder()
303− req, _ := http.NewRequest(http.MethodGet, "/", nil)
302+ req, _ := http.NewRequest("GET", "/", nil)
304303 err = proxy.sessionStore.Save(rw, req, session)
305304 assert.NoError(t, err)
306305
307306 // Extract the cookie value to inject into the test request
308307 cookie := rw.Header().Values("Set-Cookie")[0]
309308
310− req, _ = http.NewRequest(http.MethodGet, "/", nil)
309+ req, _ = http.NewRequest("GET", "/", nil)
311310 req.Header.Set("Cookie", cookie)
312311 rw = httptest.NewRecorder()
313312 proxy.ServeHTTP(rw, req)
@@ -457,7 +456,7 @@ func (patTest *PassAccessTokenTest) getEndpointWithCookie(cookie string, endpoin
457456 return 0, ""
458457 }
459458
460− req, err := http.NewRequest(http.MethodGet, endpoint, strings.NewReader(""))
459+ req, err := http.NewRequest("GET", endpoint, strings.NewReader(""))
461460 if err != nil {
462461 return 0, ""
463462 }
@@ -608,7 +607,7 @@ func NewSignInPageTest(skipProvider bool) (*SignInPageTest, error) {
608607
609608func (sipTest *SignInPageTest) GetEndpoint(endpoint string) (int, string) {
610609 rw := httptest.NewRecorder()
611− req, _ := http.NewRequest(http.MethodGet, endpoint, strings.NewReader(""))
610+ req, _ := http.NewRequest("GET", endpoint, strings.NewReader(""))
612611 sipTest.proxy.ServeHTTP(rw, req)
613612 return rw.Code, rw.Body.String()
614613}
@@ -713,50 +712,6 @@ func TestManualSignInCorrectCredentials(t *testing.T) {
713712 assert.Equal(t, http.StatusFound, statusCode)
714713}
715714
716−func TestSignInPageClearsExistingSessionCookie(t *testing.T) {
717− opts := baseTestOptions()
718− err := validation.Validate(opts)
719− require.NoError(t, err)
720−
721− proxy, err := NewOAuthProxy(opts, func(string) bool {
722− return true
723− })
724− require.NoError(t, err)
725−
726− // Create a real session cookie using the actual session store.
727− saveRW := httptest.NewRecorder()
728− saveReq := httptest.NewRequest(http.MethodGet, "/", nil)
729− err = proxy.sessionStore.Save(saveRW, saveReq, &sessions.SessionState{
730− Email: "john.doe@example.com",
731− })
732− require.NoError(t, err)
733−
734− cookies := saveRW.Result().Cookies()
735− require.NotEmpty(t, cookies)
736−
737− // Send that cookie to the sign-in page.
738− req := httptest.NewRequest(http.MethodGet, "/oauth2/sign_in", nil)
739− for _, c := range cookies {
740− req.AddCookie(c)
741− }
742−
743− rw := httptest.NewRecorder()
744− proxy.ServeHTTP(rw, req)
745−
746− assert.Equal(t, http.StatusOK, rw.Code)
747−
748− cleared := false
749− for _, c := range rw.Result().Cookies() {
750− if c.Name == proxy.CookieOptions.Name {
751− cleared = true
752− assert.Equal(t, "", c.Value)
753− assert.Less(t, c.MaxAge, 0)
754− }
755− }
756−
757− assert.True(t, cleared, "expected sign-in page to clear existing session cookie")
758−}
759−
760715func TestSignInPageIncludesTargetRedirect(t *testing.T) {
761716 sipTest, err := NewSignInPageTest(false)
762717 if err != nil {
@@ -894,7 +849,7 @@ func NewProcessCookieTest(opts ProcessCookieTestOpts, modifiers ...OptionsModifi
894849 // access_token validation.
895850 pcTest.proxy.CookieOptions.Refresh = time.Duration(0)
896851 pcTest.rw = httptest.NewRecorder()
897− pcTest.req, _ = http.NewRequest(http.MethodGet, "/", strings.NewReader(""))
852+ pcTest.req, _ = http.NewRequest("GET", "/", strings.NewReader(""))
898853 pcTest.validateUser = true
899854 return &pcTest, nil
900855}
@@ -1027,7 +982,7 @@ func NewUserInfoEndpointTest() (*ProcessCookieTest, error) {
1027982 if err != nil {
1028983 return nil, err
1029984 }
1030− pcTest.req, _ = http.NewRequest(http.MethodGet,
985+ pcTest.req, _ = http.NewRequest("GET",
1031986 pcTest.opts.ProxyPrefix+"/userinfo", nil)
1032987 return pcTest, nil
1033988}
@@ -1135,7 +1090,7 @@ func NewAuthOnlyEndpointTest(querystring string, modifiers ...OptionsModifier) (
11351090 return nil, err
11361091 }
11371092 pcTest.req, _ = http.NewRequest(
1138− http.MethodGet,
1093+ "GET",
11391094 fmt.Sprintf("%s/auth%s", pcTest.opts.ProxyPrefix, querystring),
11401095 nil)
11411096 return pcTest, nil
@@ -1274,7 +1229,7 @@ func TestAuthOnlyEndpointSetXAuthRequestHeaders(t *testing.T) {
12741229 pcTest.validateUser = true
12751230
12761231 pcTest.rw = httptest.NewRecorder()
1277− pcTest.req, _ = http.NewRequest(http.MethodGet,
1232+ pcTest.req, _ = http.NewRequest("GET",
12781233 pcTest.opts.ProxyPrefix+authOnlyPath, nil)
12791234
12801235 created := time.Now()
@@ -1367,7 +1322,7 @@ func TestAuthOnlyEndpointSetBasicAuthTrueRequestHeaders(t *testing.T) {
13671322 pcTest.validateUser = true
13681323
13691324 pcTest.rw = httptest.NewRecorder()
1370− pcTest.req, _ = http.NewRequest(http.MethodGet,
1325+ pcTest.req, _ = http.NewRequest("GET",
13711326 pcTest.opts.ProxyPrefix+authOnlyPath, nil)
13721327
13731328 created := time.Now()
@@ -1447,7 +1402,7 @@ func TestAuthOnlyEndpointSetBasicAuthFalseRequestHeaders(t *testing.T) {
14471402 pcTest.validateUser = true
14481403
14491404 pcTest.rw = httptest.NewRecorder()
1450− pcTest.req, _ = http.NewRequest(http.MethodGet,
1405+ pcTest.req, _ = http.NewRequest("GET",
14511406 pcTest.opts.ProxyPrefix+authOnlyPath, nil)
14521407
14531408 created := time.Now()
@@ -1495,7 +1450,7 @@ func TestAuthSkippedForPreflightRequests(t *testing.T) {
14951450 }
14961451 proxy.provider = NewTestProvider(upstreamURL, "")
14971452 rw := httptest.NewRecorder()
1498− req, _ := http.NewRequest(http.MethodOptions, "/preflight-request", nil)
1453+ req, _ := http.NewRequest("OPTIONS", "/preflight-request", nil)
14991454 proxy.ServeHTTP(rw, req)
15001455
15011456 assert.Equal(t, 200, rw.Code)
@@ -1652,19 +1607,19 @@ func TestRequestSignature(t *testing.T) {
16521607 resp string
16531608 }{
16541609 "No request signature": {
1655− method: http.MethodGet,
1610+ method: "GET",
16561611 body: "",
16571612 key: "",
16581613 resp: "no signature received",
16591614 },
16601615 "Get request": {
1661− method: http.MethodGet,
1616+ method: "GET",
16621617 body: "",
16631618 key: "7d9e1aa87a5954e6f9fc59266b3af9d7c35fda2d",
16641619 resp: "signatures match",
16651620 },
16661621 "Post request": {
1667− method: http.MethodPost,
1622+ method: "POST",
16681623 body: `{ "hello": "world!" }`,
16691624 key: "d90df39e2d19282840252612dd7c81421a372f61",
16701625 resp: "signatures match",
@@ -2189,33 +2144,7 @@ func TestTrustedIPs(t *testing.T) {
21892144 reverseProxy: false,
21902145 realClientIPHeader: "X-Real-IP", // Default value
21912146 req: func() *http.Request {
2192− req, _ := http.NewRequest(http.MethodGet, "/", nil)
2193− return req
2194− }(),
2195− expectTrusted: false,
2196− },
2197− // Check Unix socket with no trusted IPs configured does not error.
2198− {
2199− name: "UnixSocketWithoutTrustedIPs",
2200− trustedIPs: nil,
2201− reverseProxy: false,
2202− realClientIPHeader: "X-Real-IP",
2203− req: func() *http.Request {
2204− req, _ := http.NewRequest(http.MethodGet, "/", nil)
2205− req.RemoteAddr = "@"
2206− return req
2207− }(),
2208− expectTrusted: false,
2209− },
2210− // Check Unix socket with trusted IPs configured returns false (no IP to match).
2211− {
2212− name: "UnixSocketWithTrustedIPs",
2213− trustedIPs: []string{"127.0.0.1"},
2214− reverseProxy: false,
2215− realClientIPHeader: "X-Real-IP",
2216− req: func() *http.Request {
2217− req, _ := http.NewRequest(http.MethodGet, "/", nil)
2218− req.RemoteAddr = "@"
2147+ req, _ := http.NewRequest("GET", "/", nil)
22192148 return req
22202149 }(),
22212150 expectTrusted: false,
@@ -2227,7 +2156,7 @@ func TestTrustedIPs(t *testing.T) {
22272156 reverseProxy: false,
22282157 realClientIPHeader: "X-Real-IP", // Default value
22292158 req: func() *http.Request {
2230− req, _ := http.NewRequest(http.MethodGet, "/", nil)
2159+ req, _ := http.NewRequest("GET", "/", nil)
22312160 req.RemoteAddr = "127.0.0.1:43670"
22322161 return req
22332162 }(),
@@ -2240,7 +2169,7 @@ func TestTrustedIPs(t *testing.T) {
22402169 reverseProxy: true,
22412170 realClientIPHeader: "X-Real-IP", // Default value
22422171 req: func() *http.Request {
2243− req, _ := http.NewRequest(http.MethodGet, "/", nil)
2172+ req, _ := http.NewRequest("GET", "/", nil)
22442173 req.RemoteAddr = "127.0.0.1:44324"
22452174 return req
22462175 }(),
@@ -2253,7 +2182,7 @@ func TestTrustedIPs(t *testing.T) {
22532182 reverseProxy: true,
22542183 realClientIPHeader: "X-Forwarded-For",
22552184 req: func() *http.Request {
2256− req, _ := http.NewRequest(http.MethodGet, "/", nil)
2185+ req, _ := http.NewRequest("GET", "/", nil)
22572186 req.Header.Add("X-Forwarded-For", "127.0.0.1")
22582187 return req
22592188 }(),
@@ -2266,7 +2195,7 @@ func TestTrustedIPs(t *testing.T) {
22662195 reverseProxy: true,
22672196 realClientIPHeader: "X-Forwarded-For",
22682197 req: func() *http.Request {
2269− req, _ := http.NewRequest(http.MethodGet, "/", nil)
2198+ req, _ := http.NewRequest("GET", "/", nil)
22702199 req.Header.Add("X-Forwarded-For", "::1")
22712200 return req
22722201 }(),
@@ -2279,7 +2208,7 @@ func TestTrustedIPs(t *testing.T) {
22792208 reverseProxy: true,
22802209 realClientIPHeader: "X-Forwarded-For",
22812210 req: func() *http.Request {
2282− req, _ := http.NewRequest(http.MethodGet, "/", nil)
2211+ req, _ := http.NewRequest("GET", "/", nil)
22832212 req.Header.Add("X-Forwarded-For", "12.34.56.78")
22842213 return req
22852214 }(),
@@ -2292,7 +2221,7 @@ func TestTrustedIPs(t *testing.T) {
22922221 reverseProxy: true,
22932222 realClientIPHeader: "X-Forwarded-For",
22942223 req: func() *http.Request {
2295− req, _ := http.NewRequest(http.MethodGet, "/", nil)
2224+ req, _ := http.NewRequest("GET", "/", nil)
22962225 req.Header.Add("X-Forwarded-For", "::2")
22972226 return req
22982227 }(),
@@ -2305,7 +2234,7 @@ func TestTrustedIPs(t *testing.T) {
23052234 reverseProxy: true,
23062235 realClientIPHeader: "X-Forwarded-For",
23072236 req: func() *http.Request {
2308− req, _ := http.NewRequest(http.MethodGet, "/", nil)
2237+ req, _ := http.NewRequest("GET", "/", nil)
23092238 req.Header.Add("X-Real-IP", "::1")
23102239 return req
23112240 }(),
@@ -2318,7 +2247,7 @@ func TestTrustedIPs(t *testing.T) {
23182247 reverseProxy: true,
23192248 realClientIPHeader: "X-Forwarded-For",
23202249 req: func() *http.Request {
2321− req, _ := http.NewRequest(http.MethodGet, "/", nil)
2250+ req, _ := http.NewRequest("GET", "/", nil)
23222251 req.Header.Add("X-Forwarded-For", "adsfljk29242as!!")
23232252 return req
23242253 }(),
@@ -2331,7 +2260,7 @@ func TestTrustedIPs(t *testing.T) {
23312260 reverseProxy: false,
23322261 realClientIPHeader: "X-Real-IP",
23332262 req: func() *http.Request {
2334− req, _ := http.NewRequest(http.MethodGet, "/", nil)
2263+ req, _ := http.NewRequest("GET", "/", nil)
23352264 req.RemoteAddr = "adsfljk29242as!!"
23362265 return req
23372266 }(),
@@ -2427,12 +2356,12 @@ func Test_buildRoutesAllowlist(t *testing.T) {
24272356 },
24282357 expectedRoutes: []expectedAllowedRoute{
24292358 {
2430− method: http.MethodGet,
2359+ method: "GET",
24312360 negate: false,
24322361 regexString: "^/foo/bar",
24332362 },
24342363 {
2435− method: http.MethodPost,
2364+ method: "POST",
24362365 negate: false,
24372366 regexString: "^/baz/[0-9]+/thing",
24382367 },
@@ -2485,11 +2414,11 @@ func Test_buildRoutesAllowlist(t *testing.T) {
24852414 regexString: "^/baz/[0-9]+/thing/regex",
24862415 },
24872416 {
2488− method: http.MethodGet,
2417+ method: "GET",
24892418 regexString: "^/foo/bar",
24902419 },
24912420 {
2492− method: http.MethodPost,
2421+ method: "POST",
24932422 regexString: "^/baz/[0-9]+/thing",
24942423 },
24952424 {
@@ -2641,7 +2570,7 @@ func TestApiRoutes(t *testing.T) {
26412570
26422571 for _, tc := range testCases {
26432572 t.Run(tc.name, func(t *testing.T) {
2644− req, err := http.NewRequest(http.MethodGet, tc.url, nil)
2573+ req, err := http.NewRequest("GET", tc.url, nil)
26452574 req.Header.Set("Accept", tc.contentType)
26462575 assert.NoError(t, err)
26472576
@@ -2679,11 +2608,9 @@ func TestAllowedRequest(t *testing.T) {
26792608 }
26802609 opts.SkipAuthRegex = []string{
26812610 "^/skip/auth/regex$",
2682− "^/public/.*/endpoint$",
26832611 }
26842612 opts.SkipAuthRoutes = []string{
26852613 "GET=^/skip/auth/routes/get",
2686− "^/foo/.*/bar$",
26872614 }
26882615 err := validation.Validate(opts)
26892616 assert.NoError(t, err)
@@ -2700,37 +2627,25 @@ func TestAllowedRequest(t *testing.T) {
27002627 }{
27012628 {
27022629 name: "Regex GET allowed",
2703− method: http.MethodGet,
2630+ method: "GET",
27042631 url: "/skip/auth/regex",
27052632 allowed: true,
27062633 },
27072634 {
27082635 name: "Regex POST allowed ",
2709− method: http.MethodPost,
2636+ method: "POST",
27102637 url: "/skip/auth/regex",
27112638 allowed: true,
27122639 },
27132640 {
27142641 name: "Regex denied",
2715− method: http.MethodGet,
2642+ method: "GET",
27162643 url: "/wrong/denied",
27172644 allowed: false,
27182645 },
2719− {
2720− name: "Regex allowed with fragment-free path",
2721− method: http.MethodGet,
2722− url: "/public/legit/endpoint",
2723− allowed: true,
2724− },
2725− {
2726− name: "Regex denied when path contains encoded fragment suffix",
2727− method: http.MethodGet,
2728− url: "/public/secret%23/endpoint",
2729− allowed: false,
2730− },
27312646 {
27322647 name: "Route allowed",
2733− method: http.MethodGet,
2648+ method: "GET",
27342649 url: "/skip/auth/routes/get",
27352650 allowed: true,
27362651 },
@@ -2742,28 +2657,16 @@ func TestAllowedRequest(t *testing.T) {
27422657 },
27432658 {
27442659 name: "Route denied with wrong path",
2745− method: http.MethodGet,
2660+ method: "GET",
27462661 url: "/skip/auth/routes/wrong/path",
27472662 allowed: false,
27482663 },
27492664 {
27502665 name: "Route denied with wrong path and method",
2751− method: http.MethodPost,
2666+ method: "POST",
27522667 url: "/skip/auth/routes/wrong/path",
27532668 allowed: false,
27542669 },
2755− {
2756− name: "Route allowed with fragment-free path",
2757− method: http.MethodGet,
2758− url: "/foo/public/bar",
2759− allowed: true,
2760− },
2761− {
2762− name: "Route denied when path contains encoded fragment suffix",
2763− method: http.MethodGet,
2764− url: "/foo/secret%23/bar",
2765− allowed: false,
2766− },
27672670 }
27682671
27692672 for _, tc := range testCases {
@@ -2804,11 +2707,9 @@ func TestAllowedRequestWithForwardedUriHeader(t *testing.T) {
28042707 }
28052708 opts.SkipAuthRegex = []string{
28062709 "^/skip/auth/regex$",
2807− "^/public/.*/endpoint$",
28082710 }
28092711 opts.SkipAuthRoutes = []string{
28102712 "GET=^/skip/auth/routes/get",
2811− "^/foo/.*/bar$",
28122713 }
28132714 err := validation.Validate(opts)
28142715 assert.NoError(t, err)
@@ -2825,37 +2726,25 @@ func TestAllowedRequestWithForwardedUriHeader(t *testing.T) {
28252726 }{
28262727 {
28272728 name: "Regex GET allowed",
2828− method: http.MethodGet,
2729+ method: "GET",
28292730 url: "/skip/auth/regex",
28302731 allowed: true,
28312732 },
28322733 {
28332734 name: "Regex POST allowed ",
2834− method: http.MethodPost,
2735+ method: "POST",
28352736 url: "/skip/auth/regex",
28362737 allowed: true,
28372738 },
28382739 {
28392740 name: "Regex denied",
2840− method: http.MethodGet,
2741+ method: "GET",
28412742 url: "/wrong/denied",
28422743 allowed: false,
28432744 },
2844− {
2845− name: "Regex allowed with fragment-free path",
2846− method: http.MethodGet,
2847− url: "/public/legit/endpoint",
2848− allowed: true,
2849− },
2850− {
2851− name: "Regex denied when X-Forwarded-Uri contains an encoded fragment suffix",
2852− method: http.MethodGet,
2853− url: "/public/secret%23/endpoint",
2854− allowed: false,
2855− },
28562745 {
28572746 name: "Route allowed",
2858− method: http.MethodGet,
2747+ method: "GET",
28592748 url: "/skip/auth/routes/get",
28602749 allowed: true,
28612750 },
@@ -2867,35 +2756,22 @@ func TestAllowedRequestWithForwardedUriHeader(t *testing.T) {
28672756 },
28682757 {
28692758 name: "Route denied with wrong path",
2870− method: http.MethodGet,
2759+ method: "GET",
28712760 url: "/skip/auth/routes/wrong/path",
28722761 allowed: false,
28732762 },
28742763 {
28752764 name: "Route denied with wrong path and method",
2876− method: http.MethodPost,
2765+ method: "POST",
28772766 url: "/skip/auth/routes/wrong/path",
28782767 allowed: false,
28792768 },
2880− {
2881− name: "Route allowed with fragment-free path",
2882− method: http.MethodGet,
2883− url: "/foo/public/bar",
2884− allowed: true,
2885− },
2886− {
2887− name: "Route denied when X-Forwarded-Uri contains an encoded fragment suffix",
2888− method: http.MethodGet,
2889− url: "/foo/secret%23/bar",
2890− allowed: false,
2891− },
28922769 }
28932770
28942771 for _, tc := range testCases {
28952772 t.Run(tc.name, func(t *testing.T) {
28962773 req, err := http.NewRequest(tc.method, opts.ProxyPrefix+authOnlyPath, nil)
28972774 req.Header.Set("X-Forwarded-Uri", tc.url)
2898− req.RemoteAddr = "127.0.0.1:4180"
28992775 assert.NoError(t, err)
29002776
29012777 rw := httptest.NewRecorder()
@@ -2910,43 +2786,6 @@ func TestAllowedRequestWithForwardedUriHeader(t *testing.T) {
29102786 }
29112787}
29122788
2913−func TestAllowedRequestWithForwardedUriHeaderRequiresTrustedProxy(t *testing.T) {
2914− upstreamServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2915− w.WriteHeader(200)
2916− }))
2917− t.Cleanup(upstreamServer.Close)
2918−
2919− opts := baseTestOptions()
2920− opts.ReverseProxy = true
2921− opts.TrustedProxyIPs = []string{"127.0.0.1/32"}
2922− opts.UpstreamServers = options.UpstreamConfig{
2923− Upstreams: []options.Upstream{
2924− {
2925− ID: upstreamServer.URL,
2926− Path: "/",
2927− URI: upstreamServer.URL,
2928− },
2929− },
2930− }
2931− opts.SkipAuthRegex = []string{"^/skip/auth/regex$"}
2932−
2933− err := validation.Validate(opts)
2934− assert.NoError(t, err)
2935−
2936− proxy, err := NewOAuthProxy(opts, func(_ string) bool { return true })
2937− assert.NoError(t, err)
2938−
2939− req, err := http.NewRequest(http.MethodGet, opts.ProxyPrefix+authOnlyPath, nil)
2940− assert.NoError(t, err)
2941− req.RemoteAddr = "192.0.2.10:4180"
2942− req.Header.Set("X-Forwarded-Uri", "/skip/auth/regex")
2943−
2944− rw := httptest.NewRecorder()
2945− proxy.ServeHTTP(rw, req)
2946−
2947− assert.Equal(t, 401, rw.Code)
2948−}
2949−
29502789func TestAllowedRequestNegateWithoutMethod(t *testing.T) {
29512790 upstreamServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
29522791 w.WriteHeader(200)
@@ -2986,37 +2825,37 @@ func TestAllowedRequestNegateWithoutMethod(t *testing.T) {
29862825 }{
29872826 {
29882827 name: "Some static file allowed",
2989− method: http.MethodGet,
2828+ method: "GET",
29902829 url: "/static/file.txt",
29912830 allowed: true,
29922831 },
29932832 {
29942833 name: "POST to contact form allowed",
2995− method: http.MethodPost,
2834+ method: "POST",
29962835 url: "/contact",
29972836 allowed: true,
29982837 },
29992838 {
30002839 name: "Regex POST allowed",
3001− method: http.MethodPost,
2840+ method: "POST",
30022841 url: "/api/public-entity",
30032842 allowed: true,
30042843 },
30052844 {
30062845 name: "Regex POST with trailing slash allowed",
3007− method: http.MethodPost,
2846+ method: "POST",
30082847 url: "/api/public-entity/",
30092848 allowed: true,
30102849 },
30112850 {
30122851 name: "Regex GET api route denied",
3013− method: http.MethodGet,
2852+ method: "GET",
30142853 url: "/api/users",
30152854 allowed: false,
30162855 },
30172856 {
30182857 name: "Regex POST api route denied",
3019− method: http.MethodPost,
2858+ method: "POST",
30202859 url: "/api/users",
30212860 allowed: false,
30222861 },
@@ -3086,37 +2925,37 @@ func TestAllowedRequestNegateWithMethod(t *testing.T) {
30862925 }{
30872926 {
30882927 name: "Some static file allowed",
3089− method: http.MethodGet,
2928+ method: "GET",
30902929 url: "/static/file.txt",
30912930 allowed: true,
30922931 },
30932932 {
30942933 name: "POST to contact form not allowed",
3095− method: http.MethodPost,
2934+ method: "POST",
30962935 url: "/contact",
30972936 allowed: false,
30982937 },
30992938 {
31002939 name: "Regex POST allowed",
3101− method: http.MethodPost,
2940+ method: "POST",
31022941 url: "/api/public-entity",
31032942 allowed: true,
31042943 },
31052944 {
31062945 name: "Regex POST with trailing slash allowed",
3107− method: http.MethodPost,
2946+ method: "POST",
31082947 url: "/api/public-entity/",
31092948 allowed: true,
31102949 },
31112950 {
31122951 name: "Regex GET api route denied",
3113− method: http.MethodGet,
2952+ method: "GET",
31142953 url: "/api/users",
31152954 allowed: false,
31162955 },
31172956 {
31182957 name: "Regex POST api route denied",
3119− method: http.MethodPost,
2958+ method: "POST",
31202959 url: "/api/users",
31212960 allowed: false,
31222961 },
@@ -3256,7 +3095,7 @@ func TestProxyAllowedGroups(t *testing.T) {
32563095 t.Fatal(err)
32573096 }
32583097
3259− test.req, _ = http.NewRequest(http.MethodGet, fmt.Sprintf("/%s", tt.querystring), nil)
3098+ test.req, _ = http.NewRequest("GET", fmt.Sprintf("/%s", tt.querystring), nil)
32603099
32613100 test.req.Header.Add("accept", applicationJSON)
32623101 err = test.SaveSession(session)
@@ -3400,7 +3239,7 @@ func TestAuthOnlyAllowedGroupsWithSkipMethods(t *testing.T) {
34003239 {
34013240 name: "UserWithGroupSkipAuthPreflight",
34023241 groups: []string{"a", "c"},
3403− method: http.MethodOptions,
3242+ method: "OPTIONS",
34043243 ip: "1.2.3.5:43670",
34053244 withSession: true,
34063245 expectedStatusCode: http.StatusAccepted,
@@ -3408,7 +3247,7 @@ func TestAuthOnlyAllowedGroupsWithSkipMethods(t *testing.T) {
34083247 {
34093248 name: "UserWithGroupTrustedIp",
34103249 groups: []string{"a", "c"},
3411− method: http.MethodGet,
3250+ method: "GET",
34123251 ip: "1.2.3.4:43670",
34133252 withSession: true,
34143253 expectedStatusCode: http.StatusAccepted,
@@ -3416,7 +3255,7 @@ func TestAuthOnlyAllowedGroupsWithSkipMethods(t *testing.T) {
34163255 {
34173256 name: "UserWithoutGroupSkipAuthPreflight",
34183257 groups: []string{"c"},
3419− method: http.MethodOptions,
3258+ method: "OPTIONS",
34203259 ip: "1.2.3.5:43670",
34213260 withSession: true,
34223261 expectedStatusCode: http.StatusForbidden,
@@ -3424,21 +3263,21 @@ func TestAuthOnlyAllowedGroupsWithSkipMethods(t *testing.T) {
34243263 {
34253264 name: "UserWithoutGroupTrustedIp",
34263265 groups: []string{"c"},
3427− method: http.MethodGet,
3266+ method: "GET",
34283267 ip: "1.2.3.4:43670",
34293268 withSession: true,
34303269 expectedStatusCode: http.StatusForbidden,
34313270 },
34323271 {
34333272 name: "UserWithoutSessionSkipAuthPreflight",
3434− method: http.MethodOptions,
3273+ method: "OPTIONS",
34353274 ip: "1.2.3.5:43670",
34363275 withSession: false,
34373276 expectedStatusCode: http.StatusAccepted,
34383277 },
34393278 {
34403279 name: "UserWithoutSessionTrustedIp",
3441− method: http.MethodGet,
3280+ method: "GET",
34423281 ip: "1.2.3.4:43670",
34433282 withSession: false,
34443283 expectedStatusCode: http.StatusAccepted,
@@ -3538,24 +3377,6 @@ func TestAuthOnlyAllowedEmailDomains(t *testing.T) {
35383377 querystring: "?allowed_email_domains=a.b.c.example.com,*.c.example.com",
35393378 expectedStatusCode: http.StatusAccepted,
35403379 },
3541− {
3542− name: "UserWithMultipleAtSignsExactDomain",
3543− email: "attacker@evil.com@example.com",
3544− querystring: "?allowed_email_domains=example.com",
3545− expectedStatusCode: http.StatusForbidden,
3546− },
3547− {
3548− name: "UserWithMultipleAtSignsWildcardDomain",
3549− email: "attacker@evil.com@foo.example.com",
3550− querystring: "?allowed_email_domains=*.example.com",
3551− expectedStatusCode: http.StatusForbidden,
3552− },
3553− {
3554− name: "UserWithMultipleAtSignsDotPrefixedDomain",
3555− email: "attacker@evil.com@foo.example.com",
3556− querystring: "?allowed_email_domains=.example.com",
3557− expectedStatusCode: http.StatusForbidden,
3558− },
35593380 }
35603381
35613382 for _, tc := range testCases {
@@ -3762,49 +3583,3 @@ func TestGetOAuthRedirectURI(t *testing.T) {
37623583 })
37633584 }
37643585}
3765−
3766−func TestIdTokenPlaceholderInSignOut(t *testing.T) {
3767− opts := baseTestOptions()
3768− opts.WhitelistDomains = []string{"my-oidc-provider.example.com"}
3769−
3770− err := validation.Validate(opts)
3771− assert.NoError(t, err)
3772−
3773− const emailAddress = "john.doe@example.com"
3774− const userName = "9fcab5c9b889a557"
3775− created := time.Now()
3776−
3777− session := &sessions.SessionState{
3778− User: userName,
3779− Groups: []string{"a", "b"},
3780− Email: emailAddress,
3781− IDToken: "eYjjjjjj.vvvv.ddd",
3782− AccessToken: "oauth_token",
3783− CreatedAt: &created,
3784− }
3785−
3786− proxy, err := NewOAuthProxy(opts, func(email string) bool {
3787− return true
3788− })
3789− assert.NoError(t, err)
3790−
3791− // Save the required session
3792− rw := httptest.NewRecorder()
3793− req, _ := http.NewRequest(http.MethodGet, "/", nil)
3794− err = proxy.sessionStore.Save(rw, req, session)
3795− assert.NoError(t, err)
3796−
3797− rw = httptest.NewRecorder()
3798−
3799− rdUrl := url.QueryEscape("https://my-oidc-provider.example.com/sign_out_page?id_token_hint={id_token}&post_logout_redirect_uri=https://my-app.example.com/")
3800− req, _ = http.NewRequest(http.MethodGet, "/oauth2/sign_out?rd="+rdUrl, nil)
3801− req = middlewareapi.AddRequestScope(req, &middlewareapi.RequestScope{
3802− RequestID: "11111111-2222-4333-8444-555555555555",
3803− Session: session,
3804− })
3805−
3806− proxy.SignOut(rw, req)
3807− newLocation := rw.Header().Values("Location")[0]
3808−
3809− assert.Equal(t, "https://my-oidc-provider.example.com/sign_out_page?id_token_hint=eYjjjjjj.vvvv.ddd&post_logout_redirect_uri=https://my-app.example.com/", newLocation)
3810−}