forked from xmidt-org/scytale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basculeValidators_test.go
65 lines (58 loc) · 1.3 KB
/
basculeValidators_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/xmidt-org/bascule"
)
func TestRequirePartnerIDs(t *testing.T) {
var tests = []struct {
name string
attrMap map[string]interface{}
shouldPass bool
}{
{
name: "partnerIDs",
attrMap: map[string]interface{}{
"allowedResources": map[string]interface{}{
"allowedPartners": []string{"partner0", "partner1"},
}},
shouldPass: true,
},
{
name: "missing partnerIDs key",
attrMap: map[string]interface{}{
"allowedResources": map[string]interface{}{},
},
},
{
name: "no partnerIDs",
attrMap: map[string]interface{}{
"allowedResources": map[string]interface{}{
"allowedPartners": []string{},
},
},
},
{
name: "malformed partnerIDs field",
attrMap: map[string]interface{}{
"allowedResources": map[string]interface{}{
"allowedPartners": []int{0, 1, 2},
}},
},
}
ctx := context.Background()
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
assert := assert.New(t)
attrs := bascule.NewAttributes(test.attrMap)
token := bascule.NewToken("bearer", "client0", attrs)
err := requirePartnersJWTClaim(ctx, token)
if test.shouldPass {
assert.Nil(err)
} else {
assert.NotNil(err)
}
})
}
}