MCPcopy
hub / github.com/golang-jwt/jwt / Test_Validator_verifyAudience

Function Test_Validator_verifyAudience

validator_test.go:332–443  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

330}
331
332func Test_Validator_verifyAudience(t *testing.T) {
333 type fields struct {
334 expectedAud []string
335 }
336 type args struct {
337 claims Claims
338 cmp []string
339 expectAllAud bool
340 }
341 tests := []struct {
342 name string
343 fields fields
344 args args
345 wantErr error
346 }{
347 {
348 name: "fail without audience when expecting one aud match",
349 fields: fields{expectedAud: []string{"example.com"}},
350 args: args{
351 claims: MapClaims{},
352 cmp: []string{"example.com"},
353 expectAllAud: false,
354 },
355 wantErr: ErrTokenRequiredClaimMissing,
356 },
357 {
358 name: "fail without audience when expecting all aud matches",
359 fields: fields{expectedAud: []string{"example.com"}},
360 args: args{
361 claims: MapClaims{},
362 cmp: []string{"example.com"},
363 expectAllAud: true,
364 },
365 wantErr: ErrTokenRequiredClaimMissing,
366 },
367 {
368 name: "good when audience matches",
369 fields: fields{expectedAud: []string{"example.com"}},
370 args: args{
371 claims: RegisteredClaims{Audience: ClaimStrings{"example.com"}},
372 cmp: []string{"example.com"},
373 expectAllAud: false,
374 },
375 wantErr: nil,
376 },
377 {
378 name: "fail when audience matches with one value",
379 fields: fields{expectedAud: []string{"example.org", "example.com"}},
380 args: args{
381 claims: RegisteredClaims{Audience: ClaimStrings{"example.com"}},
382 cmp: []string{"example.org", "example.com"},
383 expectAllAud: false,
384 },
385 wantErr: nil,
386 },
387 {
388 name: "fail when audience matches with all values",
389 fields: fields{expectedAud: []string{"example.org", "example.com"}},

Callers

nothing calls this directly

Calls 1

verifyAudienceMethod · 0.95

Tested by

no test coverage detected