git.iko.soy/typeable/oauth2-proxy
on master help sign in
chore(goconsts): use proper constants for http methods

Signed-off-by: Jan Larwig <jan@larwig.com>

commit9a14186a26cb7a12e51d39ed3a10ff0299d5e354 authorJan Larwig <jan@larwig.com> dateMon 8 Jun 2026, 12:54 (4 months ago) parent65037b0
11 files changed+106−102
oauthproxy.go+2−2 oauthproxy_test.go+75−75 pkg/apis/options/load.go+1−1 pkg/authentication/hmacauth/hmacauth_test.go+1−1 pkg/requests/builder_test.go+15−15 providers/azure.go+2−2 providers/google.go+2−2 providers/logingov.go+2−1 providers/ms_entra_id.go+2−1 providers/provider_default.go+2−1 providers/srht.go+2−1
oauthproxy.go+2−2
@@ -587,7 +587,7 @@ func (p *OAuthProxy) ErrorPage(rw http.ResponseWriter, req *http.Request, code i
587587
588588// IsAllowedRequest is used to check if auth should be skipped for this request
589589func (p *OAuthProxy) IsAllowedRequest(req *http.Request) bool {
590− isPreflightRequestAllowed := p.skipAuthPreflight && req.Method == "OPTIONS"
590+ isPreflightRequestAllowed := p.skipAuthPreflight && req.Method == http.MethodOptions
591591 return isPreflightRequestAllowed || p.isAllowedRoute(req) || p.isTrustedIP(req)
592592}
593593
@@ -669,7 +669,7 @@ func (p *OAuthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code
669669
670670// ManualSignIn handles basic auth logins to the proxy
671671func (p *OAuthProxy) ManualSignIn(req *http.Request) (string, bool, int) {
672− if req.Method != "POST" || p.basicAuthValidator == nil {
672+ if req.Method != http.MethodPost || p.basicAuthValidator == nil {
673673 return "", false, http.StatusOK
674674 }
675675 user := req.FormValue("username")
oauthproxy_test.go+75−75
@@ -54,7 +54,7 @@ func TestRobotsTxt(t *testing.T) {
5454 t.Fatal(err)
5555 }
5656 rw := httptest.NewRecorder()
57− req, _ := http.NewRequest("GET", "/robots.txt", nil)
57+ req, _ := http.NewRequest(http.MethodGet, "/robots.txt", nil)
5858 proxy.ServeHTTP(rw, req)
5959 assert.Equal(t, 200, rw.Code)
6060 assert.Equal(t, "User-agent: *\nDisallow: /\n", rw.Body.String())
@@ -241,7 +241,7 @@ func TestBasicAuthPassword(t *testing.T) {
241241
242242 // Save the required session
243243 rw := httptest.NewRecorder()
244− req, _ := http.NewRequest("GET", "/", nil)
244+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
245245 err = proxy.sessionStore.Save(rw, req, &sessions.SessionState{
246246 Email: emailAddress,
247247 })
@@ -250,7 +250,7 @@ func TestBasicAuthPassword(t *testing.T) {
250250 // Extract the cookie value to inject into the test request
251251 cookie := rw.Header().Values("Set-Cookie")[0]
252252
253− req, _ = http.NewRequest("GET", "/", nil)
253+ req, _ = http.NewRequest(http.MethodGet, "/", nil)
254254 req.Header.Set("Cookie", cookie)
255255 rw = httptest.NewRecorder()
256256 proxy.ServeHTTP(rw, req)
@@ -300,14 +300,14 @@ func TestPassGroupsHeadersWithGroups(t *testing.T) {
300300
301301 // Save the required session
302302 rw := httptest.NewRecorder()
303− req, _ := http.NewRequest("GET", "/", nil)
303+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
304304 err = proxy.sessionStore.Save(rw, req, session)
305305 assert.NoError(t, err)
306306
307307 // Extract the cookie value to inject into the test request
308308 cookie := rw.Header().Values("Set-Cookie")[0]
309309
310− req, _ = http.NewRequest("GET", "/", nil)
310+ req, _ = http.NewRequest(http.MethodGet, "/", nil)
311311 req.Header.Set("Cookie", cookie)
312312 rw = httptest.NewRecorder()
313313 proxy.ServeHTTP(rw, req)
@@ -457,7 +457,7 @@ func (patTest *PassAccessTokenTest) getEndpointWithCookie(cookie string, endpoin
457457 return 0, ""
458458 }
459459
460− req, err := http.NewRequest("GET", endpoint, strings.NewReader(""))
460+ req, err := http.NewRequest(http.MethodGet, endpoint, strings.NewReader(""))
461461 if err != nil {
462462 return 0, ""
463463 }
@@ -608,7 +608,7 @@ func NewSignInPageTest(skipProvider bool) (*SignInPageTest, error) {
608608
609609func (sipTest *SignInPageTest) GetEndpoint(endpoint string) (int, string) {
610610 rw := httptest.NewRecorder()
611− req, _ := http.NewRequest("GET", endpoint, strings.NewReader(""))
611+ req, _ := http.NewRequest(http.MethodGet, endpoint, strings.NewReader(""))
612612 sipTest.proxy.ServeHTTP(rw, req)
613613 return rw.Code, rw.Body.String()
614614}
@@ -894,7 +894,7 @@ func NewProcessCookieTest(opts ProcessCookieTestOpts, modifiers ...OptionsModifi
894894 // access_token validation.
895895 pcTest.proxy.CookieOptions.Refresh = time.Duration(0)
896896 pcTest.rw = httptest.NewRecorder()
897− pcTest.req, _ = http.NewRequest("GET", "/", strings.NewReader(""))
897+ pcTest.req, _ = http.NewRequest(http.MethodGet, "/", strings.NewReader(""))
898898 pcTest.validateUser = true
899899 return &pcTest, nil
900900}
@@ -1027,7 +1027,7 @@ func NewUserInfoEndpointTest() (*ProcessCookieTest, error) {
10271027 if err != nil {
10281028 return nil, err
10291029 }
1030− pcTest.req, _ = http.NewRequest("GET",
1030+ pcTest.req, _ = http.NewRequest(http.MethodGet,
10311031 pcTest.opts.ProxyPrefix+"/userinfo", nil)
10321032 return pcTest, nil
10331033}
@@ -1135,7 +1135,7 @@ func NewAuthOnlyEndpointTest(querystring string, modifiers ...OptionsModifier) (
11351135 return nil, err
11361136 }
11371137 pcTest.req, _ = http.NewRequest(
1138− "GET",
1138+ http.MethodGet,
11391139 fmt.Sprintf("%s/auth%s", pcTest.opts.ProxyPrefix, querystring),
11401140 nil)
11411141 return pcTest, nil
@@ -1274,7 +1274,7 @@ func TestAuthOnlyEndpointSetXAuthRequestHeaders(t *testing.T) {
12741274 pcTest.validateUser = true
12751275
12761276 pcTest.rw = httptest.NewRecorder()
1277− pcTest.req, _ = http.NewRequest("GET",
1277+ pcTest.req, _ = http.NewRequest(http.MethodGet,
12781278 pcTest.opts.ProxyPrefix+authOnlyPath, nil)
12791279
12801280 created := time.Now()
@@ -1367,7 +1367,7 @@ func TestAuthOnlyEndpointSetBasicAuthTrueRequestHeaders(t *testing.T) {
13671367 pcTest.validateUser = true
13681368
13691369 pcTest.rw = httptest.NewRecorder()
1370− pcTest.req, _ = http.NewRequest("GET",
1370+ pcTest.req, _ = http.NewRequest(http.MethodGet,
13711371 pcTest.opts.ProxyPrefix+authOnlyPath, nil)
13721372
13731373 created := time.Now()
@@ -1447,7 +1447,7 @@ func TestAuthOnlyEndpointSetBasicAuthFalseRequestHeaders(t *testing.T) {
14471447 pcTest.validateUser = true
14481448
14491449 pcTest.rw = httptest.NewRecorder()
1450− pcTest.req, _ = http.NewRequest("GET",
1450+ pcTest.req, _ = http.NewRequest(http.MethodGet,
14511451 pcTest.opts.ProxyPrefix+authOnlyPath, nil)
14521452
14531453 created := time.Now()
@@ -1495,7 +1495,7 @@ func TestAuthSkippedForPreflightRequests(t *testing.T) {
14951495 }
14961496 proxy.provider = NewTestProvider(upstreamURL, "")
14971497 rw := httptest.NewRecorder()
1498− req, _ := http.NewRequest("OPTIONS", "/preflight-request", nil)
1498+ req, _ := http.NewRequest(http.MethodOptions, "/preflight-request", nil)
14991499 proxy.ServeHTTP(rw, req)
15001500
15011501 assert.Equal(t, 200, rw.Code)
@@ -1652,19 +1652,19 @@ func TestRequestSignature(t *testing.T) {
16521652 resp string
16531653 }{
16541654 "No request signature": {
1655− method: "GET",
1655+ method: http.MethodGet,
16561656 body: "",
16571657 key: "",
16581658 resp: "no signature received",
16591659 },
16601660 "Get request": {
1661− method: "GET",
1661+ method: http.MethodGet,
16621662 body: "",
16631663 key: "7d9e1aa87a5954e6f9fc59266b3af9d7c35fda2d",
16641664 resp: "signatures match",
16651665 },
16661666 "Post request": {
1667− method: "POST",
1667+ method: http.MethodPost,
16681668 body: `{ "hello": "world!" }`,
16691669 key: "d90df39e2d19282840252612dd7c81421a372f61",
16701670 resp: "signatures match",
@@ -2189,7 +2189,7 @@ func TestTrustedIPs(t *testing.T) {
21892189 reverseProxy: false,
21902190 realClientIPHeader: "X-Real-IP", // Default value
21912191 req: func() *http.Request {
2192− req, _ := http.NewRequest("GET", "/", nil)
2192+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
21932193 return req
21942194 }(),
21952195 expectTrusted: false,
@@ -2201,7 +2201,7 @@ func TestTrustedIPs(t *testing.T) {
22012201 reverseProxy: false,
22022202 realClientIPHeader: "X-Real-IP",
22032203 req: func() *http.Request {
2204− req, _ := http.NewRequest("GET", "/", nil)
2204+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
22052205 req.RemoteAddr = "@"
22062206 return req
22072207 }(),
@@ -2214,7 +2214,7 @@ func TestTrustedIPs(t *testing.T) {
22142214 reverseProxy: false,
22152215 realClientIPHeader: "X-Real-IP",
22162216 req: func() *http.Request {
2217− req, _ := http.NewRequest("GET", "/", nil)
2217+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
22182218 req.RemoteAddr = "@"
22192219 return req
22202220 }(),
@@ -2227,7 +2227,7 @@ func TestTrustedIPs(t *testing.T) {
22272227 reverseProxy: false,
22282228 realClientIPHeader: "X-Real-IP", // Default value
22292229 req: func() *http.Request {
2230− req, _ := http.NewRequest("GET", "/", nil)
2230+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
22312231 req.RemoteAddr = "127.0.0.1:43670"
22322232 return req
22332233 }(),
@@ -2240,7 +2240,7 @@ func TestTrustedIPs(t *testing.T) {
22402240 reverseProxy: true,
22412241 realClientIPHeader: "X-Real-IP", // Default value
22422242 req: func() *http.Request {
2243− req, _ := http.NewRequest("GET", "/", nil)
2243+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
22442244 req.RemoteAddr = "127.0.0.1:44324"
22452245 return req
22462246 }(),
@@ -2253,7 +2253,7 @@ func TestTrustedIPs(t *testing.T) {
22532253 reverseProxy: true,
22542254 realClientIPHeader: "X-Forwarded-For",
22552255 req: func() *http.Request {
2256− req, _ := http.NewRequest("GET", "/", nil)
2256+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
22572257 req.Header.Add("X-Forwarded-For", "127.0.0.1")
22582258 return req
22592259 }(),
@@ -2266,7 +2266,7 @@ func TestTrustedIPs(t *testing.T) {
22662266 reverseProxy: true,
22672267 realClientIPHeader: "X-Forwarded-For",
22682268 req: func() *http.Request {
2269− req, _ := http.NewRequest("GET", "/", nil)
2269+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
22702270 req.Header.Add("X-Forwarded-For", "::1")
22712271 return req
22722272 }(),
@@ -2279,7 +2279,7 @@ func TestTrustedIPs(t *testing.T) {
22792279 reverseProxy: true,
22802280 realClientIPHeader: "X-Forwarded-For",
22812281 req: func() *http.Request {
2282− req, _ := http.NewRequest("GET", "/", nil)
2282+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
22832283 req.Header.Add("X-Forwarded-For", "12.34.56.78")
22842284 return req
22852285 }(),
@@ -2292,7 +2292,7 @@ func TestTrustedIPs(t *testing.T) {
22922292 reverseProxy: true,
22932293 realClientIPHeader: "X-Forwarded-For",
22942294 req: func() *http.Request {
2295− req, _ := http.NewRequest("GET", "/", nil)
2295+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
22962296 req.Header.Add("X-Forwarded-For", "::2")
22972297 return req
22982298 }(),
@@ -2305,7 +2305,7 @@ func TestTrustedIPs(t *testing.T) {
23052305 reverseProxy: true,
23062306 realClientIPHeader: "X-Forwarded-For",
23072307 req: func() *http.Request {
2308− req, _ := http.NewRequest("GET", "/", nil)
2308+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
23092309 req.Header.Add("X-Real-IP", "::1")
23102310 return req
23112311 }(),
@@ -2318,7 +2318,7 @@ func TestTrustedIPs(t *testing.T) {
23182318 reverseProxy: true,
23192319 realClientIPHeader: "X-Forwarded-For",
23202320 req: func() *http.Request {
2321− req, _ := http.NewRequest("GET", "/", nil)
2321+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
23222322 req.Header.Add("X-Forwarded-For", "adsfljk29242as!!")
23232323 return req
23242324 }(),
@@ -2331,7 +2331,7 @@ func TestTrustedIPs(t *testing.T) {
23312331 reverseProxy: false,
23322332 realClientIPHeader: "X-Real-IP",
23332333 req: func() *http.Request {
2334− req, _ := http.NewRequest("GET", "/", nil)
2334+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
23352335 req.RemoteAddr = "adsfljk29242as!!"
23362336 return req
23372337 }(),
@@ -2427,12 +2427,12 @@ func Test_buildRoutesAllowlist(t *testing.T) {
24272427 },
24282428 expectedRoutes: []expectedAllowedRoute{
24292429 {
2430− method: "GET",
2430+ method: http.MethodGet,
24312431 negate: false,
24322432 regexString: "^/foo/bar",
24332433 },
24342434 {
2435− method: "POST",
2435+ method: http.MethodPost,
24362436 negate: false,
24372437 regexString: "^/baz/[0-9]+/thing",
24382438 },
@@ -2485,11 +2485,11 @@ func Test_buildRoutesAllowlist(t *testing.T) {
24852485 regexString: "^/baz/[0-9]+/thing/regex",
24862486 },
24872487 {
2488− method: "GET",
2488+ method: http.MethodGet,
24892489 regexString: "^/foo/bar",
24902490 },
24912491 {
2492− method: "POST",
2492+ method: http.MethodPost,
24932493 regexString: "^/baz/[0-9]+/thing",
24942494 },
24952495 {
@@ -2641,7 +2641,7 @@ func TestApiRoutes(t *testing.T) {
26412641
26422642 for _, tc := range testCases {
26432643 t.Run(tc.name, func(t *testing.T) {
2644− req, err := http.NewRequest("GET", tc.url, nil)
2644+ req, err := http.NewRequest(http.MethodGet, tc.url, nil)
26452645 req.Header.Set("Accept", tc.contentType)
26462646 assert.NoError(t, err)
26472647
@@ -2700,37 +2700,37 @@ func TestAllowedRequest(t *testing.T) {
27002700 }{
27012701 {
27022702 name: "Regex GET allowed",
2703− method: "GET",
2703+ method: http.MethodGet,
27042704 url: "/skip/auth/regex",
27052705 allowed: true,
27062706 },
27072707 {
27082708 name: "Regex POST allowed ",
2709− method: "POST",
2709+ method: http.MethodPost,
27102710 url: "/skip/auth/regex",
27112711 allowed: true,
27122712 },
27132713 {
27142714 name: "Regex denied",
2715− method: "GET",
2715+ method: http.MethodGet,
27162716 url: "/wrong/denied",
27172717 allowed: false,
27182718 },
27192719 {
27202720 name: "Regex allowed with fragment-free path",
2721− method: "GET",
2721+ method: http.MethodGet,
27222722 url: "/public/legit/endpoint",
27232723 allowed: true,
27242724 },
27252725 {
27262726 name: "Regex denied when path contains encoded fragment suffix",
2727− method: "GET",
2727+ method: http.MethodGet,
27282728 url: "/public/secret%23/endpoint",
27292729 allowed: false,
27302730 },
27312731 {
27322732 name: "Route allowed",
2733− method: "GET",
2733+ method: http.MethodGet,
27342734 url: "/skip/auth/routes/get",
27352735 allowed: true,
27362736 },
@@ -2742,25 +2742,25 @@ func TestAllowedRequest(t *testing.T) {
27422742 },
27432743 {
27442744 name: "Route denied with wrong path",
2745− method: "GET",
2745+ method: http.MethodGet,
27462746 url: "/skip/auth/routes/wrong/path",
27472747 allowed: false,
27482748 },
27492749 {
27502750 name: "Route denied with wrong path and method",
2751− method: "POST",
2751+ method: http.MethodPost,
27522752 url: "/skip/auth/routes/wrong/path",
27532753 allowed: false,
27542754 },
27552755 {
27562756 name: "Route allowed with fragment-free path",
2757− method: "GET",
2757+ method: http.MethodGet,
27582758 url: "/foo/public/bar",
27592759 allowed: true,
27602760 },
27612761 {
27622762 name: "Route denied when path contains encoded fragment suffix",
2763− method: "GET",
2763+ method: http.MethodGet,
27642764 url: "/foo/secret%23/bar",
27652765 allowed: false,
27662766 },
@@ -2825,37 +2825,37 @@ func TestAllowedRequestWithForwardedUriHeader(t *testing.T) {
28252825 }{
28262826 {
28272827 name: "Regex GET allowed",
2828− method: "GET",
2828+ method: http.MethodGet,
28292829 url: "/skip/auth/regex",
28302830 allowed: true,
28312831 },
28322832 {
28332833 name: "Regex POST allowed ",
2834− method: "POST",
2834+ method: http.MethodPost,
28352835 url: "/skip/auth/regex",
28362836 allowed: true,
28372837 },
28382838 {
28392839 name: "Regex denied",
2840− method: "GET",
2840+ method: http.MethodGet,
28412841 url: "/wrong/denied",
28422842 allowed: false,
28432843 },
28442844 {
28452845 name: "Regex allowed with fragment-free path",
2846− method: "GET",
2846+ method: http.MethodGet,
28472847 url: "/public/legit/endpoint",
28482848 allowed: true,
28492849 },
28502850 {
28512851 name: "Regex denied when X-Forwarded-Uri contains an encoded fragment suffix",
2852− method: "GET",
2852+ method: http.MethodGet,
28532853 url: "/public/secret%23/endpoint",
28542854 allowed: false,
28552855 },
28562856 {
28572857 name: "Route allowed",
2858− method: "GET",
2858+ method: http.MethodGet,
28592859 url: "/skip/auth/routes/get",
28602860 allowed: true,
28612861 },
@@ -2867,25 +2867,25 @@ func TestAllowedRequestWithForwardedUriHeader(t *testing.T) {
28672867 },
28682868 {
28692869 name: "Route denied with wrong path",
2870− method: "GET",
2870+ method: http.MethodGet,
28712871 url: "/skip/auth/routes/wrong/path",
28722872 allowed: false,
28732873 },
28742874 {
28752875 name: "Route denied with wrong path and method",
2876− method: "POST",
2876+ method: http.MethodPost,
28772877 url: "/skip/auth/routes/wrong/path",
28782878 allowed: false,
28792879 },
28802880 {
28812881 name: "Route allowed with fragment-free path",
2882− method: "GET",
2882+ method: http.MethodGet,
28832883 url: "/foo/public/bar",
28842884 allowed: true,
28852885 },
28862886 {
28872887 name: "Route denied when X-Forwarded-Uri contains an encoded fragment suffix",
2888− method: "GET",
2888+ method: http.MethodGet,
28892889 url: "/foo/secret%23/bar",
28902890 allowed: false,
28912891 },
@@ -2986,37 +2986,37 @@ func TestAllowedRequestNegateWithoutMethod(t *testing.T) {
29862986 }{
29872987 {
29882988 name: "Some static file allowed",
2989− method: "GET",
2989+ method: http.MethodGet,
29902990 url: "/static/file.txt",
29912991 allowed: true,
29922992 },
29932993 {
29942994 name: "POST to contact form allowed",
2995− method: "POST",
2995+ method: http.MethodPost,
29962996 url: "/contact",
29972997 allowed: true,
29982998 },
29992999 {
30003000 name: "Regex POST allowed",
3001− method: "POST",
3001+ method: http.MethodPost,
30023002 url: "/api/public-entity",
30033003 allowed: true,
30043004 },
30053005 {
30063006 name: "Regex POST with trailing slash allowed",
3007− method: "POST",
3007+ method: http.MethodPost,
30083008 url: "/api/public-entity/",
30093009 allowed: true,
30103010 },
30113011 {
30123012 name: "Regex GET api route denied",
3013− method: "GET",
3013+ method: http.MethodGet,
30143014 url: "/api/users",
30153015 allowed: false,
30163016 },
30173017 {
30183018 name: "Regex POST api route denied",
3019− method: "POST",
3019+ method: http.MethodPost,
30203020 url: "/api/users",
30213021 allowed: false,
30223022 },
@@ -3086,37 +3086,37 @@ func TestAllowedRequestNegateWithMethod(t *testing.T) {
30863086 }{
30873087 {
30883088 name: "Some static file allowed",
3089− method: "GET",
3089+ method: http.MethodGet,
30903090 url: "/static/file.txt",
30913091 allowed: true,
30923092 },
30933093 {
30943094 name: "POST to contact form not allowed",
3095− method: "POST",
3095+ method: http.MethodPost,
30963096 url: "/contact",
30973097 allowed: false,
30983098 },
30993099 {
31003100 name: "Regex POST allowed",
3101− method: "POST",
3101+ method: http.MethodPost,
31023102 url: "/api/public-entity",
31033103 allowed: true,
31043104 },
31053105 {
31063106 name: "Regex POST with trailing slash allowed",
3107− method: "POST",
3107+ method: http.MethodPost,
31083108 url: "/api/public-entity/",
31093109 allowed: true,
31103110 },
31113111 {
31123112 name: "Regex GET api route denied",
3113− method: "GET",
3113+ method: http.MethodGet,
31143114 url: "/api/users",
31153115 allowed: false,
31163116 },
31173117 {
31183118 name: "Regex POST api route denied",
3119− method: "POST",
3119+ method: http.MethodPost,
31203120 url: "/api/users",
31213121 allowed: false,
31223122 },
@@ -3256,7 +3256,7 @@ func TestProxyAllowedGroups(t *testing.T) {
32563256 t.Fatal(err)
32573257 }
32583258
3259− test.req, _ = http.NewRequest("GET", fmt.Sprintf("/%s", tt.querystring), nil)
3259+ test.req, _ = http.NewRequest(http.MethodGet, fmt.Sprintf("/%s", tt.querystring), nil)
32603260
32613261 test.req.Header.Add("accept", applicationJSON)
32623262 err = test.SaveSession(session)
@@ -3400,7 +3400,7 @@ func TestAuthOnlyAllowedGroupsWithSkipMethods(t *testing.T) {
34003400 {
34013401 name: "UserWithGroupSkipAuthPreflight",
34023402 groups: []string{"a", "c"},
3403− method: "OPTIONS",
3403+ method: http.MethodOptions,
34043404 ip: "1.2.3.5:43670",
34053405 withSession: true,
34063406 expectedStatusCode: http.StatusAccepted,
@@ -3408,7 +3408,7 @@ func TestAuthOnlyAllowedGroupsWithSkipMethods(t *testing.T) {
34083408 {
34093409 name: "UserWithGroupTrustedIp",
34103410 groups: []string{"a", "c"},
3411− method: "GET",
3411+ method: http.MethodGet,
34123412 ip: "1.2.3.4:43670",
34133413 withSession: true,
34143414 expectedStatusCode: http.StatusAccepted,
@@ -3416,7 +3416,7 @@ func TestAuthOnlyAllowedGroupsWithSkipMethods(t *testing.T) {
34163416 {
34173417 name: "UserWithoutGroupSkipAuthPreflight",
34183418 groups: []string{"c"},
3419− method: "OPTIONS",
3419+ method: http.MethodOptions,
34203420 ip: "1.2.3.5:43670",
34213421 withSession: true,
34223422 expectedStatusCode: http.StatusForbidden,
@@ -3424,21 +3424,21 @@ func TestAuthOnlyAllowedGroupsWithSkipMethods(t *testing.T) {
34243424 {
34253425 name: "UserWithoutGroupTrustedIp",
34263426 groups: []string{"c"},
3427− method: "GET",
3427+ method: http.MethodGet,
34283428 ip: "1.2.3.4:43670",
34293429 withSession: true,
34303430 expectedStatusCode: http.StatusForbidden,
34313431 },
34323432 {
34333433 name: "UserWithoutSessionSkipAuthPreflight",
3434− method: "OPTIONS",
3434+ method: http.MethodOptions,
34353435 ip: "1.2.3.5:43670",
34363436 withSession: false,
34373437 expectedStatusCode: http.StatusAccepted,
34383438 },
34393439 {
34403440 name: "UserWithoutSessionTrustedIp",
3441− method: "GET",
3441+ method: http.MethodGet,
34423442 ip: "1.2.3.4:43670",
34433443 withSession: false,
34443444 expectedStatusCode: http.StatusAccepted,
@@ -3790,14 +3790,14 @@ func TestIdTokenPlaceholderInSignOut(t *testing.T) {
37903790
37913791 // Save the required session
37923792 rw := httptest.NewRecorder()
3793− req, _ := http.NewRequest("GET", "/", nil)
3793+ req, _ := http.NewRequest(http.MethodGet, "/", nil)
37943794 err = proxy.sessionStore.Save(rw, req, session)
37953795 assert.NoError(t, err)
37963796
37973797 rw = httptest.NewRecorder()
37983798
37993799 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("GET", "/oauth2/sign_out?rd="+rdUrl, nil)
3800+ req, _ = http.NewRequest(http.MethodGet, "/oauth2/sign_out?rd="+rdUrl, nil)
38013801 req = middlewareapi.AddRequestScope(req, &middlewareapi.RequestScope{
38023802 RequestID: "11111111-2222-4333-8444-555555555555",
38033803 Session: session,
pkg/apis/options/load.go+1−1
@@ -145,7 +145,7 @@ func loadAndSubstituteEnvs(configFileName string) ([]byte, error) {
145145func registerFlags(v *viper.Viper, prefix string, flagSet *pflag.FlagSet, options interface{}) error {
146146 val := reflect.ValueOf(options)
147147 var typ reflect.Type
148− if val.Kind() == reflect.Ptr {
148+ if val.Kind() == reflect.Pointer {
149149 typ = val.Elem().Type()
150150 } else {
151151 typ = val.Type()
pkg/authentication/hmacauth/hmacauth_test.go+1−1
@@ -286,7 +286,7 @@ func TestSendAuthenticatedPostRequestToServer(t *testing.T) {
286286 upstream := httptest.NewServer(
287287 http.HandlerFunc(authenticator.Authenticate))
288288
289− req, err := http.NewRequest("POST", upstream.URL+"/foo/bar",
289+ req, err := http.NewRequest(http.MethodPost, upstream.URL+"/foo/bar",
290290 io.NopCloser(&fakeNetConn{reqBody: payload}))
291291 if err != nil {
292292 panic(err)
pkg/requests/builder_test.go+15−15
@@ -31,7 +31,7 @@ var _ = Describe("Builder suite", func() {
3131
3232 Context("with a basic request", func() {
3333 assertSuccessfulRequest(getBuilder, testHTTPRequest{
34− Method: "GET",
34+ Method: http.MethodGet,
3535 Header: baseHeaders,
3636 Body: []byte{},
3737 RequestURI: "/json/path",
@@ -52,7 +52,7 @@ var _ = Describe("Builder suite", func() {
5252 })
5353
5454 assertSuccessfulRequest(getBuilder, testHTTPRequest{
55− Method: "GET",
55+ Method: http.MethodGet,
5656 Header: baseHeaders,
5757 Body: []byte{},
5858 RequestURI: "/json/path",
@@ -78,7 +78,7 @@ var _ = Describe("Builder suite", func() {
7878 })
7979
8080 assertSuccessfulRequest(getBuilder, testHTTPRequest{
81− Method: "GET",
81+ Method: http.MethodGet,
8282 Header: header,
8383 Body: []byte(body),
8484 RequestURI: "/json/path",
@@ -93,11 +93,11 @@ var _ = Describe("Builder suite", func() {
9393
9494 BeforeEach(func() {
9595 buf := bytes.NewBuffer([]byte(body))
96− b = b.WithMethod("POST").WithBody(buf)
96+ b = b.WithMethod(http.MethodPost).WithBody(buf)
9797 })
9898
9999 assertSuccessfulRequest(getBuilder, testHTTPRequest{
100− Method: "POST",
100+ Method: http.MethodPost,
101101 Header: header,
102102 Body: []byte(body),
103103 RequestURI: "/json/path",
@@ -109,11 +109,11 @@ var _ = Describe("Builder suite", func() {
109109 header.Set("Content-Length", "0")
110110
111111 BeforeEach(func() {
112− b = b.WithMethod("POST")
112+ b = b.WithMethod(http.MethodPost)
113113 })
114114
115115 assertSuccessfulRequest(getBuilder, testHTTPRequest{
116− Method: "POST",
116+ Method: http.MethodPost,
117117 Header: header,
118118 Body: []byte{},
119119 RequestURI: "/json/path",
@@ -122,11 +122,11 @@ var _ = Describe("Builder suite", func() {
122122
123123 Context("OPTIONS", func() {
124124 BeforeEach(func() {
125− b = b.WithMethod("OPTIONS")
125+ b = b.WithMethod(http.MethodOptions)
126126 })
127127
128128 assertSuccessfulRequest(getBuilder, testHTTPRequest{
129− Method: "OPTIONS",
129+ Method: http.MethodOptions,
130130 Header: baseHeaders,
131131 Body: []byte{},
132132 RequestURI: "/json/path",
@@ -152,7 +152,7 @@ var _ = Describe("Builder suite", func() {
152152 })
153153
154154 assertSuccessfulRequest(getBuilder, testHTTPRequest{
155− Method: "GET",
155+ Method: http.MethodGet,
156156 Header: header,
157157 Body: []byte{},
158158 RequestURI: "/json/path",
@@ -170,7 +170,7 @@ var _ = Describe("Builder suite", func() {
170170 })
171171
172172 assertSuccessfulRequest(getBuilder, testHTTPRequest{
173− Method: "GET",
173+ Method: http.MethodGet,
174174 Header: replacementHeaders,
175175 Body: []byte{},
176176 RequestURI: "/json/path",
@@ -190,7 +190,7 @@ var _ = Describe("Builder suite", func() {
190190 })
191191
192192 assertSuccessfulRequest(getBuilder, testHTTPRequest{
193− Method: "GET",
193+ Method: http.MethodGet,
194194 Header: replacementHeaders,
195195 Body: []byte{},
196196 RequestURI: "/json/path",
@@ -205,7 +205,7 @@ var _ = Describe("Builder suite", func() {
205205 })
206206
207207 assertSuccessfulRequest(getBuilder, testHTTPRequest{
208− Method: "GET",
208+ Method: http.MethodGet,
209209 Header: header,
210210 Body: []byte{},
211211 RequestURI: "/json/path",
@@ -219,12 +219,12 @@ var _ = Describe("Builder suite", func() {
219219 result := b.Do()
220220 Expect(result.Error()).ToNot(HaveOccurred())
221221
222− b.WithMethod("POST")
222+ b.WithMethod(http.MethodPost)
223223 })
224224
225225 Context("should not redo the request", func() {
226226 assertSuccessfulRequest(getBuilder, testHTTPRequest{
227− Method: "GET",
227+ Method: http.MethodGet,
228228 Header: baseHeaders,
229229 Body: []byte{},
230230 RequestURI: "/json/path",
providers/azure.go+2−2
@@ -166,7 +166,7 @@ func (p *AzureProvider) Redeem(ctx context.Context, redirectURL, code, codeVerif
166166
167167 err = requests.New(p.RedeemURL.String()).
168168 WithContext(ctx).
169− WithMethod("POST").
169+ WithMethod(http.MethodPost).
170170 WithBody(bytes.NewBufferString(params.Encode())).
171171 SetHeader("Content-Type", "application/x-www-form-urlencoded").
172172 Do().
@@ -334,7 +334,7 @@ func (p *AzureProvider) redeemRefreshToken(ctx context.Context, s *sessions.Sess
334334
335335 err = requests.New(p.RedeemURL.String()).
336336 WithContext(ctx).
337− WithMethod("POST").
337+ WithMethod(http.MethodPost).
338338 WithBody(bytes.NewBufferString(params.Encode())).
339339 SetHeader("Content-Type", "application/x-www-form-urlencoded").
340340 Do().
providers/google.go+2−2
@@ -219,7 +219,7 @@ func (p *GoogleProvider) Redeem(ctx context.Context, redirectURL, code, codeVeri
219219
220220 err = requests.New(p.RedeemURL.String()).
221221 WithContext(ctx).
222− WithMethod("POST").
222+ WithMethod(http.MethodPost).
223223 WithBody(bytes.NewBufferString(params.Encode())).
224224 SetHeader("Content-Type", "application/x-www-form-urlencoded").
225225 Do().
@@ -543,7 +543,7 @@ func (p *GoogleProvider) redeemRefreshToken(ctx context.Context, s *sessions.Ses
543543
544544 err = requests.New(p.RedeemURL.String()).
545545 WithContext(ctx).
546− WithMethod("POST").
546+ WithMethod(http.MethodPost).
547547 WithBody(bytes.NewBufferString(params.Encode())).
548548 SetHeader("Content-Type", "application/x-www-form-urlencoded").
549549 Do().
providers/logingov.go+2−1
@@ -8,6 +8,7 @@ import (
88 "errors"
99 "fmt"
1010 "math/big"
11+ "net/http"
1112 "net/url"
1213 "os"
1314 "time"
@@ -237,7 +238,7 @@ func (p *LoginGovProvider) Redeem(ctx context.Context, _, code, codeVerifier str
237238 }
238239 err = requests.New(p.RedeemURL.String()).
239240 WithContext(ctx).
240− WithMethod("POST").
241+ WithMethod(http.MethodPost).
241242 WithBody(bytes.NewBufferString(params.Encode())).
242243 SetHeader("Content-Type", "application/x-www-form-urlencoded").
243244 Do().
providers/ms_entra_id.go+2−1
@@ -5,6 +5,7 @@ import (
55 "context"
66 "encoding/json"
77 "fmt"
8+ "net/http"
89 "net/url"
910 "os"
1011 "regexp"
@@ -304,7 +305,7 @@ func (p *MicrosoftEntraIDProvider) checkTenantMatchesTenantList(tenant string, a
304305func (p *MicrosoftEntraIDProvider) fetchToken(ctx context.Context, params url.Values) (*oauth2.Token, error) {
305306 resp := requests.New(p.RedeemURL.String()).
306307 WithContext(ctx).
307− WithMethod("POST").
308+ WithMethod(http.MethodPost).
308309 WithBody(bytes.NewBufferString(params.Encode())).
309310 SetHeader("Content-Type", "application/x-www-form-urlencoded").
310311 Do()
providers/provider_default.go+2−1
@@ -5,6 +5,7 @@ import (
55 "context"
66 "errors"
77 "fmt"
8+ "net/http"
89 "net/url"
910
1011 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/middleware"
@@ -71,7 +72,7 @@ func (p *ProviderData) Redeem(ctx context.Context, redirectURL, code, codeVerifi
7172
7273 result := requests.New(p.RedeemURL.String()).
7374 WithContext(ctx).
74− WithMethod("POST").
75+ WithMethod(http.MethodPost).
7576 WithBody(bytes.NewBufferString(params.Encode())).
7677 SetHeader("Content-Type", "application/x-www-form-urlencoded").
7778 Do()
providers/srht.go+2−1
@@ -4,6 +4,7 @@ import (
44 "bytes"
55 "context"
66 "fmt"
7+ "net/http"
78 "net/url"
89
910 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/sessions"
@@ -75,7 +76,7 @@ func NewSourceHutProvider(p *ProviderData) *SourceHutProvider {
7576func (p *SourceHutProvider) EnrichSession(ctx context.Context, s *sessions.SessionState) error {
7677 json, err := requests.New(p.ProfileURL.String()).
7778 WithContext(ctx).
78− WithMethod("POST").
79+ WithMethod(http.MethodPost).
7980 SetHeader("Content-Type", "application/json").
8081 SetHeader("Authorization", "Bearer "+s.AccessToken).
8182 WithBody(bytes.NewBufferString(`{"query": "{ me { username, email } }"}`)).