-
Notifications
You must be signed in to change notification settings - Fork 0
/
scope_test.go
104 lines (87 loc) · 1.62 KB
/
scope_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
package scope_test
import (
"fmt"
"testing"
"github.com/qba73/scope"
)
func TestValidOIDC_ReturnsTrueOnValidInput(t *testing.T) {
t.Parallel()
validInputs := []string{
"openid",
"openid email",
"customScope openid",
"myscope openid mysecondscope",
}
for _, v := range validInputs {
if !scope.ValidOIDC(v) {
t.Error(false)
}
}
}
func TestValidOIDC_ReturnsFalseOnInvalidInput(t *testing.T) {
t.Parallel()
validInputs := []string{
"openi",
"email",
"customScope",
}
for _, v := range validInputs {
if scope.ValidOIDC(v) {
t.Error(true)
}
}
}
func TestValid_ReturnsTrueOnValidInput(t *testing.T) {
t.Parallel()
validInputs := []string{
"abc",
"openid",
"email",
"customScope",
}
for _, v := range validInputs {
if !scope.Valid(v) {
t.Error(false)
}
}
}
func TestValid_ReturnsFalseOnInvalidInput(t *testing.T) {
t.Parallel()
invalidInputs := []string{
"\x20hello",
"open\x19id",
"email\x5c",
"custom\x22Scope",
"custom\x7f",
}
for _, v := range invalidInputs {
if scope.Valid(v) {
t.Error(true)
}
}
}
func ExampleValidOIDC_validTokens() {
fmt.Println(scope.ValidOIDC("openid myscope"))
// Output:
// true
}
func ExampleValidOIDC_invalidTokens() {
fmt.Println(scope.ValidOIDC("openid m\x7fyscope"))
// Output:
// false
}
func ExampleValidOIDC_missingRequiredToken() {
fmt.Println(scope.ValidOIDC("secondScope email"))
// Output:
// false
}
func ExampleValid_validTokens() {
fmt.Println(scope.Valid("myscope"))
// Output:
// true
}
func ExampleValid_invalidTokens() {
fmt.Println(scope.Valid("my\x18scope+second\x7fScope"))
// Output:
// false
}