-
Notifications
You must be signed in to change notification settings - Fork 1
/
filter_test.go
95 lines (92 loc) · 3.63 KB
/
filter_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
package ldapserver_test
import (
"bytes"
"testing"
"github.com/merlinz01/ldapserver"
)
func TestFilterString(t *testing.T) {
type testCase struct {
raw []byte
str string
}
cases := []testCase{
{[]byte{0b10100000, 0x00}, "(&)"},
{[]byte{0b10100001, 0x00}, "(|)"},
{[]byte{0x87, 0x03, 0x75, 0x69, 0x64}, "(uid=*)"},
{[]byte{0xa3, 0x0b, 0x04, 0x03, 0x75, 0x69, 0x64, 0x04, 0x04, 0x6a, 0x64, 0x6f, 0x65}, "(uid=jdoe)"},
{[]byte{
0xa5, 0x26,
0x04, 0x0f, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69,
0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70,
0x04, 0x13, 0x32, 0x30, 0x31, 0x37, 0x30, 0x31, 0x30, 0x32,
0x30, 0x33, 0x30, 0x34, 0x30, 0x35, 0x2e, 0x36,
0x37, 0x38, 0x5a}, "(createTimestamp>=20170102030405.678Z)"},
{[]byte{
0xa6, 0x16,
0x04, 0x0e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x42,
0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65,
0x04, 0x04, 0x31, 0x32, 0x33, 0x34}, "(accountBalance<=1234)"},
{[]byte{0xa8, 0x11, 0x04, 0x09, 0x67, 0x69, 0x76, 0x65, 0x6e, 0x4e, 0x61, 0x6d, 0x65, 0x04, 0x04, 0x4a, 0x6f, 0x68, 0x6e}, "(givenName~=John)"},
{[]byte{0xa4, 0x0b, 0x04, 0x02, 0x63, 0x6e, 0x30, 0x05, 0x80, 0x03, 0x61, 0x62, 0x63}, "(cn=abc*)"},
{[]byte{0xa4, 0x0b, 0x04, 0x02, 0x63, 0x6e, 0x30, 0x05, 0x81, 0x03, 0x6c, 0x6d, 0x6e}, "(cn=*lmn*)"},
{[]byte{0xa4, 0x0b, 0x04, 0x02, 0x63, 0x6e, 0x30, 0x05, 0x82, 0x03, 0x78, 0x79, 0x7a}, "(cn=*xyz)"},
{[]byte{
0xa4, 0x1f, 0x04, 0x02, 0x63, 0x6e,
0x30, 0x19,
0x80, 0x03, 0x61, 0x62, 0x63,
0x81, 0x03, 0x64, 0x65, 0x66,
0x81, 0x03, 0x6c, 0x6d, 0x6e,
0x81, 0x03, 0x75, 0x76, 0x77,
0x82, 0x03, 0x78, 0x79, 0x7a}, "(cn=abc*def*lmn*uvw*xyz)"},
{[]byte{0xa9, 0x0b, 0x82, 0x03, 0x75, 0x69, 0x64, 0x83, 0x04, 0x6a, 0x64, 0x6f, 0x65}, "(uid:=jdoe)"},
{[]byte{
0xa9, 0x16,
0x81, 0x0f, 0x63, 0x61, 0x73, 0x65, 0x49, 0x67, 0x6e, 0x6f,
0x72, 0x65, 0x4d, 0x61, 0x74, 0x63, 0x68,
0x83, 0x03, 0x66, 0x6f, 0x6f}, "(:caseIgnoreMatch:=foo)"},
{[]byte{
0xa9, 0x1f,
0x81, 0x0f, 0x63, 0x61, 0x73, 0x65, 0x49, 0x67, 0x6e, 0x6f,
0x72, 0x65, 0x4d, 0x61, 0x74, 0x63, 0x68,
0x82, 0x03, 0x75, 0x69, 0x64,
0x83, 0x04, 0x6a, 0x64, 0x6f, 0x65,
0x84, 0x01, 0xff}, "(uid:dn:caseIgnoreMatch:=jdoe)"},
{[]byte{
0xa0, 0x1e,
0xa3, 0x11,
0x04, 0x09, 0x67, 0x69, 0x76, 0x65, 0x6e, 0x4e, 0x61, 0x6d, 0x65,
0x04, 0x04, 0x4a, 0x6f, 0x68, 0x6e,
0xa3, 0x09,
0x04, 0x02, 0x73, 0x6e,
0x04, 0x03, 0x44, 0x6f, 0x65}, "(&(givenName=John)(sn=Doe))"},
{[]byte{
0xa1, 0x2a,
0xa3, 0x11,
0x04, 0x09, 0x67, 0x69, 0x76, 0x65, 0x6e, 0x4e, 0x61, 0x6d, 0x65,
0x04, 0x04, 0x4a, 0x6f, 0x68, 0x6e,
0xa3, 0x15,
0x04, 0x09, 0x67, 0x69, 0x76, 0x65, 0x6e, 0x4e, 0x61, 0x6d, 0x65,
0x04, 0x08, 0x4a, 0x6f, 0x6e, 0x61, 0x74, 0x68, 0x61, 0x6e}, "(|(givenName=John)(givenName=Jonathan))"},
{[]byte{
0xa2, 0x13,
0xa3, 0x11,
0x04, 0x09, 0x67, 0x69, 0x76, 0x65, 0x6e, 0x4e, 0x61, 0x6d, 0x65,
0x04, 0x04, 0x4a, 0x6f, 0x68, 0x6e}, "(!(givenName=John))"},
{[]byte{0xa3, 0x0b, 0x04, 0x03, 0x75, 0x69, 0x64, 0x04, 0x04, 0x6a, 0x64, 0x6f, 0x00}, "(uid=jdo\\00)"},
{[]byte{0xa3, 0x0b, 0x04, 0x03, 0x75, 0x69, 0x64, 0x04, 0x04, 0x6a, 0x64, 0x6f, 0x5c}, "(uid=jdo\\5c)"},
{[]byte{0xa3, 0x0b, 0x04, 0x03, 0x75, 0x69, 0x64, 0x04, 0x04, 0x6a, 0x64, 0x28, 0x29}, "(uid=jd\\28\\29)"},
}
for _, c := range cases {
elmt, err := ldapserver.BerReadElement(bytes.NewReader(c.raw))
if err != nil {
t.Fatalf("BerReadElement returned error: %v", err)
}
f, err := ldapserver.GetFilter(elmt)
if err != nil {
t.Fatalf("GetFilter(%v) returned error: %v", c.raw, err)
}
if f.String() != c.str {
t.Fatalf("Filter.String() = %v, want %v", f.String(), c.str)
}
}
}