-
Notifications
You must be signed in to change notification settings - Fork 0
/
access_test.go
55 lines (43 loc) · 1.29 KB
/
access_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
package main
import (
"testing"
u "github.com/iavael/goutil"
"github.com/stretchr/testify/assert"
"gopkg.in/ldap.v2"
)
type HostTest struct {
hostname string
}
func (ht HostTest) inNetGroups(_ []string) bool {
return false
}
func (ht HostTest) matchACL(acl string) bool {
return ht.hostname == acl
}
func TestAccess(t *testing.T) {
var (
assert = assert.New(t)
test *ldap.Entry
)
logger = u.NewLogger(u.FATAL, nil)
test = ldap.NewEntry("cn=test", map[string][]string{
"trustModel": {"fullAccess"},
})
assert.True(checkAccess("user", HostTest{"example.com"}, []*ldap.Entry{test}))
test = ldap.NewEntry("cn=test", map[string][]string{
"trustModel": {"byHost"},
})
assert.False(checkAccess("user", HostTest{"example.com"}, []*ldap.Entry{test}))
test = ldap.NewEntry("cn=test", map[string][]string{})
assert.False(checkAccess("user", HostTest{"example.com"}, []*ldap.Entry{test}))
test = ldap.NewEntry("cn=test", map[string][]string{
"trustModel": {"byHost"},
"accessTo": {"example.com"},
})
assert.True(checkAccess("user", HostTest{"example.com"}, []*ldap.Entry{test}))
test = ldap.NewEntry("cn=test", map[string][]string{
"trustModel": {"byHost"},
"accessTo": {"example.net"},
})
assert.False(checkAccess("user", HostTest{"example.com"}, []*ldap.Entry{test}))
}