-
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{"myuser@mail.com", "other@mail.com"},
},
}
acl := []string{"uid abc", "ounumber 5678", "mail blah@blah.com"}
assert.Equal(t, true, isAuthorized(acl, token))
acl = []string{"uid abcd", "ounumber 5678", "mail blah@blah.com"}
assert.Equal(t, false, isAuthorized(acl, token))
acl = []string{"uid abc", "ounumber 12345", "mail blah@blah.com"}
assert.Equal(t, true, isAuthorized(acl, token))
acl = []string{"uid abc", "ounumber 12345", "mail other@blah.com"}
assert.Equal(t, true, isAuthorized(acl, token))
acl = []string{"uid abc", "ounumber 12345", "mail other@blah.com"}
}
func TestIsAuthorizedAnd(t *testing.T) {
token := &AuthorizationToken{
Attributes: map[string][]string{
"uid": []string{"abc"},
"ounumber": []string{"81234", "12345"},
"mail": []string{"myuser@mail.com", "other@mail.com"},
},
}
acl := []string{"uid abc", "ounumber 5678", "mail blah@blah.com", "require-all"}
assert.Equal(t, false, isAuthorized(acl, token))
acl = []string{"uid abc", "ounumber 81234", "mail other@mail.com", "require-all"}
assert.Equal(t, true, isAuthorized(acl, token))
acl = []string{"uid abc", "ounumber 81234", "mail other@mail.coms", "require-all"}
assert.Equal(t, false, isAuthorized(acl, token))
acl = []string{"uid abc", "require-all"}
assert.Equal(t, true, isAuthorized(acl, token))
}