This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
forked from arrikto/oidc-authservice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
authenticator_opaque_test.go
121 lines (110 loc) · 2.49 KB
/
authenticator_opaque_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main
import (
"testing"
)
func TestValidAccessTokenAuthn(t *testing.T) {
tests := []struct {
testName string
AccessTokenAuthnEnabled bool
AccessTokenAuthn string
success bool
}{
{
testName: "Access Token Authenticator is set to JWT",
AccessTokenAuthnEnabled: true,
AccessTokenAuthn: "jwt",
success: true,
},
{
testName: "Access Token Authenticator is set to opaque",
AccessTokenAuthnEnabled: true,
AccessTokenAuthn: "opaque",
success: true,
},
{
testName: "Access Token Authenticator is disabled",
AccessTokenAuthnEnabled: false,
AccessTokenAuthn: "whatever",
success: true,
},
{
testName: "Access Token Authenticator envvar is invalid (JWT)",
AccessTokenAuthnEnabled: true,
AccessTokenAuthn: "JWT",
success: false,
},
{
testName: "Access Token Authenticator envvar is invalid (Opaque)",
AccessTokenAuthnEnabled: true,
AccessTokenAuthn: "Opaque",
success: false,
},
}
for _, c := range tests {
t.Run(c.testName, func(t *testing.T) {
result := validAccessTokenAuthn(c.AccessTokenAuthnEnabled, c.AccessTokenAuthn)
if result != c.success {
t.Errorf("validAccessTokenAuthn result for %v is not the expected one.", c)
}
})
}
}
func TestRetrieveUserIDGroupsUserInfo(t *testing.T) {
s := &opaqueTokenAuthenticator {
userIDClaim: "preferred_username",
groupsClaim: "groups",
}
tests := []struct {
testName string
claims map[string]interface{}
success bool
}{
{
testName: "No claims",
claims: map[string]interface{}{},
success: false,
},
{
testName: "No USERID_CLAIM found",
claims: map[string]interface{}{
"bacon": "delicious",
"eggs": struct {
source string
price float64
}{"chicken", 1.75},
"steak": true,
},
success: false,
},
{
testName: "No GROUPS_CLAIM found",
claims: map[string]interface{}{
"preferred_username": "myusername",
},
success: false,
},
{
testName: "Both USERID_CLAIM and GROUPS_CLAIM exist",
claims: map[string]interface{}{
"preferred_username": "myusername",
"groups": []interface{}{
"mygroup",
"Strokes",
},
},
success: true,
},
}
for _, c := range tests {
t.Run(c.testName, func(t *testing.T) {
_, _, err:= s.retrieveUserIDGroupsClaims(c.claims)
success := true
if err != nil {
success = false
}
if success != c.success {
t.Errorf("retrieveUserIDGroupsClaims result for %v is not the expected one. Error %v", c, err)
}
})
}
}