From b1004a0ecb27ba397bf5fe48d131866bf94f3b39 Mon Sep 17 00:00:00 2001 From: Dmitry Verkhoturov Date: Wed, 20 Mar 2024 11:26:35 +0100 Subject: [PATCH] fix golangci-lint errors --- _example/main.go | 2 +- auth_test.go | 2 +- avatar/localfs.go | 2 +- logger/interface.go | 2 +- middleware/auth_test.go | 8 ++++---- middleware/user_updater_test.go | 2 +- provider/apple_test.go | 4 ++-- provider/custom_server_test.go | 2 +- provider/direct_test.go | 2 +- provider/oauth1_test.go | 4 ++-- provider/oauth2_test.go | 4 ++-- provider/providers.go | 2 +- provider/telegram_test.go | 22 +++++++++++----------- token/jwt_test.go | 2 +- 14 files changed, 30 insertions(+), 30 deletions(-) diff --git a/_example/main.go b/_example/main.go index de0b9e82..2a2e42dc 100644 --- a/_example/main.go +++ b/_example/main.go @@ -311,7 +311,7 @@ func initGoauth2Srv() *goauth2.Server { srv := goauth2.NewServer(goauth2.NewConfig(), manager) - srv.SetUserAuthorizationHandler(func(w http.ResponseWriter, r *http.Request) (string, error) { + srv.SetUserAuthorizationHandler(func(_ http.ResponseWriter, r *http.Request) (string, error) { if r.Form.Get("username") != "admin" || r.Form.Get("password") != "admin" { return "", fmt.Errorf("wrong creds. Use: admin admin") } diff --git a/auth_test.go b/auth_test.go index 15b9efbe..e924f6a6 100644 --- a/auth_test.go +++ b/auth_test.go @@ -525,7 +525,7 @@ func prepService(t *testing.T) (svc *Service, teardown func()) { //nolint unpara provider.CredCheckerFunc(func(user, password string) (ok bool, err error) { return user == "dev_direct" && password == "password", nil }), - func(user string, r *http.Request) string { + func(string, *http.Request) string { return "blah" }, ) diff --git a/avatar/localfs.go b/avatar/localfs.go index f387d2f7..ee4828c0 100644 --- a/avatar/localfs.go +++ b/avatar/localfs.go @@ -89,7 +89,7 @@ func (fs *LocalFS) Remove(avatar string) error { // note: id includes .image suffix func (fs *LocalFS) List() (ids []string, err error) { err = filepath.Walk(fs.storePath, - func(path string, info os.FileInfo, err error) error { + func(_ string, info os.FileInfo, err error) error { if err != nil { return err } diff --git a/logger/interface.go b/logger/interface.go index ac43b009..85724318 100644 --- a/logger/interface.go +++ b/logger/interface.go @@ -16,7 +16,7 @@ type Func func(format string, args ...interface{}) func (f Func) Logf(format string, args ...interface{}) { f(format, args...) } // NoOp logger -var NoOp = Func(func(format string, args ...interface{}) {}) +var NoOp = Func(func(string, ...interface{}) {}) // Std logger sends to std default logger directly var Std = Func(func(format string, args ...interface{}) { log.Printf(format, args...) }) diff --git a/middleware/auth_test.go b/middleware/auth_test.go index 18208aee..b38325c8 100644 --- a/middleware/auth_test.go +++ b/middleware/auth_test.go @@ -278,7 +278,7 @@ func TestAuthJWTRefreshFailed(t *testing.T) { func TestAuthJWtBlocked(t *testing.T) { a := makeTestAuth(t) - a.Validator = token.ValidatorFunc(func(token string, claims token.Claims) bool { return false }) + a.Validator = token.ValidatorFunc(func(string, token.Claims) bool { return false }) server := httptest.NewServer(makeTestMux(t, &a, true)) defer server.Close() @@ -405,7 +405,7 @@ func TestAuthNotRequired(t *testing.T) { func TestAdminRequired(t *testing.T) { a := makeTestAuth(t) mux := http.NewServeMux() - handler := func(w http.ResponseWriter, r *http.Request) { + handler := func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(201) } mux.Handle("/auth", a.AdminOnly(http.HandlerFunc(handler))) @@ -509,7 +509,7 @@ func makeTestMux(_ *testing.T, a *Authenticator, required bool) http.Handler { if !required { authMiddleware = a.Trace } - handler := func(w http.ResponseWriter, r *http.Request) { + handler := func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(201) } mux.Handle("/auth", authMiddleware(http.HandlerFunc(handler))) @@ -533,7 +533,7 @@ func makeTestAuth(_ *testing.T) Authenticator { return Authenticator{ AdminPasswd: "123456", JWTService: j, - Validator: token.ValidatorFunc(func(token string, claims token.Claims) bool { return true }), + Validator: token.ValidatorFunc(func(string, token.Claims) bool { return true }), L: logger.Std, Providers: []provider.Service{ {Provider: provider.DirectHandler{ProviderName: "provider1"}}, diff --git a/middleware/user_updater_test.go b/middleware/user_updater_test.go index 3797ab81..f7cbf309 100644 --- a/middleware/user_updater_test.go +++ b/middleware/user_updater_test.go @@ -47,7 +47,7 @@ func TestUserUpdate(t *testing.T) { func TestUserUpdate_WithoutAuth(t *testing.T) { a := makeTestAuth(t) mux := http.NewServeMux() - handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(201) }) upd := UserUpdFunc(func(user token.User) token.User { diff --git a/provider/apple_test.go b/provider/apple_test.go index 3ed103b5..f448ae77 100644 --- a/provider/apple_test.go +++ b/provider/apple_test.go @@ -491,7 +491,7 @@ func prepareAppleOauthTest(t *testing.T, loginPort, authPort int, testToken *str ts := &http.Server{Addr: fmt.Sprintf(":%d", loginPort), Handler: http.HandlerFunc(svc.Handler)} //nolint:gosec count := 0 - useIds := []string{"myuser1", "myuser2"} // user for first ans second calls + useIDs := []string{"myuser1", "myuser2"} // user for first ans second calls oauth := &http.Server{ //nolint:gosec Addr: fmt.Sprintf(":%d", authPort), @@ -542,7 +542,7 @@ func prepareAppleOauthTest(t *testing.T, loginPort, authPort int, testToken *str "id": "%s", "name":"blah", "picture":"http://exmple.com/pic1.png" - }`, useIds[count]) + }`, useIDs[count]) count++ w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(200) diff --git a/provider/custom_server_test.go b/provider/custom_server_test.go index 3083920f..9e58732a 100644 --- a/provider/custom_server_test.go +++ b/provider/custom_server_test.go @@ -208,7 +208,7 @@ func initGoauth2Srv(t *testing.T) *goauth2.Server { srv := goauth2.NewServer(goauth2.NewConfig(), manager) - srv.SetUserAuthorizationHandler(func(w http.ResponseWriter, r *http.Request) (string, error) { + srv.SetUserAuthorizationHandler(func(_ http.ResponseWriter, r *http.Request) (string, error) { if r.ParseForm() != nil { return "", fmt.Errorf("no username and password in request") } diff --git a/provider/direct_test.go b/provider/direct_test.go index 334ceeee..213d7b09 100644 --- a/provider/direct_test.go +++ b/provider/direct_test.go @@ -109,7 +109,7 @@ func TestDirect_LoginHandlerCustomUserID(t *testing.T) { }), Issuer: "iss-test", L: logger.Std, - UserIDFunc: func(user string, r *http.Request) string { + UserIDFunc: func(user string, _ *http.Request) string { return user + "_custom_id" }, } diff --git a/provider/oauth1_test.go b/provider/oauth1_test.go index 4089803d..7a8d1182 100644 --- a/provider/oauth1_test.go +++ b/provider/oauth1_test.go @@ -230,7 +230,7 @@ func prepOauth1Test(t *testing.T, loginPort, authPort int) func() { //nolint ts := &http.Server{Addr: fmt.Sprintf(":%d", loginPort), Handler: http.HandlerFunc(svc.Handler)} //nolint:gosec count := 0 - useIds := []string{"myuser1", "myuser2"} // user for first ans second calls + useIDs := []string{"myuser1", "myuser2"} // user for first ans second calls //nolint var ( @@ -270,7 +270,7 @@ func prepOauth1Test(t *testing.T, loginPort, authPort int) func() { //nolint "id": "%s", "name":"blah", "picture":"http://exmple.com/pic1.png" - }`, useIds[count]) + }`, useIDs[count]) count++ w.Header().Set("Content-Type", "application/json; charset=utf-8") _, err := w.Write([]byte(res)) diff --git a/provider/oauth2_test.go b/provider/oauth2_test.go index d510123b..26a51a8d 100644 --- a/provider/oauth2_test.go +++ b/provider/oauth2_test.go @@ -305,7 +305,7 @@ func prepOauth2Test(t *testing.T, loginPort, authPort int, btHook BearerTokenHoo ts := &http.Server{Addr: fmt.Sprintf(":%d", loginPort), Handler: http.HandlerFunc(svc.Handler)} //nolint:gosec count := 0 - useIds := []string{"myuser1", "myuser2"} // user for first ans second calls + useIDs := []string{"myuser1", "myuser2"} // user for first ans second calls oauth := &http.Server{ //nolint:gosec Addr: fmt.Sprintf(":%d", authPort), @@ -335,7 +335,7 @@ func prepOauth2Test(t *testing.T, loginPort, authPort int, btHook BearerTokenHoo "id": "%s", "name":"blah", "picture":"http://exmple.com/pic1.png" - }`, useIds[count]) + }`, useIDs[count]) count++ w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(200) diff --git a/provider/providers.go b/provider/providers.go index 186f498f..4487b4cb 100644 --- a/provider/providers.go +++ b/provider/providers.go @@ -199,7 +199,7 @@ func NewMicrosoft(p Params) Oauth2Handler { infoURL: "https://graph.microsoft.com/v1.0/me", // non-beta doesn't provide photo for consumers yet // see https://github.com/microsoftgraph/microsoft-graph-docs/issues/3990 - mapUser: func(data UserData, b []byte) token.User { + mapUser: func(data UserData, _ []byte) token.User { userInfo := token.User{ ID: "microsoft_" + token.HashID(sha1.New(), data.Value("id")), Name: data.Value("displayName"), diff --git a/provider/telegram_test.go b/provider/telegram_test.go index 5121c7cd..6d7f7351 100644 --- a/provider/telegram_test.go +++ b/provider/telegram_test.go @@ -18,7 +18,7 @@ import ( ) // same across all tests -var botInfoFunc = func(ctx context.Context) (*botInfo, error) { +var botInfoFunc = func(context.Context) (*botInfo, error) { return &botInfo{Username: "my_auth_bot"}, nil } @@ -41,7 +41,7 @@ func TestTgLoginHandlerErrors(t *testing.T) { func TestTelegramUnconfirmedRequest(t *testing.T) { m := &TelegramAPIMock{ - GetUpdatesFunc: func(ctx context.Context) (*telegramUpdate, error) { + GetUpdatesFunc: func(context.Context) (*telegramUpdate, error) { return &telegramUpdate{}, nil }, BotInfoFunc: botInfoFunc, @@ -92,7 +92,7 @@ func TestTelegramConfirmedRequest(t *testing.T) { var mu sync.Mutex m := &TelegramAPIMock{ - GetUpdatesFunc: func(ctx context.Context) (*telegramUpdate, error) { + GetUpdatesFunc: func(context.Context) (*telegramUpdate, error) { var upd telegramUpdate mu.Lock() @@ -107,11 +107,11 @@ func TestTelegramConfirmedRequest(t *testing.T) { } return &upd, nil }, - AvatarFunc: func(ctx context.Context, userID int) (string, error) { + AvatarFunc: func(_ context.Context, userID int) (string, error) { assert.Equal(t, 313131313, userID) return "http://t.me/avatar.png", nil }, - SendFunc: func(ctx context.Context, id int, text string) error { + SendFunc: func(_ context.Context, id int, text string) error { assert.Equal(t, 313131313, id) assert.Equal(t, "success", text) return nil @@ -173,7 +173,7 @@ func TestTelegramConfirmedRequest(t *testing.T) { func TestTelegramLogout(t *testing.T) { m := &TelegramAPIMock{ - GetUpdatesFunc: func(ctx context.Context) (*telegramUpdate, error) { + GetUpdatesFunc: func(context.Context) (*telegramUpdate, error) { return &telegramUpdate{}, nil }, BotInfoFunc: botInfoFunc, @@ -209,14 +209,14 @@ func TestTelegramHandler_Name(t *testing.T) { func TestTelegram_ProcessUpdateFlow(t *testing.T) { m := &TelegramAPIMock{ - GetUpdatesFunc: func(ctx context.Context) (*telegramUpdate, error) { + GetUpdatesFunc: func(context.Context) (*telegramUpdate, error) { return &telegramUpdate{}, nil }, - SendFunc: func(ctx context.Context, id int, text string) error { + SendFunc: func(_ context.Context, id int, _ string) error { assert.Equal(t, 313131313, id) return nil }, - AvatarFunc: func(ctx context.Context, userID int) (string, error) { + AvatarFunc: func(_ context.Context, userID int) (string, error) { assert.Equal(t, 313131313, userID) return "http://t.me/avatar.png", nil }, @@ -284,7 +284,7 @@ func TestTelegram_ProcessUpdateFlow(t *testing.T) { func TestTelegram_TokenVerification(t *testing.T) { m := &TelegramAPIMock{ - GetUpdatesFunc: func(ctx context.Context) (*telegramUpdate, error) { + GetUpdatesFunc: func(context.Context) (*telegramUpdate, error) { return &telegramUpdate{}, nil }, BotInfoFunc: botInfoFunc, @@ -531,7 +531,7 @@ func TestTgAPI_Avatar(t *testing.T) { const errorResp = `{"ok":false,"error_code":400,"description":"Very bad request"}` func TestTgAPI_Error(t *testing.T) { - tg, cleanup := prepareTgAPI(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + tg, cleanup := prepareTgAPI(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusBadRequest) _, _ = w.Write([]byte(errorResp)) })) diff --git a/token/jwt_test.go b/token/jwt_test.go index e30ee137..72b810e9 100644 --- a/token/jwt_test.go +++ b/token/jwt_test.go @@ -534,7 +534,7 @@ func TestJWT_Reset(t *testing.T) { } func TestJWT_Validator(t *testing.T) { - ch := ValidatorFunc(func(token string, claims Claims) bool { + ch := ValidatorFunc(func(token string, _ Claims) bool { return token == "good" }) assert.True(t, ch.Validate("good", Claims{}))