Skip to content

Commit 7bd6571

Browse files
Update module github.com/golang-jwt/jwt/v4 to v5 (#8337)
* Update module github.com/golang-jwt/jwt/v4 to v5 | datasource | package | from | to | | ---------- | ---------------------------- | ------ | ------ | | go | github.com/golang-jwt/jwt/v4 | v4.5.2 | v5.3.0 | Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update module github.com/golang-jwt/jwt/v4 to v5 | datasource | package | from | to | | ---------- | ---------------------------- | ------ | ------ | | go | github.com/golang-jwt/jwt/v4 | v4.5.2 | v5.3.0 | Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update AWS metering to use v5 of jwt module --------- Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
1 parent 577c2ef commit 7bd6571

File tree

4 files changed

+68
-60
lines changed

4 files changed

+68
-60
lines changed

cmd/nginx-ingress/aws.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/aws/aws-sdk-go-v2/service/marketplacemetering"
1616
"github.com/aws/aws-sdk-go-v2/service/marketplacemetering/types"
1717

18-
"github.com/golang-jwt/jwt/v4"
18+
"github.com/golang-jwt/jwt/v5"
1919
)
2020

2121
var (
@@ -24,6 +24,12 @@ var (
2424
pubKeyString string
2525
)
2626

27+
var (
28+
ErrMissingProductCode = errors.New("token doesn't include the ProductCode")
29+
ErrMissingNonce = errors.New("token doesn't include the Nonce")
30+
ErrMissingKeyVersion = errors.New("token doesn't include the PublicKeyVersion")
31+
)
32+
2733
func init() {
2834
startupCheckFn = checkAWSEntitlement
2935
}
@@ -95,21 +101,18 @@ type claims struct {
95101
jwt.RegisteredClaims
96102
}
97103

98-
func (c claims) Valid() error {
104+
var _ jwt.ClaimsValidator = (*claims)(nil)
105+
106+
func (c claims) Validate() error {
99107
if c.Nonce == "" {
100-
return jwt.NewValidationError("token doesn't include the Nonce", jwt.ValidationErrorClaimsInvalid)
108+
return ErrMissingNonce
101109
}
102110
if c.ProductCode == "" {
103-
return jwt.NewValidationError("token doesn't include the ProductCode", jwt.ValidationErrorClaimsInvalid)
111+
return ErrMissingProductCode
104112
}
105113
if c.PublicKeyVersion == 0 {
106-
return jwt.NewValidationError("token doesn't include the PublicKeyVersion", jwt.ValidationErrorClaimsInvalid)
114+
return ErrMissingKeyVersion
107115
}
108-
109-
if err := c.RegisteredClaims.Valid(); err != nil {
110-
return err
111-
}
112-
113116
return nil
114117
}
115118

cmd/nginx-ingress/aws_test.go

Lines changed: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"testing"
88
"time"
99

10-
"github.com/golang-jwt/jwt/v4"
10+
"github.com/golang-jwt/jwt/v5"
1111
)
1212

1313
func TestValidClaims(t *testing.T) {
@@ -21,69 +21,72 @@ func TestValidClaims(t *testing.T) {
2121
IssuedAt: &iat,
2222
},
2323
}
24-
if err := c.Valid(); err != nil {
24+
v := jwt.NewValidator(
25+
jwt.WithIssuedAt(),
26+
)
27+
if err := v.Validate(c); err != nil {
2528
t.Fatalf("Failed to verify claims, wanted: %v got %v", nil, err)
2629
}
2730
}
2831

2932
func TestInvalidClaims(t *testing.T) {
30-
badClaims := []struct {
31-
c claims
32-
expectedError error
33+
type fields struct {
34+
leeway time.Duration
35+
timeFunc func() time.Time
36+
expectedAud string
37+
expectAllAud []string
38+
expectedIss string
39+
expectedSub string
40+
}
41+
type args struct {
42+
claims jwt.Claims
43+
}
44+
tests := []struct {
45+
name string
46+
fields fields
47+
args args
48+
wantErr error
3349
}{
3450
{
35-
claims{
36-
"",
37-
1,
38-
"nonce",
39-
jwt.RegisteredClaims{
40-
IssuedAt: jwt.NewNumericDate(time.Now().Add(time.Hour * -1)),
41-
},
42-
},
43-
errors.New("token doesn't include the ProductCode"),
51+
name: "missing ProductCode",
52+
fields: fields{},
53+
args: args{jwt.RegisteredClaims{}},
54+
wantErr: ErrMissingProductCode,
4455
},
4556
{
46-
claims{
47-
"productCode",
48-
1,
49-
"",
50-
jwt.RegisteredClaims{
51-
IssuedAt: jwt.NewNumericDate(time.Now().Add(time.Hour * -1)),
52-
},
53-
},
54-
errors.New("token doesn't include the Nonce"),
57+
name: "missing Nonce",
58+
fields: fields{},
59+
args: args{jwt.RegisteredClaims{}},
60+
wantErr: ErrMissingNonce,
5561
},
5662
{
57-
claims{
58-
"productCode",
59-
0,
60-
"nonce",
61-
jwt.RegisteredClaims{
62-
IssuedAt: jwt.NewNumericDate(time.Now().Add(time.Hour * -1)),
63-
},
64-
},
65-
errors.New("token doesn't include the PublicKeyVersion"),
63+
name: "missing PublicKeyVersion",
64+
fields: fields{},
65+
args: args{jwt.RegisteredClaims{}},
66+
wantErr: ErrMissingKeyVersion,
6667
},
6768
{
68-
claims{
69-
"test",
70-
1,
71-
"nonce",
72-
jwt.RegisteredClaims{
73-
IssuedAt: jwt.NewNumericDate(time.Now().Add(time.Hour * +2)),
74-
},
75-
},
76-
errors.New("token used before issued"),
69+
name: "iat is in the future",
70+
fields: fields{},
71+
args: args{jwt.RegisteredClaims{IssuedAt: jwt.NewNumericDate(time.Now().Add(time.Hour * +2))}},
72+
wantErr: jwt.ErrTokenUsedBeforeIssued,
7773
},
7874
}
7975

80-
for _, badC := range badClaims {
81-
82-
err := badC.c.Valid()
83-
if err == nil {
84-
t.Errorf("Valid() returned no error when it should have returned error %q", badC.expectedError)
85-
} else if err.Error() != badC.expectedError.Error() {
86-
t.Errorf("Valid() returned error %q when it should have returned error %q", err, badC.expectedError)
87-
}
76+
for _, tt := range tests {
77+
t.Run(tt.name, func(t *testing.T) {
78+
v := jwt.NewValidator(
79+
jwt.WithLeeway(tt.fields.leeway),
80+
jwt.WithTimeFunc(tt.fields.timeFunc),
81+
jwt.WithIssuedAt(),
82+
jwt.WithAudience(tt.fields.expectedAud),
83+
jwt.WithAllAudiences(tt.fields.expectAllAud...),
84+
jwt.WithIssuer(tt.fields.expectedIss),
85+
jwt.WithSubject(tt.fields.expectedSub),
86+
)
87+
if err := v.Validate(tt.args.claims); (err != nil) && !errors.Is(err, tt.wantErr) {
88+
t.Errorf("validator.Validate() error = %v, wantErr = %v", err, tt.wantErr)
89+
}
90+
})
8891
}
8992
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/cert-manager/cert-manager v1.18.2
99
github.com/dlclark/regexp2 v1.11.5
1010
github.com/gkampitakis/go-snaps v0.5.15
11-
github.com/golang-jwt/jwt/v4 v4.5.2
11+
github.com/golang-jwt/jwt/v5 v5.3.0
1212
github.com/google/go-cmp v0.7.0
1313
github.com/gruntwork-io/terratest v0.50.0
1414
github.com/jinzhu/copier v0.4.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
169169
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
170170
github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI=
171171
github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
172+
github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo=
173+
github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
172174
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
173175
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
174176
github.com/gonvenience/bunt v1.3.5 h1:wSQquifvwEWtzn27k1ngLfeLaStyt0k1b/K6TrlCNAs=

0 commit comments

Comments
 (0)