git.iko.soy/typeable/oauth2-proxy
on master help sign in
chore(lint): fix staticcheck issues (#3061)

* chores: fix staticcheck QF1012 Fix use of fmt.Sprintf when writing to a writer. https://staticcheck.dev/docs/checks/#QF1012 https://github.com/oauth2-proxy/oauth2-proxy/issues/3060 * chores: fix staticcheck QF1003 Use switch instead of multiple if/else. https://staticcheck.dev/docs/checks/#QF1003 https://github.com/oauth2-proxy/oauth2-proxy/issues/3060 * chores: exclude staticcheck QF1008 for now We aim to migrate golangci-lint to v2 Let's disable QF1008 (Omit embedded fields from selector expression) for now. https://staticcheck.dev/docs/checks/#QF1008 * chores: fix golangci config: run.deadline -> timeout Rename config option to match v1 documentation: deadline -> timeout. https://golangci.github.io/legacy-v1-doc/usage/configuration/#run-configuration This error has been spotted by golangci-lint v2 migration tool. * chores: fix staticcheck QF1012

commit1225d611e9979f4f37f63adf66df18f70cf700ca authorOlivier Mengué <dolmen@cpan.org> dateMon 26 May 2025, 12:29 (1 year ago) parent09f6252
4 files changed+17−12
.golangci.yml+5−1 pkg/app/pagewriter/pagewriter_test.go+3−3 providers/google_test.go+7−6 providers/ms_entra_id_test.go+2−2
.golangci.yml+5−1
@@ -1,5 +1,5 @@
11run:
2− deadline: 120s
2+ timeout: 120s
33linters:
44 enable:
55 - govet
@@ -24,6 +24,10 @@ linters:
2424 - revive
2525 disable-all: true
2626issues:
27+ exclude:
28+ # To ease migration to golangci-lint v2.1
29+ # https://staticcheck.dev/docs/checks/#QF1008
30+ - QF1008
2731 exclude-rules:
2832 - path: _test\.go
2933 linters:
pkg/app/pagewriter/pagewriter_test.go+3−3
@@ -167,7 +167,7 @@ var _ = Describe("Writer", func() {
167167 writer: &WriterFuncs{
168168 SignInPageFunc: func(rw http.ResponseWriter, req *http.Request, redirectURL string, statusCode int) {
169169 rw.WriteHeader(202)
170− rw.Write([]byte(fmt.Sprintf("%s %s", req.URL.Path, redirectURL)))
170+ fmt.Fprintf(rw, "%s %s", req.URL.Path, redirectURL)
171171 },
172172 },
173173 expectedStatus: 202,
@@ -200,7 +200,7 @@ var _ = Describe("Writer", func() {
200200 writer: &WriterFuncs{
201201 ErrorPageFunc: func(rw http.ResponseWriter, opts ErrorPageOpts) {
202202 rw.WriteHeader(503)
203− rw.Write([]byte(fmt.Sprintf("%s %s", opts.RequestID, opts.RedirectURL)))
203+ fmt.Fprintf(rw, "%s %s", opts.RequestID, opts.RedirectURL)
204204 },
205205 },
206206 expectedStatus: 503,
@@ -230,7 +230,7 @@ var _ = Describe("Writer", func() {
230230 writer: &WriterFuncs{
231231 ProxyErrorFunc: func(rw http.ResponseWriter, req *http.Request, proxyErr error) {
232232 rw.WriteHeader(503)
233− rw.Write([]byte(fmt.Sprintf("%s %v", req.URL.Path, proxyErr)))
233+ fmt.Fprintf(rw, "%s %v", req.URL.Path, proxyErr)
234234 },
235235 },
236236 expectedStatus: 503,
providers/google_test.go+7−6
@@ -237,30 +237,31 @@ func TestGoogleProviderGetEmailAddressEmailMissing(t *testing.T) {
237237
238238func TestGoogleProvider_userInGroup(t *testing.T) {
239239 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
240− if r.URL.Path == "/admin/directory/v1/groups/group@example.com/hasMember/member-in-domain@example.com" {
240+ switch r.URL.Path {
241+ case "/admin/directory/v1/groups/group@example.com/hasMember/member-in-domain@example.com":
241242 fmt.Fprintln(w, `{"isMember":true}`)
242− } else if r.URL.Path == "/admin/directory/v1/groups/group@example.com/hasMember/non-member-in-domain@example.com" {
243+ case "/admin/directory/v1/groups/group@example.com/hasMember/non-member-in-domain@example.com":
243244 fmt.Fprintln(w, `{"isMember":false}`)
244− } else if r.URL.Path == "/admin/directory/v1/groups/group@example.com/hasMember/member-out-of-domain@otherexample.com" {
245+ case "/admin/directory/v1/groups/group@example.com/hasMember/member-out-of-domain@otherexample.com":
245246 http.Error(
246247 w,
247248 `{"error":{"errors":[{"domain":"global","reason":"invalid","message":"Invalid Input: memberKey"}],"code":400,"message":"Invalid Input: memberKey"}}`,
248249 http.StatusBadRequest,
249250 )
250− } else if r.URL.Path == "/admin/directory/v1/groups/group@example.com/hasMember/non-member-out-of-domain@otherexample.com" {
251+ case "/admin/directory/v1/groups/group@example.com/hasMember/non-member-out-of-domain@otherexample.com":
251252 http.Error(
252253 w,
253254 `{"error":{"errors":[{"domain":"global","reason":"invalid","message":"Invalid Input: memberKey"}],"code":400,"message":"Invalid Input: memberKey"}}`,
254255 http.StatusBadRequest,
255256 )
256− } else if r.URL.Path == "/admin/directory/v1/groups/group@example.com/members/non-member-out-of-domain@otherexample.com" {
257+ case "/admin/directory/v1/groups/group@example.com/members/non-member-out-of-domain@otherexample.com":
257258 // note that the client currently doesn't care what this response text or code is - any error here results in failure to match the group
258259 http.Error(
259260 w,
260261 `{"kind":"admin#directory#member","etag":"12345","id":"1234567890","email":"member-out-of-domain@otherexample.com","role":"MEMBER","type":"USER","status":"ACTIVE","delivery_settings":"ALL_MAIL"}`,
261262 http.StatusNotFound,
262263 )
263− } else if r.URL.Path == "/admin/directory/v1/groups/group@example.com/members/member-out-of-domain@otherexample.com" {
264+ case "/admin/directory/v1/groups/group@example.com/members/member-out-of-domain@otherexample.com":
264265 fmt.Fprintln(w,
265266 `{"kind":"admin#directory#member","etag":"12345","id":"1234567890","email":"member-out-of-domain@otherexample.com","role":"MEMBER","type":"USER","status":"ACTIVE","delivery_settings":"ALL_MAIL"}`,
266267 )
providers/ms_entra_id_test.go+2−2
@@ -149,7 +149,7 @@ func mockGraphAPI(noGroupMemberPermissions bool) *httptest.Server {
149149
150150 } else if r.URL.Path == groupsPath && r.Method == http.MethodGet {
151151 // First page (pagination)
152− w.Write([]byte(fmt.Sprintf(`{
152+ fmt.Fprintf(w, `{
153153 "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#directoryObjects(id)",
154154 "@odata.nextLink": "http://%s/v1.0/me/transitiveMemberOf?$select=id&$top=2&$skiptoken=TEST_TOKEN",
155155 "value": [
@@ -162,7 +162,7 @@ func mockGraphAPI(noGroupMemberPermissions bool) *httptest.Server {
162162 "id": "916f0604-8a3b-4a69-bda9-06db11a8f0cd"
163163 }
164164 ]
165− }`, r.Host)))
165+ }`, r.Host)
166166 }
167167 },
168168 ))