Skip to content

Commit

Permalink
fix golangci-lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal committed Mar 20, 2024
1 parent 109bad6 commit b1004a0
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion _example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
)
Expand Down
2 changes: 1 addition & 1 deletion avatar/localfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion logger/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...) })
8 changes: 4 additions & 4 deletions middleware/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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)))
Expand All @@ -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"}},
Expand Down
2 changes: 1 addition & 1 deletion middleware/user_updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions provider/apple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion provider/custom_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion provider/direct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
}
Expand Down
4 changes: 2 additions & 2 deletions provider/oauth1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions provider/oauth2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion provider/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
22 changes: 11 additions & 11 deletions provider/telegram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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))
}))
Expand Down
2 changes: 1 addition & 1 deletion token/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}))
Expand Down

0 comments on commit b1004a0

Please sign in to comment.