Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply changes from #1156 to v2 #1158

Merged
merged 1 commit into from
Jul 27, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
check-latest: true
- uses: golangci/golangci-lint-action@v6
with:
version: v1.54.2
version: v1.59
- name: Run go vet
run: |
go vet ./...
20 changes: 9 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ linters:
enable-all: true
disable:
- cyclop
- deadcode # deprecated
- depguard
- dupl
- exhaustive
- exhaustivestruct
- errorlint
- err113
- funlen
- gci
- gochecknoglobals
Expand All @@ -26,31 +25,26 @@ linters:
- gocyclo
- godot
- godox
- goerr113
- gofumpt
- golint #deprecated
- gomnd
- gosec
- govet
- interfacer # deprecated
- ifshort
- inamedparam # oh, sod off
- ireturn # No, I _LIKE_ returning interfaces
- lll
- maintidx # Do this in code review
- maligned # deprecated
- makezero
- mnd
- nakedret
- nestif
- nlreturn
- nonamedreturns # visit this back later
- nosnakecase
- paralleltest
- scopelint # deprecated
- structcheck # deprecated
- perfsprint
- tagliatelle
- testifylint # TODO: revisit when we have the chance
- testpackage
- thelper # Tests are fine
- varcheck # deprecated
- varnamelen # Short names are ok
- wrapcheck
- wsl
Expand Down Expand Up @@ -92,6 +86,10 @@ issues:
- path: cmd/jwx/jwx.go
linters:
- forbidigo
- path: /*_test.go
text: "var-naming: "
litners:
- revive

# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/lestrrat-go/jwx/v2

go 1.18
go 1.19

require (
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
Expand Down
1 change: 0 additions & 1 deletion jwe/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func uncompress(src []byte, maxBufferSize int64) ([]byte, error) {

if readErr != nil {
// if it got here, then readErr == io.EOF, we're done
//nolint:nilerr
return dst.Bytes(), nil
}
}
Expand Down
4 changes: 2 additions & 2 deletions jwk/jwk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1890,7 +1890,7 @@ func TestFetch(t *testing.T) {
return
}

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write(expected)
}))
Expand Down Expand Up @@ -2011,7 +2011,7 @@ func TestGH567(t *testing.T) {
]
}`

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set(`Content-Type`, `application/json`)
w.WriteHeader(http.StatusOK)

Expand Down
10 changes: 5 additions & 5 deletions jwk/refresh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestCache(t *testing.T) {
}
}

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
hdrs := w.Header()
hdrs.Set(`Content-Type`, `application/json`)
hdrs.Set(`Cache-Control`, `max-age=5`)
Expand Down Expand Up @@ -125,7 +125,7 @@ func TestCache(t *testing.T) {
defer cancel()

var accessCount int
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
accessCount++

key := map[string]interface{}{
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestCache(t *testing.T) {
defer cancel()

var accessCount int
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
accessCount++

key := map[string]interface{}{
Expand Down Expand Up @@ -248,7 +248,7 @@ func TestCache(t *testing.T) {
defer cancel()

var accessCount int
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
accessCount++
if accessCount > 1 && accessCount < 4 {
http.Error(w, "wait for it....", http.StatusForbidden)
Expand Down Expand Up @@ -426,7 +426,7 @@ func TestErrorSink(t *testing.T) {
})),
}
},
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Handler: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(k)
}),
Expand Down
4 changes: 2 additions & 2 deletions jws/jws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ func TestJKU(t *testing.T) {
require.NoError(t, err, `jwk.PublicKeyOf should succeed`)
set := jwk.NewSet()
set.AddKey(pubkey)
srv := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
srv := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(set)
}))
Expand Down Expand Up @@ -1384,7 +1384,7 @@ func TestJKU(t *testing.T) {
require.Equal(t, pubkey.KeyID(), key.KeyID(), `key ID should be populated`)
set.AddKey(pubkey)
}
srv := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
srv := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(set)
}))
Expand Down
17 changes: 9 additions & 8 deletions jwt/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ func TestCustomField(t *testing.T) {

func TestParseRequest(t *testing.T) {
const u = "https://github.com/lestrrat-gow/jwx/jwt"
const xauth = "X-Authorization"

privkey, _ := jwxtest.GenerateEcdsaJwk()
privkey.Set(jwk.AlgorithmKey, jwa.ES256)
Expand Down Expand Up @@ -835,7 +836,7 @@ func TestParseRequest(t *testing.T) {
Parse: func(req *http.Request) (jwt.Token, error) {
return jwt.ParseRequest(req,
jwt.WithHeaderKey("Authorization"),
jwt.WithHeaderKey("x-authorization"),
jwt.WithHeaderKey(xauth),
jwt.WithFormKey("access_token"),
jwt.WithFormKey("token"),
jwt.WithCookieKey("cookie"),
Expand Down Expand Up @@ -885,30 +886,30 @@ func TestParseRequest(t *testing.T) {
return req
},
Parse: func(req *http.Request) (jwt.Token, error) {
return jwt.ParseRequest(req, jwt.WithHeaderKey("x-authorization"), jwt.WithKey(jwa.ES256, pubkey))
return jwt.ParseRequest(req, jwt.WithHeaderKey(xauth), jwt.WithKey(jwa.ES256, pubkey))
},
Error: true,
},
{
Name: "Token in x-authorization header (w/ option)",
Name: fmt.Sprintf("Token in %s header (w/ option)", xauth),
Request: func() *http.Request {
req := httptest.NewRequest(http.MethodGet, u, nil)
req.Header.Add("x-authorization", string(signed))
req.Header.Add(xauth, string(signed))
return req
},
Parse: func(req *http.Request) (jwt.Token, error) {
return jwt.ParseRequest(req, jwt.WithHeaderKey("x-authorization"), jwt.WithKey(jwa.ES256, pubkey))
return jwt.ParseRequest(req, jwt.WithHeaderKey(xauth), jwt.WithKey(jwa.ES256, pubkey))
},
},
{
Name: "Invalid token in x-authorization header",
Name: fmt.Sprintf("Invalid token in %s header", xauth),
Request: func() *http.Request {
req := httptest.NewRequest(http.MethodGet, u, nil)
req.Header.Add("x-authorization", string(signed)+"foobarbaz")
req.Header.Add(xauth, string(signed)+"foobarbaz")
return req
},
Parse: func(req *http.Request) (jwt.Token, error) {
return jwt.ParseRequest(req, jwt.WithHeaderKey("x-authorization"), jwt.WithKey(jwa.ES256, pubkey))
return jwt.ParseRequest(req, jwt.WithHeaderKey(xauth), jwt.WithKey(jwa.ES256, pubkey))
},
Error: true,
},
Expand Down
4 changes: 2 additions & 2 deletions jwt/openid/openid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,10 @@ func TestOpenIDClaims(t *testing.T) {
t.Run(token.Name, func(t *testing.T) {
for _, value := range base {
value := value
t.Run(value.Key, func(t *testing.T) {
t.Run(value.Key, func(_ *testing.T) {
value.Check(token.Token)
})
t.Run(value.Key+" via Get()", func(t *testing.T) {
t.Run(value.Key+" via Get()", func(_ *testing.T) {
expected := value.Value
if expf := value.Expected; expf != nil {
expected = expf(value.Value)
Expand Down
Loading