@@ -10,56 +10,61 @@ func TestVerifyAud(t *testing.T) {
1010 var nilListInterface []interface {}
1111 var intListInterface interface {} = []int {1 , 2 , 3 }
1212 type test struct {
13- Name string
14- MapClaims MapClaims
15- Expected bool
16- Comparison string
17- Required bool
13+ Name string
14+ MapClaims MapClaims
15+ Expected bool
16+ Comparison []string
17+ MatchAllAud bool
18+ Required bool
1819 }
1920 tests := []test {
2021 // Matching Claim in aud
2122 // Required = true
22- {Name : "String Aud matching required" , MapClaims : MapClaims {"aud" : "example.com" }, Expected : true , Required : true , Comparison : "example.com" },
23- {Name : "[]String Aud with match required" , MapClaims : MapClaims {"aud" : []string {"example.com" , "example.example.com" }}, Expected : true , Required : true , Comparison : "example.com" },
23+ {Name : "String Aud matching required" , MapClaims : MapClaims {"aud" : "example.com" }, Expected : true , Required : true , Comparison : []string {"example.com" }},
24+ {Name : "[]String Aud with match required" , MapClaims : MapClaims {"aud" : []string {"example.com" , "example.example.com" }}, Expected : true , Required : true , Comparison : []string {"example.com" }},
25+ {Name : "[]String Aud with []match any required" , MapClaims : MapClaims {"aud" : []string {"example.com" , "example.example.com" }}, Expected : true , Required : true , Comparison : []string {"example.com" , "auth.example.com" }},
26+ {Name : "[]String Aud with []match all required" , MapClaims : MapClaims {"aud" : []string {"example.com" , "example.example.com" }}, Expected : true , Required : true , Comparison : []string {"example.com" , "example.example.com" }, MatchAllAud : true },
2427
2528 // Required = false
26- {Name : "String Aud with match not required" , MapClaims : MapClaims {"aud" : "example.com" }, Expected : true , Required : false , Comparison : "example.com" },
27- {Name : "Empty String Aud with match not required" , MapClaims : MapClaims {}, Expected : true , Required : false , Comparison : "example.com" },
28- {Name : "Empty String Aud with match not required" , MapClaims : MapClaims {"aud" : "" }, Expected : true , Required : false , Comparison : "example.com" },
29- {Name : "Nil String Aud with match not required" , MapClaims : MapClaims {"aud" : nil }, Expected : true , Required : false , Comparison : "example.com" },
29+ {Name : "String Aud with match not required" , MapClaims : MapClaims {"aud" : "example.com" }, Expected : true , Required : false , Comparison : [] string { "example.com" } },
30+ {Name : "Empty String Aud with match not required" , MapClaims : MapClaims {}, Expected : true , Required : false , Comparison : [] string { "example.com" } },
31+ {Name : "Empty String Aud with match not required" , MapClaims : MapClaims {"aud" : "" }, Expected : true , Required : false , Comparison : [] string { "example.com" } },
32+ {Name : "Nil String Aud with match not required" , MapClaims : MapClaims {"aud" : nil }, Expected : true , Required : false , Comparison : [] string { "example.com" } },
3033
31- {Name : "[]String Aud with match not required" , MapClaims : MapClaims {"aud" : []string {"example.com" , "example.example.com" }}, Expected : true , Required : false , Comparison : "example.com" },
32- {Name : "Empty []String Aud with match not required" , MapClaims : MapClaims {"aud" : []string {}}, Expected : true , Required : false , Comparison : "example.com" },
34+ {Name : "[]String Aud with match not required" , MapClaims : MapClaims {"aud" : []string {"example.com" , "example.example.com" }}, Expected : true , Required : false , Comparison : [] string { "example.com" } },
35+ {Name : "Empty []String Aud with match not required" , MapClaims : MapClaims {"aud" : []string {}}, Expected : true , Required : false , Comparison : [] string { "example.com" } },
3336
3437 // Non-Matching Claim in aud
3538 // Required = true
36- {Name : "String Aud without match required" , MapClaims : MapClaims {"aud" : "not.example.com" }, Expected : false , Required : true , Comparison : "example.com" },
37- {Name : "Empty String Aud without match required" , MapClaims : MapClaims {"aud" : "" }, Expected : false , Required : true , Comparison : "example.com" },
38- {Name : "[]String Aud without match required" , MapClaims : MapClaims {"aud" : []string {"not.example.com" , "example.example.com" }}, Expected : false , Required : true , Comparison : "example.com" },
39- {Name : "Empty []String Aud without match required" , MapClaims : MapClaims {"aud" : []string {"" }}, Expected : false , Required : true , Comparison : "example.com" },
40- {Name : "String Aud without match not required" , MapClaims : MapClaims {"aud" : "not.example.com" }, Expected : false , Required : true , Comparison : "example.com" },
41- {Name : "Empty String Aud without match not required" , MapClaims : MapClaims {"aud" : "" }, Expected : false , Required : true , Comparison : "example.com" },
42- {Name : "[]String Aud without match not required" , MapClaims : MapClaims {"aud" : []string {"not.example.com" , "example.example.com" }}, Expected : false , Required : true , Comparison : "example.com" },
39+ {Name : "String Aud without match required" , MapClaims : MapClaims {"aud" : "not.example.com" }, Expected : false , Required : true , Comparison : [] string { "example.com" } },
40+ {Name : "Empty String Aud without match required" , MapClaims : MapClaims {"aud" : "" }, Expected : false , Required : true , Comparison : [] string { "example.com" } },
41+ {Name : "[]String Aud without match required" , MapClaims : MapClaims {"aud" : []string {"not.example.com" , "example.example.com" }}, Expected : false , Required : true , Comparison : [] string { "example.com" } },
42+ {Name : "Empty []String Aud without match required" , MapClaims : MapClaims {"aud" : []string {"" }}, Expected : false , Required : true , Comparison : [] string { "example.com" } },
43+ {Name : "String Aud without match not required" , MapClaims : MapClaims {"aud" : "not.example.com" }, Expected : false , Required : true , Comparison : [] string { "example.com" } },
44+ {Name : "Empty String Aud without match not required" , MapClaims : MapClaims {"aud" : "" }, Expected : false , Required : true , Comparison : [] string { "example.com" } },
45+ {Name : "[]String Aud without match not required" , MapClaims : MapClaims {"aud" : []string {"not.example.com" , "example.example.com" }}, Expected : false , Required : true , Comparison : [] string { "example.com" } },
4346
4447 // Required = false
45- {Name : "Empty []String Aud without match required" , MapClaims : MapClaims {"aud" : []string {"" }}, Expected : true , Required : false , Comparison : "example.com" },
48+ {Name : "Empty []String Aud without match required" , MapClaims : MapClaims {"aud" : []string {"" }}, Expected : true , Required : false , Comparison : [] string { "example.com" } },
4649
4750 // []interface{}
48- {Name : "Empty []interface{} Aud without match required" , MapClaims : MapClaims {"aud" : nilListInterface }, Expected : true , Required : false , Comparison : "example.com" },
49- {Name : "[]interface{} Aud with match required" , MapClaims : MapClaims {"aud" : []interface {}{"a" , "foo" , "example.com" }}, Expected : true , Required : true , Comparison : "example.com" },
50- {Name : "[]interface{} Aud with match but invalid types" , MapClaims : MapClaims {"aud" : []interface {}{"a" , 5 , "example.com" }}, Expected : false , Required : true , Comparison : "example.com" },
51- {Name : "[]interface{} Aud int with match required" , MapClaims : MapClaims {"aud" : intListInterface }, Expected : false , Required : true , Comparison : "example.com" },
51+ {Name : "Empty []interface{} Aud without match required" , MapClaims : MapClaims {"aud" : nilListInterface }, Expected : true , Required : false , Comparison : [] string { "example.com" } },
52+ {Name : "[]interface{} Aud with match required" , MapClaims : MapClaims {"aud" : []interface {}{"a" , "foo" , "example.com" }}, Expected : true , Required : true , Comparison : [] string { "example.com" } },
53+ {Name : "[]interface{} Aud with match but invalid types" , MapClaims : MapClaims {"aud" : []interface {}{"a" , 5 , "example.com" }}, Expected : false , Required : true , Comparison : [] string { "example.com" } },
54+ {Name : "[]interface{} Aud int with match required" , MapClaims : MapClaims {"aud" : intListInterface }, Expected : false , Required : true , Comparison : [] string { "example.com" } },
5255
5356 // interface{}
54- {Name : "Empty interface{} Aud without match not required" , MapClaims : MapClaims {"aud" : nilInterface }, Expected : true , Required : false , Comparison : "example.com" },
57+ {Name : "Empty interface{} Aud without match not required" , MapClaims : MapClaims {"aud" : nilInterface }, Expected : true , Required : false , Comparison : [] string { "example.com" } },
5558 }
5659
5760 for _ , test := range tests {
5861 t .Run (test .Name , func (t * testing.T ) {
5962 var opts []ParserOption
6063
61- if test .Required {
62- opts = append (opts , WithAudience (test .Comparison ))
64+ if test .Required && test .MatchAllAud {
65+ opts = append (opts , WithAllAudiences (test .Comparison ... ))
66+ } else if test .Required {
67+ opts = append (opts , WithAudience (test .Comparison ... ))
6368 }
6469
6570 validator := NewValidator (opts ... )
0 commit comments