From 23d9eaaf09edd5ad058e564e9af6a507105c869e Mon Sep 17 00:00:00 2001 From: Daisuke Maki Date: Sat, 27 Jul 2024 12:22:26 +0900 Subject: [PATCH 1/7] Update settings around golangci-lint --- .github/workflows/lint.yml | 2 +- .golangci.yml | 19 +++++------ go.mod | 8 ++++- go.sum | 68 -------------------------------------- 4 files changed, 16 insertions(+), 81 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 702a4c5d7..5ea89ef55 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,7 +12,7 @@ jobs: check-latest: true - uses: golangci/golangci-lint-action@v6 with: - version: v1.54.2 + version: v1.54 - name: Run go vet run: | go vet ./... diff --git a/.golangci.yml b/.golangci.yml index b07a8c3bb..4063bca0f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -13,11 +13,10 @@ linters: - contextcheck - cyclop - depguard - - deadcode # deprecated - dupl - exhaustive - - exhaustivestruct - exhaustruct + - err113 - errorlint - funlen - gci @@ -28,34 +27,28 @@ linters: - gocyclo - godot - godox - - goerr113 - gofumpt - - golint #deprecated - gomnd - gomoddirectives # I think it's broken - gosec - gosmopolitan - govet - - interfacer # deprecated + - inamedparam # oh, sod off - interfacebloat - - ifshort - ireturn # No, I _LIKE_ returning interfaces - lll - maintidx # Do this in code review - - maligned # deprecated - makezero + - mnd # TODO: re-enable when we can check again - nonamedreturns - nakedret - nestif - nlreturn - - nosnakecase # deprecated - paralleltest - - scopelint # deprecated - - structcheck # deprecated + - testifylint # TODO: re-enable when we can check again - tagliatelle - testpackage - thelper # Tests are fine - - varcheck # deprecated - varnamelen # Short names are ok - wrapcheck - wsl @@ -93,6 +86,10 @@ issues: - path: cmd/jwx/jwx.go linters: - forbidigo + - path: /*_test.go + text: "var-naming: " + linters: + - revive # Maximum issues count per one linter. Set to 0 to disable. Default is 50. max-issues-per-linter: 0 diff --git a/go.mod b/go.mod index 807d1b9e6..6523e68d8 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/lestrrat-go/jwx -go 1.15 +go 1.19 require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 @@ -15,4 +15,10 @@ require ( golang.org/x/crypto v0.24.0 ) +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) + retract v1.2.16 // Packaging problems. diff --git a/go.sum b/go.sum index 3bc52c6eb..888c1d76d 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,10 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA= github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/lestrrat-go/backoff/v2 v2.0.8 h1:oNb5E5isby2kiro9AgdHLv5N5tint1AnDVVf2E2un5A= github.com/lestrrat-go/backoff/v2 v2.0.8/go.mod h1:rHP/q/r9aT27n24JQLa7JhSQZCKBBOiM/uP402WwN8Y= github.com/lestrrat-go/blackmagic v1.0.2 h1:Cg2gVSc9h7sz9NOByczrbUvLopQmXrfFx//N+AkAr5k= @@ -23,78 +21,12 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= -golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= -golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= -golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= -golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= -golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= -golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= -golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= -golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= -golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 7112f28bad39e1e23b934cb3d9ac152abec77ce7 Mon Sep 17 00:00:00 2001 From: Daisuke Maki Date: Sat, 27 Jul 2024 12:23:31 +0900 Subject: [PATCH 2/7] silence nolintlint --- jwe/compress.go | 1 - 1 file changed, 1 deletion(-) diff --git a/jwe/compress.go b/jwe/compress.go index 6956cabda..53dbd2b5a 100644 --- a/jwe/compress.go +++ b/jwe/compress.go @@ -35,7 +35,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 } } From 3396f51ad72f64ba59c700fcb4bf8493f124dd1a Mon Sep 17 00:00:00 2001 From: Daisuke Maki Date: Sat, 27 Jul 2024 12:31:15 +0900 Subject: [PATCH 3/7] Fix usage of io/ioutil --- cmd/jwx/jwe.go | 6 +++--- cmd/jwx/jwk.go | 3 +-- cmd/jwx/jws.go | 8 ++++---- cmd/jwx/jwx.go | 3 +-- internal/jwxtest/jwxtest.go | 7 +++---- jwe/jwe.go | 3 +-- jwe/jwe_test.go | 6 +++--- jwk/jwk.go | 3 +-- jws/jws.go | 5 ++--- jws/jws_test.go | 6 +++--- jwt/jwt.go | 3 +-- jwt/jwt_test.go | 6 +++--- 12 files changed, 26 insertions(+), 33 deletions(-) diff --git a/cmd/jwx/jwe.go b/cmd/jwx/jwe.go index 6dcf91708..34ab8693c 100644 --- a/cmd/jwx/jwe.go +++ b/cmd/jwx/jwe.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "io/ioutil" + "io" "github.com/lestrrat-go/jwx/jwa" "github.com/lestrrat-go/jwx/jwe" @@ -71,7 +71,7 @@ func makeJweEncryptCmd() *cli.Command { } defer src.Close() - buf, err := ioutil.ReadAll(src) + buf, err := io.ReadAll(src) if err != nil { return errors.Wrap(err, `failed to read data from source`) } @@ -139,7 +139,7 @@ func makeJweDecryptCmd() *cli.Command { } defer src.Close() - buf, err := ioutil.ReadAll(src) + buf, err := io.ReadAll(src) if err != nil { return errors.Wrap(err, `failed to read data from source`) } diff --git a/cmd/jwx/jwk.go b/cmd/jwx/jwk.go index b3616c168..1cad2afb2 100644 --- a/cmd/jwx/jwk.go +++ b/cmd/jwx/jwk.go @@ -8,7 +8,6 @@ import ( "crypto/rsa" "encoding/json" "io" - "io/ioutil" "github.com/lestrrat-go/jwx/internal/ecutil" "github.com/lestrrat-go/jwx/jwa" @@ -255,7 +254,7 @@ func makeJwkFormatCmd() *cli.Command { } defer src.Close() - buf, err := ioutil.ReadAll(src) + buf, err := io.ReadAll(src) if err != nil { return errors.Wrap(err, `failed to read data from source`) } diff --git a/cmd/jwx/jws.go b/cmd/jwx/jws.go index b7c8de190..65718357d 100644 --- a/cmd/jwx/jws.go +++ b/cmd/jwx/jws.go @@ -6,7 +6,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "os" "github.com/lestrrat-go/jwx/internal/base64" @@ -59,7 +59,7 @@ func makeJwsParseCmd() *cli.Command { } defer src.Close() - buf, err := ioutil.ReadAll(src) + buf, err := io.ReadAll(src) if err != nil { return errors.Wrap(err, `failed to read data from source`) if err != nil { @@ -198,7 +198,7 @@ func makeJwsVerifyCmd() *cli.Command { } defer src.Close() - buf, err := ioutil.ReadAll(src) + buf, err := io.ReadAll(src) if err != nil { return errors.Wrap(err, `failed to read data from source`) if err != nil { @@ -287,7 +287,7 @@ func makeJwsSignCmd() *cli.Command { } defer src.Close() - buf, err := ioutil.ReadAll(src) + buf, err := io.ReadAll(src) if err != nil { return errors.Wrap(err, `failed to read data from source`) if err != nil { diff --git a/cmd/jwx/jwx.go b/cmd/jwx/jwx.go index 6904d8201..eaa5d685d 100644 --- a/cmd/jwx/jwx.go +++ b/cmd/jwx/jwx.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "sort" "strings" @@ -77,7 +76,7 @@ func dumpJSON(dst io.Writer, v interface{}) error { func getSource(filename string) (io.ReadCloser, error) { var src io.ReadCloser if filename == "-" { - src = ioutil.NopCloser(os.Stdin) + src = io.NopCloser(os.Stdin) } else { if filename == "" { return nil, errors.New(`filename required (use "-" to read from stdin)`) diff --git a/internal/jwxtest/jwxtest.go b/internal/jwxtest/jwxtest.go index ecd52c43d..1a8a876a8 100644 --- a/internal/jwxtest/jwxtest.go +++ b/internal/jwxtest/jwxtest.go @@ -10,7 +10,6 @@ import ( "crypto/rsa" "encoding/json" "io" - "io/ioutil" "os" "strings" "testing" @@ -168,7 +167,7 @@ func WriteJSONFile(template string, v interface{}) (string, func(), error) { } func DumpFile(t *testing.T, file string) { - buf, err := ioutil.ReadFile(file) + buf, err := os.ReadFile(file) if !assert.NoError(t, err, `failed to read file %s for debugging`, file) { return } @@ -217,7 +216,7 @@ func DumpFile(t *testing.T, file string) { } func CreateTempFile(template string) (*os.File, func(), error) { - file, err := ioutil.TempFile("", template) + file, err := os.CreateTemp("", template) if err != nil { return nil, nil, errors.Wrap(err, "failed to create temporary file") } @@ -237,7 +236,7 @@ func ReadFile(file string) ([]byte, error) { } defer f.Close() - buf, err := ioutil.ReadAll(f) + buf, err := io.ReadAll(f) if err != nil { return nil, errors.Wrapf(err, `failed to read from key file %s`, file) } diff --git a/jwe/jwe.go b/jwe/jwe.go index 95c48abd0..eae1cbcc5 100644 --- a/jwe/jwe.go +++ b/jwe/jwe.go @@ -8,7 +8,6 @@ import ( "crypto/ecdsa" "crypto/rsa" "io" - "io/ioutil" "github.com/lestrrat-go/jwx/internal/base64" "github.com/lestrrat-go/jwx/internal/json" @@ -292,7 +291,7 @@ func ParseString(s string) (*Message, error) { // ParseReader is the same as Parse, but takes an io.Reader. func ParseReader(src io.Reader) (*Message, error) { - buf, err := ioutil.ReadAll(src) + buf, err := io.ReadAll(src) if err != nil { return nil, errors.Wrap(err, `failed to read from io.Reader`) } diff --git a/jwe/jwe_test.go b/jwe/jwe_test.go index 40a3d08f7..92e05c382 100644 --- a/jwe/jwe_test.go +++ b/jwe/jwe_test.go @@ -8,7 +8,7 @@ import ( "crypto/rsa" "encoding/base64" "fmt" - "io/ioutil" + "os" "strings" "testing" "time" @@ -673,8 +673,8 @@ func TestReadFile(t *testing.T) { const s = `eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ.OKOawDo13gRp2ojaHV7LFpZcgV7T6DVZKTyKOMTYUmKoTCVJRgckCL9kiMT03JGeipsEdY3mx_etLbbWSrFr05kLzcSr4qKAq7YN7e9jwQRb23nfa6c9d-StnImGyFDbSv04uVuxIp5Zms1gNxKKK2Da14B8S4rzVRltdYwam_lDp5XnZAYpQdb76FdIKLaVmqgfwX7XWRxv2322i-vDxRfqNzo_tETKzpVLzfiwQyeyPGLBIO56YJ7eObdv0je81860ppamavo35UgoRdbYaBcoh9QcfylQr66oc6vFWXRcZ_ZT2LawVCWTIy3brGPi6UklfCpIMfIjf7iGdXKHzg.48V1_ALb6US04U3b.5eym8TW_c8SuK0ltJ3rpYIzOeDQz7TALvtu6UG9oMo4vpzs9tX_EFShS8iB7j6jiSdiwkIr3ajwQzaBtQD_A.XFBoMYUZodetZdvTiFvSkQ` t.Parallel() - f, err := ioutil.TempFile("", "test-read-file-*.jwe") - if !assert.NoError(t, err, `ioutil.TempFile should succeed`) { + f, err := os.CreateTemp("", "test-read-file-*.jwe") + if !assert.NoError(t, err, `os.CreateTemp should succeed`) { return } defer f.Close() diff --git a/jwk/jwk.go b/jwk/jwk.go index 453ecf443..c3551cfe9 100644 --- a/jwk/jwk.go +++ b/jwk/jwk.go @@ -13,7 +13,6 @@ import ( "crypto/x509" "encoding/pem" "io" - "io/ioutil" "math/big" "net/http" @@ -560,7 +559,7 @@ func Parse(src []byte, options ...ParseOption) (Set, error) { func ParseReader(src io.Reader, options ...ParseOption) (Set, error) { // meh, there's no way to tell if a stream has "ended" a single // JWKs except when we encounter an EOF, so just... ReadAll - buf, err := ioutil.ReadAll(src) + buf, err := io.ReadAll(src) if err != nil { return nil, errors.Wrap(err, `failed to read from io.Reader`) } diff --git a/jws/jws.go b/jws/jws.go index 4e00b6dd5..d6325f927 100644 --- a/jws/jws.go +++ b/jws/jws.go @@ -30,7 +30,6 @@ import ( "crypto/rsa" "fmt" "io" - "io/ioutil" "net/http" "net/url" "reflect" @@ -650,13 +649,13 @@ func (ctx *verifyCtx) tryVerify(verifier Verifier, hdr Headers, buf, decodedSign return decodedPayload, nil } -// This is an "optimized" ioutil.ReadAll(). It will attempt to read +// This is an "optimized" io.ReadAll(). It will attempt to read // all of the contents from the reader IF the reader is of a certain // concrete type. func readAll(rdr io.Reader) ([]byte, bool) { switch rdr.(type) { case *bytes.Reader, *bytes.Buffer, *strings.Reader: - data, err := ioutil.ReadAll(rdr) + data, err := io.ReadAll(rdr) if err != nil { return nil, false } diff --git a/jws/jws_test.go b/jws/jws_test.go index c6cd45391..297abb5fe 100644 --- a/jws/jws_test.go +++ b/jws/jws_test.go @@ -12,10 +12,10 @@ import ( "encoding/asn1" "fmt" "io" - "io/ioutil" "math/big" "net/http" "net/http/httptest" + "os" "sort" "strings" "testing" @@ -1039,8 +1039,8 @@ func TestDecode_ES384Compact_NoSigTrim(t *testing.T) { func TestReadFile(t *testing.T) { t.Parallel() - f, err := ioutil.TempFile("", "test-read-file-*.jws") - if !assert.NoError(t, err, `ioutil.TempFile should succeed`) { + f, err := os.CreateTemp("", "test-read-file-*.jws") + if !assert.NoError(t, err, `os.CreateTemp should succeed`) { return } defer f.Close() diff --git a/jwt/jwt.go b/jwt/jwt.go index 332483362..696ff9120 100644 --- a/jwt/jwt.go +++ b/jwt/jwt.go @@ -6,7 +6,6 @@ package jwt import ( "bytes" "io" - "io/ioutil" "net/http" "strings" "sync/atomic" @@ -86,7 +85,7 @@ func Parse(s []byte, options ...ParseOption) (Token, error) { // ParseReader calls Parse against an io.Reader func ParseReader(src io.Reader, options ...ParseOption) (Token, error) { // We're going to need the raw bytes regardless. Read it. - data, err := ioutil.ReadAll(src) + data, err := io.ReadAll(src) if err != nil { return nil, errors.Wrap(err, `failed to read from token data source`) } diff --git a/jwt/jwt_test.go b/jwt/jwt_test.go index 24aa37558..8e9466e62 100644 --- a/jwt/jwt_test.go +++ b/jwt/jwt_test.go @@ -9,10 +9,10 @@ import ( "crypto/rsa" "encoding/base64" "fmt" - "io/ioutil" "net/http" "net/http/httptest" "net/url" + "os" "strconv" "strings" "sync" @@ -770,8 +770,8 @@ func TestSignTyp(t *testing.T) { func TestReadFile(t *testing.T) { t.Parallel() - f, err := ioutil.TempFile("", "test-read-file-*.jwt") - if !assert.NoError(t, err, `ioutil.TempFile should succeed`) { + f, err := os.CreateTemp("", "test-read-file-*.jwt") + if !assert.NoError(t, err, `os.CreateTemp should succeed`) { return } defer f.Close() From ccc760041e3fdcfa929bae21b16b985dfa637769 Mon Sep 17 00:00:00 2001 From: Daisuke Maki Date: Sat, 27 Jul 2024 12:33:30 +0900 Subject: [PATCH 4/7] fix unused parameters --- jwk/jwk_test.go | 4 ++-- jwk/refresh_test.go | 14 +++++++------- jws/jws_test.go | 2 +- jwt/jwt_test.go | 2 +- jwt/openid/openid_test.go | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/jwk/jwk_test.go b/jwk/jwk_test.go index b346d495b..5cd1699f4 100644 --- a/jwk/jwk_test.go +++ b/jwk/jwk_test.go @@ -1834,7 +1834,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) })) @@ -1954,7 +1954,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) diff --git a/jwk/refresh_test.go b/jwk/refresh_test.go index 4faa3a904..371381342 100644 --- a/jwk/refresh_test.go +++ b/jwk/refresh_test.go @@ -59,7 +59,7 @@ func TestAutoRefresh(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{}{ @@ -116,7 +116,7 @@ func TestAutoRefresh(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{}{ @@ -177,7 +177,7 @@ func TestAutoRefresh(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) @@ -315,13 +315,13 @@ func TestErrorSink(t *testing.T) { }{ { Name: "non-200 response", - Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + Handler: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusForbidden) }), }, { Name: "invalid JWK", - Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + Handler: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) w.Write([]byte(`{"empty": "nonthingness"}`)) }), @@ -335,7 +335,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) }), @@ -395,7 +395,7 @@ func TestAutoRefreshRace(t *testing.T) { set.Add(k) // set up a server that always success since we need to update the registered target - 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) json.NewEncoder(w).Encode(k) })) diff --git a/jws/jws_test.go b/jws/jws_test.go index 297abb5fe..ca6f2cb38 100644 --- a/jws/jws_test.go +++ b/jws/jws_test.go @@ -1694,7 +1694,7 @@ func TestJKU(t *testing.T) { } set.Add(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) })) diff --git a/jwt/jwt_test.go b/jwt/jwt_test.go index 8e9466e62..225e81005 100644 --- a/jwt/jwt_test.go +++ b/jwt/jwt_test.go @@ -386,7 +386,7 @@ func TestJWTParseVerify(t *testing.T) { return } - _, err = jwt.Parse(signed, jwt.WithKeySetProvider(jwt.KeySetProviderFunc(func(tok jwt.Token) (jwk.Set, error) { + _, err = jwt.Parse(signed, jwt.WithKeySetProvider(jwt.KeySetProviderFunc(func(_ jwt.Token) (jwk.Set, error) { return nil, errors.New(`dummy`) }))) if !assert.Error(t, err, `jwt.Parse should fail`) { diff --git a/jwt/openid/openid_test.go b/jwt/openid/openid_test.go index abbf8f524..436873ffe 100644 --- a/jwt/openid/openid_test.go +++ b/jwt/openid/openid_test.go @@ -475,10 +475,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) From 0d06c710b33226636661e8df3be19ba8714ff36e Mon Sep 17 00:00:00 2001 From: Daisuke Maki Date: Sat, 27 Jul 2024 12:36:23 +0900 Subject: [PATCH 5/7] use canonical constant --- jwt/jwt_test.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/jwt/jwt_test.go b/jwt/jwt_test.go index 225e81005..f72dff8bd 100644 --- a/jwt/jwt_test.go +++ b/jwt/jwt_test.go @@ -838,6 +838,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) @@ -865,7 +866,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.WithVerify(jwa.ES256, pubkey)) @@ -914,30 +915,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.WithVerify(jwa.ES256, pubkey)) + return jwt.ParseRequest(req, jwt.WithHeaderKey(xauth), jwt.WithVerify(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.WithVerify(jwa.ES256, pubkey)) + return jwt.ParseRequest(req, jwt.WithHeaderKey(xauth), jwt.WithVerify(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.WithVerify(jwa.ES256, pubkey)) + return jwt.ParseRequest(req, jwt.WithHeaderKey(xauth), jwt.WithVerify(jwa.ES256, pubkey)) }, Error: true, }, From 03a4419d3f37716532b6c27c3e8145db2a817c5a Mon Sep 17 00:00:00 2001 From: Daisuke Maki Date: Sat, 27 Jul 2024 12:36:55 +0900 Subject: [PATCH 6/7] disable perfsprint --- .golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yml b/.golangci.yml index 4063bca0f..632221d0b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -45,6 +45,7 @@ linters: - nestif - nlreturn - paralleltest + - perfsprint - testifylint # TODO: re-enable when we can check again - tagliatelle - testpackage From c194c1af704fa5985c9ccedcecb0ced63c5731c6 Mon Sep 17 00:00:00 2001 From: Daisuke Maki Date: Sat, 27 Jul 2024 12:40:56 +0900 Subject: [PATCH 7/7] ops, needed more recent version --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5ea89ef55..3c38e1cae 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,7 +12,7 @@ jobs: check-latest: true - uses: golangci/golangci-lint-action@v6 with: - version: v1.54 + version: v1.59 - name: Run go vet run: | go vet ./...