-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalidate_test.go
86 lines (78 loc) · 1.65 KB
/
validate_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
// Package oidc provides ...
package oidc
import (
"strings"
"testing"
"github.com/deepzz0/oidc/examples"
"github.com/deepzz0/oidc/protocol"
)
var cli protocol.Client
func init() {
storage := examples.NewTestStorage()
var err error
cli, err = storage.Client("test_client_id")
if err != nil {
panic(err)
}
}
func TestValidateScopes(t *testing.T) {
testcases := [][]string{
{ // all
protocol.ScopeProfile,
protocol.ScopeEmail,
protocol.ScopeAddress,
protocol.ScopePhone,
protocol.ScopeOfflineAccess,
protocol.ScopeOpenID,
},
{ // ignore unknown
protocol.ScopeProfile,
"scope1",
"scope2",
},
{}, // default scope
{ // ignore offline_access
protocol.ScopeOfflineAccess,
protocol.ScopeProfile,
},
{
protocol.ScopeOfflineAccess,
},
}
for i, v := range testcases {
var (
respTypeCode bool
prompt []string
)
if i == 4 {
respTypeCode = true
prompt = []string{
"consent",
}
}
scope, openid, offline := ValidateScopes(cli, v, []string{"scope3"}, respTypeCode, prompt)
t.Log(scope, openid, offline)
}
}
func TestValidateResponseType(t *testing.T) {
testcases := []protocol.ResponseType{
protocol.ResponseTypeCode,
protocol.ResponseTypeToken,
protocol.ResponseTypeIDToken,
protocol.ResponseTypeNone,
protocol.ResponseTypeDevice,
protocol.ResponseTypeCodeToken,
protocol.ResponseTypeCodeIDToken,
protocol.ResponseTypeTokenIDToken,
protocol.ResponseTypeCodeTokenIDToken,
"token code",
}
for _, v := range testcases {
types := strings.Fields(string(v))
typeOK, err := ValidateResponseType(cli, types)
if err != nil {
t.Fatal(err)
}
t.Log(typeOK)
}
}