@@ -46,12 +46,13 @@ func TestVerifierDefault(t *testing.T) {
46
46
{
47
47
d : "should pass because JWT is valid" ,
48
48
c : & ValidationContext {
49
- Algorithms : []string {"HS256" },
50
- Audiences : []string {"aud-1" , "aud-2" },
51
- Issuers : []string {"iss-1" , "iss-2" },
52
- Scope : []string {"scope-1" , "scope-2" },
53
- KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
54
- ScopeStrategy : fosite .ExactScopeStrategy ,
49
+ Algorithms : []string {"HS256" },
50
+ Audiences : []string {"aud-1" , "aud-2" },
51
+ Issuers : []string {"iss-1" , "iss-2" },
52
+ Scope : []string {"scope-1" , "scope-2" },
53
+ KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
54
+ ScopeStrategy : fosite .ExactScopeStrategy ,
55
+ ScopesValidator : DefaultValidation ,
55
56
},
56
57
token : sign (jwt.MapClaims {
57
58
"sub" : "sub" ,
@@ -68,15 +69,69 @@ func TestVerifierDefault(t *testing.T) {
68
69
"scp" : []string {"scope-3" , "scope-2" , "scope-1" },
69
70
},
70
71
},
72
+ {
73
+ d : "should pass because one of scopes is valid" ,
74
+ c : & ValidationContext {
75
+ Algorithms : []string {"HS256" },
76
+ Audiences : []string {"aud-1" , "aud-2" },
77
+ Issuers : []string {"iss-1" , "iss-2" },
78
+ Scope : []string {"scope-1" , "not-scope-2" },
79
+ KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
80
+ ScopeStrategy : fosite .ExactScopeStrategy ,
81
+ ScopesValidator : AnyValidation ,
82
+ },
83
+ token : sign (jwt.MapClaims {
84
+ "sub" : "sub" ,
85
+ "exp" : now .Add (time .Hour ).Unix (),
86
+ "aud" : []string {"aud-1" , "aud-2" },
87
+ "iss" : "iss-2" ,
88
+ "scope" : []string {"scope-3" , "scope-2" , "scope-1" },
89
+ }, "file://../test/stub/jwks-hs.json" ),
90
+ expectClaims : jwt.MapClaims {
91
+ "sub" : "sub" ,
92
+ "exp" : float64 (now .Add (time .Hour ).Unix ()),
93
+ "aud" : []interface {}{"aud-1" , "aud-2" },
94
+ "iss" : "iss-2" ,
95
+ "scp" : []string {"scope-3" , "scope-2" , "scope-1" },
96
+ },
97
+ },
98
+ {
99
+ d : "should fail because one of scopes is invalid and validation is strict" ,
100
+ c : & ValidationContext {
101
+ Algorithms : []string {"HS256" },
102
+ Audiences : []string {"aud-1" , "aud-2" },
103
+ Issuers : []string {"iss-1" , "iss-2" },
104
+ Scope : []string {"scope-1" , "not-scope-2" },
105
+ KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
106
+ ScopeStrategy : fosite .ExactScopeStrategy ,
107
+ ScopesValidator : DefaultValidation ,
108
+ },
109
+ token : sign (jwt.MapClaims {
110
+ "sub" : "sub" ,
111
+ "exp" : now .Add (time .Hour ).Unix (),
112
+ "aud" : []string {"aud-1" , "aud-2" },
113
+ "iss" : "iss-2" ,
114
+ "scope" : []string {"scope-3" , "scope-2" , "scope-1" },
115
+ }, "file://../test/stub/jwks-hs.json" ),
116
+ expectClaims : jwt.MapClaims {
117
+ "sub" : "sub" ,
118
+ "exp" : float64 (now .Add (time .Hour ).Unix ()),
119
+ "aud" : []interface {}{"aud-1" , "aud-2" },
120
+ "iss" : "iss-2" ,
121
+ "scp" : []string {"scope-3" , "scope-2" , "scope-1" },
122
+ },
123
+ expectErr : true ,
124
+ },
71
125
{
72
126
d : "should pass even when scope is a string" ,
73
127
c : & ValidationContext {
74
- Algorithms : []string {"HS256" },
75
- Audiences : []string {"aud-1" , "aud-2" },
76
- Issuers : []string {"iss-1" , "iss-2" },
77
- Scope : []string {"scope-1" , "scope-2" },
78
- KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
79
- ScopeStrategy : fosite .ExactScopeStrategy ,
128
+ Algorithms : []string {"HS256" },
129
+ Audiences : []string {"aud-1" , "aud-2" },
130
+ Issuers : []string {"iss-1" , "iss-2" },
131
+ Scope : []string {"scope-1" , "scope-2" },
132
+ KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
133
+ ScopeStrategy : fosite .ExactScopeStrategy ,
134
+ ScopesValidator : DefaultValidation ,
80
135
},
81
136
token : sign (jwt.MapClaims {
82
137
"sub" : "sub" ,
@@ -96,12 +151,13 @@ func TestVerifierDefault(t *testing.T) {
96
151
{
97
152
d : "should pass when scope is keyed as scp" ,
98
153
c : & ValidationContext {
99
- Algorithms : []string {"HS256" },
100
- Audiences : []string {"aud-1" , "aud-2" },
101
- Issuers : []string {"iss-1" , "iss-2" },
102
- Scope : []string {"scope-1" , "scope-2" },
103
- KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
104
- ScopeStrategy : fosite .ExactScopeStrategy ,
154
+ Algorithms : []string {"HS256" },
155
+ Audiences : []string {"aud-1" , "aud-2" },
156
+ Issuers : []string {"iss-1" , "iss-2" },
157
+ Scope : []string {"scope-1" , "scope-2" },
158
+ KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
159
+ ScopeStrategy : fosite .ExactScopeStrategy ,
160
+ ScopesValidator : DefaultValidation ,
105
161
},
106
162
token : sign (jwt.MapClaims {
107
163
"sub" : "sub" ,
@@ -121,12 +177,13 @@ func TestVerifierDefault(t *testing.T) {
121
177
{
122
178
d : "should pass when scope is keyed as scopes" ,
123
179
c : & ValidationContext {
124
- Algorithms : []string {"HS256" },
125
- Audiences : []string {"aud-1" , "aud-2" },
126
- Issuers : []string {"iss-1" , "iss-2" },
127
- Scope : []string {"scope-1" , "scope-2" },
128
- KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
129
- ScopeStrategy : fosite .ExactScopeStrategy ,
180
+ Algorithms : []string {"HS256" },
181
+ Audiences : []string {"aud-1" , "aud-2" },
182
+ Issuers : []string {"iss-1" , "iss-2" },
183
+ Scope : []string {"scope-1" , "scope-2" },
184
+ KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
185
+ ScopeStrategy : fosite .ExactScopeStrategy ,
186
+ ScopesValidator : DefaultValidation ,
130
187
},
131
188
token : sign (jwt.MapClaims {
132
189
"sub" : "sub" ,
@@ -164,12 +221,13 @@ func TestVerifierDefault(t *testing.T) {
164
221
{
165
222
d : "should fail when algorithm does not match" ,
166
223
c : & ValidationContext {
167
- Algorithms : []string {"HS256" },
168
- Audiences : []string {"aud-1" , "aud-2" },
169
- Issuers : []string {"iss-1" , "iss-2" },
170
- Scope : []string {"scope-1" , "scope-2" },
171
- KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-rsa-single.json" )},
172
- ScopeStrategy : fosite .ExactScopeStrategy ,
224
+ Algorithms : []string {"HS256" },
225
+ Audiences : []string {"aud-1" , "aud-2" },
226
+ Issuers : []string {"iss-1" , "iss-2" },
227
+ Scope : []string {"scope-1" , "scope-2" },
228
+ KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-rsa-single.json" )},
229
+ ScopeStrategy : fosite .ExactScopeStrategy ,
230
+ ScopesValidator : DefaultValidation ,
173
231
},
174
232
token : sign (jwt.MapClaims {
175
233
"sub" : "sub" ,
@@ -183,12 +241,13 @@ func TestVerifierDefault(t *testing.T) {
183
241
{
184
242
d : "should fail when audience mismatches" ,
185
243
c : & ValidationContext {
186
- Algorithms : []string {"HS256" },
187
- Audiences : []string {"aud-1" , "aud-2" },
188
- Issuers : []string {"iss-1" , "iss-2" },
189
- Scope : []string {"scope-1" , "scope-2" },
190
- KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
191
- ScopeStrategy : fosite .ExactScopeStrategy ,
244
+ Algorithms : []string {"HS256" },
245
+ Audiences : []string {"aud-1" , "aud-2" },
246
+ Issuers : []string {"iss-1" , "iss-2" },
247
+ Scope : []string {"scope-1" , "scope-2" },
248
+ KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
249
+ ScopeStrategy : fosite .ExactScopeStrategy ,
250
+ ScopesValidator : DefaultValidation ,
192
251
},
193
252
token : sign (jwt.MapClaims {
194
253
"sub" : "sub" ,
@@ -202,12 +261,13 @@ func TestVerifierDefault(t *testing.T) {
202
261
{
203
262
d : "should fail when issuer mismatches" ,
204
263
c : & ValidationContext {
205
- Algorithms : []string {"HS256" },
206
- Audiences : []string {"aud-1" , "aud-2" },
207
- Issuers : []string {"iss-1" , "iss-2" },
208
- Scope : []string {"scope-1" , "scope-2" },
209
- KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
210
- ScopeStrategy : fosite .ExactScopeStrategy ,
264
+ Algorithms : []string {"HS256" },
265
+ Audiences : []string {"aud-1" , "aud-2" },
266
+ Issuers : []string {"iss-1" , "iss-2" },
267
+ Scope : []string {"scope-1" , "scope-2" },
268
+ KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
269
+ ScopeStrategy : fosite .ExactScopeStrategy ,
270
+ ScopesValidator : DefaultValidation ,
211
271
},
212
272
token : sign (jwt.MapClaims {
213
273
"sub" : "sub" ,
@@ -221,12 +281,13 @@ func TestVerifierDefault(t *testing.T) {
221
281
{
222
282
d : "should fail when issuer mismatches" ,
223
283
c : & ValidationContext {
224
- Algorithms : []string {"HS256" },
225
- Audiences : []string {"aud-1" , "aud-2" },
226
- Issuers : []string {"iss-1" , "iss-2" },
227
- Scope : []string {"scope-1" , "scope-2" },
228
- KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
229
- ScopeStrategy : fosite .ExactScopeStrategy ,
284
+ Algorithms : []string {"HS256" },
285
+ Audiences : []string {"aud-1" , "aud-2" },
286
+ Issuers : []string {"iss-1" , "iss-2" },
287
+ Scope : []string {"scope-1" , "scope-2" },
288
+ KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
289
+ ScopeStrategy : fosite .ExactScopeStrategy ,
290
+ ScopesValidator : DefaultValidation ,
230
291
},
231
292
token : sign (jwt.MapClaims {
232
293
"sub" : "sub" ,
@@ -240,12 +301,13 @@ func TestVerifierDefault(t *testing.T) {
240
301
{
241
302
d : "should fail when expired" ,
242
303
c : & ValidationContext {
243
- Algorithms : []string {"HS256" },
244
- Audiences : []string {"aud-1" , "aud-2" },
245
- Issuers : []string {"iss-1" , "iss-2" },
246
- Scope : []string {"scope-1" , "scope-2" },
247
- KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
248
- ScopeStrategy : fosite .ExactScopeStrategy ,
304
+ Algorithms : []string {"HS256" },
305
+ Audiences : []string {"aud-1" , "aud-2" },
306
+ Issuers : []string {"iss-1" , "iss-2" },
307
+ Scope : []string {"scope-1" , "scope-2" },
308
+ KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
309
+ ScopeStrategy : fosite .ExactScopeStrategy ,
310
+ ScopesValidator : DefaultValidation ,
249
311
},
250
312
token : sign (jwt.MapClaims {
251
313
"sub" : "sub" ,
@@ -259,12 +321,13 @@ func TestVerifierDefault(t *testing.T) {
259
321
{
260
322
d : "should fail when nbf in future" ,
261
323
c : & ValidationContext {
262
- Algorithms : []string {"HS256" },
263
- Audiences : []string {"aud-1" , "aud-2" },
264
- Issuers : []string {"iss-1" , "iss-2" },
265
- Scope : []string {"scope-1" , "scope-2" },
266
- KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
267
- ScopeStrategy : fosite .ExactScopeStrategy ,
324
+ Algorithms : []string {"HS256" },
325
+ Audiences : []string {"aud-1" , "aud-2" },
326
+ Issuers : []string {"iss-1" , "iss-2" },
327
+ Scope : []string {"scope-1" , "scope-2" },
328
+ KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
329
+ ScopeStrategy : fosite .ExactScopeStrategy ,
330
+ ScopesValidator : DefaultValidation ,
268
331
},
269
332
token : sign (jwt.MapClaims {
270
333
"sub" : "sub" ,
@@ -279,12 +342,13 @@ func TestVerifierDefault(t *testing.T) {
279
342
{
280
343
d : "should fail when iat in future" ,
281
344
c : & ValidationContext {
282
- Algorithms : []string {"HS256" },
283
- Audiences : []string {"aud-1" , "aud-2" },
284
- Issuers : []string {"iss-1" , "iss-2" },
285
- Scope : []string {"scope-1" , "scope-2" },
286
- KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
287
- ScopeStrategy : fosite .ExactScopeStrategy ,
345
+ Algorithms : []string {"HS256" },
346
+ Audiences : []string {"aud-1" , "aud-2" },
347
+ Issuers : []string {"iss-1" , "iss-2" },
348
+ Scope : []string {"scope-1" , "scope-2" },
349
+ KeyURLs : []url.URL {* x .ParseURLOrPanic ("file://../test/stub/jwks-hs.json" )},
350
+ ScopeStrategy : fosite .ExactScopeStrategy ,
351
+ ScopesValidator : DefaultValidation ,
288
352
},
289
353
token : sign (jwt.MapClaims {
290
354
"sub" : "sub" ,
0 commit comments