Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ jobs:
run: make test

- name: Lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v7
with:
version: latest
version: v2.1.2
42 changes: 31 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
version: "2"

run:
deadline: 5m
timeout: 5m

output:
format: colored-line-number

issues:
exclude-use-default: false
exclude:
- "exported \\w+ (\\S*['.]*)([a-zA-Z'.*]*) should have comment( \\(or a comment on this block\\))? or be unexported"
- "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked"
- "package-comments: should have a package comment"
- "unused-parameter: parameter '\\w+' seems to be unused, consider removing or renaming it as _"
formats:
text:
path: stdout

linters:
enable:
- errcheck
- revive
- goimports
- govet
- misspell
- staticcheck
- unused
- unparam
exclusions:
generated: lax
rules:
- path: (.+)\.go$
text: exported \w+ (\S*['.]*)([a-zA-Z'.*]*) should have comment( \(or a comment on this block\))? or be unexported
- path: (.+)\.go$
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked
- path: (.+)\.go$
text: 'package-comments: should have a package comment'
- path: (.+)\.go$
text: 'unused-parameter: parameter ''\w+'' seems to be unused, consider removing or renaming it as _'
paths:
- third_party$
- builtin$
- examples$

formatters:
enable:
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
6 changes: 3 additions & 3 deletions cmd/oidc-example-rp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ func (s *server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
s.mux.ServeHTTP(w, req)
}

func mustRandStr(len int) string {
b := make([]byte, len)
if r, err := rand.Read(b); err != nil || r != len {
func mustRandStr(l int) string {
b := make([]byte, l)
if r, err := rand.Read(b); err != nil || r != l {
panic("error or underread from rand.Read")
}
return base64.RawURLEncoding.EncodeToString(b)
Expand Down
6 changes: 3 additions & 3 deletions core/oauth2_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func writeHTTPError(w http.ResponseWriter, req *http.Request, code int, message
type authErrorCode string

// https://tools.ietf.org/html/rfc6749#section-4.1.2.1
// nolint:unused,varcheck,deadcode
// nolint:unused
const (
authErrorCodeInvalidRequest authErrorCode = "invalid_request"
authErrorCodeUnauthorizedClient authErrorCode = "unauthorized_client"
Expand Down Expand Up @@ -168,7 +168,7 @@ func writeAuthError(w http.ResponseWriter, req *http.Request, redirectURI *url.U
// but useful when the redirect URI is configured at the client only, and not
// passed in the authorization request. If the error cannot make use of this, it
// will be ignored and the original error returned
func addRedirectToError(err error, redirectURI string) error { //nolint:unparam,unused,deadcode
func addRedirectToError(err error, redirectURI string) error { //nolint:unparam,unused
if err, ok := err.(*authError); ok {
err.RedirectURI = redirectURI
return err
Expand All @@ -179,7 +179,7 @@ func addRedirectToError(err error, redirectURI string) error { //nolint:unparam,
type bearerErrorCode string

// https://tools.ietf.org/html/rfc6750#section-3.1
// nolint:unused,varcheck,deadcode
// nolint:unused
const (
// The request is missing a required parameter, includes an unsupported
// parameter or parameter value, repeats the same parameter, uses more than
Expand Down
2 changes: 1 addition & 1 deletion core/oidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ func matchHTTPErrStatus(code int) func(error) bool {
}
}

func matchAnyErr() func(error) bool { // nolint:unused,varcheck,deadcode
func matchAnyErr() func(error) bool { // nolint:unused
return func(err error) bool {
return err != nil
}
Expand Down
8 changes: 5 additions & 3 deletions core/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ func newToken(sessID string, expires time.Time) (*corev1.UserToken, *accessToken
// token. if the user token value hashes to the same value on the server.
func tokensMatch(user *corev1.UserToken, stored *accessToken) (bool, error) {
err := bcrypt.CompareHashAndPassword(stored.Bcrypted, user.Token)
if err == nil {
switch err {
case nil:
// no error in comparison, they match
return true, nil
} else if err == bcrypt.ErrMismatchedHashAndPassword {
case bcrypt.ErrMismatchedHashAndPassword:
// they do not match, this isn't an error per se.
return false, nil
default:
return false, fmt.Errorf("failed comparing tokens: %w", err)
}
return false, fmt.Errorf("failed comparing tokens: %w", err)
}

// marshalToken returns a user-friendly version of the token. This is the base64
Expand Down
2 changes: 1 addition & 1 deletion middleware/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (s *mockOIDCServer) handleKeys(w http.ResponseWriter, r *http.Request) {

func TestMiddleware_HappyPath(t *testing.T) {
protected := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(fmt.Sprintf("sub: %s", ClaimsFromContext(r.Context()).Subject)))
_, _ = fmt.Fprintf(w, "sub: %s", ClaimsFromContext(r.Context()).Subject)
})

oidcServer, cleanupOIDCServer := startMockOIDCServer(t)
Expand Down
2 changes: 1 addition & 1 deletion oauth2/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "fmt"
type TokenErrorCode string

// https://tools.ietf.org/html/rfc6749#section-5.2
// nolint:unused,varcheck,deadcode
// nolint:unused
const (
// TokenErrorCodeInvalidRequest: The request is missing a required
// parameter, includes an unsupported parameter value (other than grant
Expand Down
2 changes: 1 addition & 1 deletion transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
return nil, errors.New("missing TokenSource")
}

token, err := t.TokenSource.Token(req.Context())
token, err := t.Token(req.Context())
if err != nil {
return nil, err
}
Expand Down
Loading