From 93dee49b25a8a22fb71f598eb717093135abe602 Mon Sep 17 00:00:00 2001 From: branchmispredictor Date: Mon, 28 Dec 2020 16:30:00 -0500 Subject: [PATCH] Fix golint errors --- .golangci.yml | 8 ++++++++ pkg/config/config.go | 2 +- pkg/modules/auth/auth.go | 9 +++------ pkg/modules/auth/auth_test.go | 1 + pkg/modules/auth/identityawareproxy/error.go | 6 +++--- .../auth/identityawareproxy/identityawareproxy.go | 6 +++--- pkg/modules/auth/identityawareproxy/middleware.go | 6 +++--- 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 967ba5d1a6..cb307aabe4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -80,3 +80,11 @@ issues: - text: "Missed string" linters: - goheader + - path: pkg/modules/auth/identityawareproxy/middleware_test.go + text: "G101:" # We don't care about hardcoded credentials in this test + linters: + - gosec + - path: pkg/modules/auth/auth.go + text: "stutters" + linters: + - golint diff --git a/pkg/config/config.go b/pkg/config/config.go index 2dfd436c5a..66394ac3a5 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -60,7 +60,7 @@ const ( AuthOpenIDRedirectURL Key = `auth.openid.redirecturl` AuthOpenIDProviders Key = `auth.openid.providers` AuthIdentityAwareProxyEnabled Key = `auth.identityawareproxy.enabled` - AuthIdentityAwareProxyJwksUri Key = `auth.identityawareproxy.jwksuri` + AuthIdentityAwareProxyJwksURI Key = `auth.identityawareproxy.jwksuri` AuthIdentityAwareProxyJwtHeader Key = `auth.identityawareproxy.jwtheader` LegalImprintURL Key = `legal.imprinturl` diff --git a/pkg/modules/auth/auth.go b/pkg/modules/auth/auth.go index 139544382c..fd03edffe7 100644 --- a/pkg/modules/auth/auth.go +++ b/pkg/modules/auth/auth.go @@ -153,7 +153,7 @@ func GetAuthFromClaims(c echo.Context) (a web.Auth, err error) { return getLinkShareFromClaims(claims) } if claims.Type == AuthTypeUser { - return getUserFromClaims(claims) + return getUserFromClaims(claims), nil } if authProvider, ok := authProviders[claims.Type]; ok { return authProvider.GetWebAuth(c, claims) @@ -178,7 +178,7 @@ func getLinkShareFromClaims(claims *AuthClaims) (share *models.LinkSharing, err } // getUserFromClaims Returns a new user from jwt claims -func getUserFromClaims(claims *AuthClaims) (u *user.User, err error) { +func getUserFromClaims(claims *AuthClaims) (u *user.User) { u = &user.User{ ID: claims.UserID, Email: claims.UserEmail, @@ -223,10 +223,7 @@ func RenewToken(s *xorm.Session, c echo.Context) (token string, err error) { return NewLinkShareJWTAuthtoken(share) } if claims.Type == AuthTypeUser { - oldUser, err := getUserFromClaims(claims) - if err != nil { - return "", err - } + oldUser := getUserFromClaims(claims) u, err := user.GetUserWithEmail(s, &user.User{ID: oldUser.ID}) if err != nil { return "", err diff --git a/pkg/modules/auth/auth_test.go b/pkg/modules/auth/auth_test.go index 40dd112ce2..0df33f0208 100644 --- a/pkg/modules/auth/auth_test.go +++ b/pkg/modules/auth/auth_test.go @@ -32,6 +32,7 @@ func TestGetOrCreateUser(t *testing.T) { u, err := GetOrCreateUserFromExternalAuth(s, "https://some.issuer", "12345", "test@example.com", "", "someUserWhoDoesNotExistYet") assert.NoError(t, err) err = s.Commit() + assert.NoError(t, err) db.AssertExists(t, "users", map[string]interface{}{ "id": u.ID, diff --git a/pkg/modules/auth/identityawareproxy/error.go b/pkg/modules/auth/identityawareproxy/error.go index 8febb04bb7..2b943b44c8 100644 --- a/pkg/modules/auth/identityawareproxy/error.go +++ b/pkg/modules/auth/identityawareproxy/error.go @@ -48,7 +48,7 @@ func (err ErrIAPTokenMissing) HTTPError() web.HTTPError { // ErrIAPPublicKeysetMissing represents a "IAPPublicKeysetMissing" kind of error. type ErrIAPPublicKeysetMissing struct { - Url string + URL string } // IsErrIAPPublicKeysetMissing checks if an error is a ErrIAPPublicKeysetMissing. @@ -58,7 +58,7 @@ func IsErrIAPPublicKeysetMissing(err error) bool { } func (err ErrIAPPublicKeysetMissing) Error() string { - return fmt.Sprintf("Failed to retrive the identity-aware proxy's signing public key at URL: %s", err.Url) + return fmt.Sprintf("Failed to retrieve the identity-aware proxy's signing public key at URL: %s", err.URL) } // ErrorCodeIAPPublicKeysetMissing holds the unique world-error code of this error @@ -66,7 +66,7 @@ const ErrorCodeIAPPublicKeysetMissing = 12002 // HTTPError holds the http error description func (err ErrIAPPublicKeysetMissing) HTTPError() web.HTTPError { - return web.HTTPError{HTTPCode: http.StatusServiceUnavailable, Code: ErrorCodeIAPPublicKeysetMissing, Message: "Failed to retrive the identity-aware proxy's signing public keys."} + return web.HTTPError{HTTPCode: http.StatusServiceUnavailable, Code: ErrorCodeIAPPublicKeysetMissing, Message: "Failed to retrieve the identity-aware proxy's signing public keys."} } // ErrIAPUserFrontendMismatch represents a "IAPUserDoesNotMatchFrontendUser" kind of error. diff --git a/pkg/modules/auth/identityawareproxy/identityawareproxy.go b/pkg/modules/auth/identityawareproxy/identityawareproxy.go index ba89eb2983..04ef02b3c0 100644 --- a/pkg/modules/auth/identityawareproxy/identityawareproxy.go +++ b/pkg/modules/auth/identityawareproxy/identityawareproxy.go @@ -52,7 +52,7 @@ func init() { // These are intentionally short lived because they can be regenerated at // any time from the IAP authn information. They are not related to // session length and are only used to provide user info to the frontend -// and a hint to auth.go to retreive auth data from the IAP. +// and a hint to auth.go to retrieve auth data from the IAP. func NewIAPUserJWTAuthtoken(u *user.User) (token string, err error) { // Set claims claims := &auth.AuthClaims{ @@ -141,11 +141,11 @@ func (c *IAPClaims) Valid() error { // Validate that expiresAt and issuedAt are set and valid (with up to 1 minute of skew) now := TimeFunc() skew := time.Minute - if c.VerifyExpiresAt(now.Add(-skew).Unix(), true) == false { + if !c.VerifyExpiresAt(now.Add(-skew).Unix(), true) { delta := now.Sub(time.Unix(c.ExpiresAt, 0)) return fmt.Errorf("token is expired by %v", delta) } - if c.VerifyIssuedAt(now.Add(skew).Unix(), true) == false { + if !c.VerifyIssuedAt(now.Add(skew).Unix(), true) { return fmt.Errorf("token used before issued") } diff --git a/pkg/modules/auth/identityawareproxy/middleware.go b/pkg/modules/auth/identityawareproxy/middleware.go index a700a296ea..e4ec0838d3 100644 --- a/pkg/modules/auth/identityawareproxy/middleware.go +++ b/pkg/modules/auth/identityawareproxy/middleware.go @@ -55,10 +55,10 @@ func (cache *iapCache) GetKeyset() (*jwk.Set, error) { } // Fetch the public key(s) from the identity-aware proxy - keyset, err := jwk.FetchHTTP(config.AuthIdentityAwareProxyJwksUri.GetString()) + keyset, err := jwk.FetchHTTP(config.AuthIdentityAwareProxyJwksURI.GetString()) if err != nil { - log.Error("Failed to retrive the identity-aware proxy's signing public key at URL %s: %v", config.AuthIdentityAwareProxyJwksUri.GetString(), err) - return nil, ErrIAPPublicKeysetMissing{Url: config.AuthIdentityAwareProxyJwksUri.GetString()} + log.Error("Failed to retrieve the identity-aware proxy's signing public key at URL %s: %v", config.AuthIdentityAwareProxyJwksURI.GetString(), err) + return nil, ErrIAPPublicKeysetMissing{URL: config.AuthIdentityAwareProxyJwksURI.GetString()} } cache.keyset = keyset return cache.keyset, nil