-
Notifications
You must be signed in to change notification settings - Fork 3
/
plugin_test.go
43 lines (40 loc) · 1.57 KB
/
plugin_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
package samlplugin
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestIsAuthorized(t *testing.T) {
token := &AuthorizationToken{
Attributes: map[string][]string{
"uid": []string{"abc"},
"ounumber": []string{"81234", "12345"},
"mail": []string{"[email protected]", "[email protected]"},
},
}
acl := []string{"uid abc", "ounumber 5678", "mail [email protected]"}
assert.Equal(t, true, isAuthorized(acl, token))
acl = []string{"uid abcd", "ounumber 5678", "mail [email protected]"}
assert.Equal(t, false, isAuthorized(acl, token))
acl = []string{"uid abc", "ounumber 12345", "mail [email protected]"}
assert.Equal(t, true, isAuthorized(acl, token))
acl = []string{"uid abc", "ounumber 12345", "mail [email protected]"}
assert.Equal(t, true, isAuthorized(acl, token))
acl = []string{"uid abc", "ounumber 12345", "mail [email protected]"}
}
func TestIsAuthorizedAnd(t *testing.T) {
token := &AuthorizationToken{
Attributes: map[string][]string{
"uid": []string{"abc"},
"ounumber": []string{"81234", "12345"},
"mail": []string{"[email protected]", "[email protected]"},
},
}
acl := []string{"uid abc", "ounumber 5678", "mail [email protected]", "require-all"}
assert.Equal(t, false, isAuthorized(acl, token))
acl = []string{"uid abc", "ounumber 81234", "mail [email protected]", "require-all"}
assert.Equal(t, true, isAuthorized(acl, token))
acl = []string{"uid abc", "ounumber 81234", "mail [email protected]", "require-all"}
assert.Equal(t, false, isAuthorized(acl, token))
acl = []string{"uid abc", "require-all"}
assert.Equal(t, true, isAuthorized(acl, token))
}