forked from ory/fosite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
audience_strategy_test.go
96 lines (93 loc) · 2.24 KB
/
audience_strategy_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
package fosite
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func TestDefaultAudienceMatchingStrategy(t *testing.T) {
for k, tc := range []struct {
h []string
n []string
err bool
}{
{
h: []string{},
n: []string{},
err: false,
},
{
h: []string{"http://foo/bar"},
n: []string{},
err: false,
},
{
h: []string{},
n: []string{"http://foo/bar"},
err: true,
},
{
h: []string{"https://cloud.ory.sh/api/users"},
n: []string{"https://cloud.ory.sh/api/users"},
err: false,
},
{
h: []string{"https://cloud.ory.sh/api/users"},
n: []string{"https://cloud.ory.sh/api/users/"},
err: false,
},
{
h: []string{"https://cloud.ory.sh/api/users/"},
n: []string{"https://cloud.ory.sh/api/users/"},
err: false,
},
{
h: []string{"https://cloud.ory.sh/api/users/"},
n: []string{"https://cloud.ory.sh/api/users"},
err: false,
},
{
h: []string{"https://cloud.ory.sh/api/users"},
n: []string{"https://cloud.ory.sh/api/users/1234"},
err: false,
},
{
h: []string{"https://cloud.ory.sh/api/users"},
n: []string{"https://cloud.ory.sh/api/users", "https://cloud.ory.sh/api/users/", "https://cloud.ory.sh/api/users/1234"},
err: false,
},
{
h: []string{"https://cloud.ory.sh/api/users", "https://cloud.ory.sh/api/tenants"},
n: []string{"https://cloud.ory.sh/api/users", "https://cloud.ory.sh/api/users/", "https://cloud.ory.sh/api/users/1234", "https://cloud.ory.sh/api/tenants"},
err: false,
},
{
h: []string{"https://cloud.ory.sh/api/users"},
n: []string{"https://cloud.ory.sh/api/users1234"},
err: true,
},
{
h: []string{"https://cloud.ory.sh/api/users"},
n: []string{"http://cloud.ory.sh/api/users"},
err: true,
},
{
h: []string{"https://cloud.ory.sh/api/users"},
n: []string{"https://cloud.ory.sh:8000/api/users"},
err: true,
},
{
h: []string{"https://cloud.ory.sh/api/users"},
n: []string{"https://cloud.ory.xyz/api/users"},
err: true,
},
} {
t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) {
err := DefaultAudienceMatchingStrategy(tc.h, tc.n)
if tc.err {
require.Error(t, err)
} else {
require.NoError(t, err)
}
})
}
}