forked from innovationfactory/ruby-net-ldap
-
Notifications
You must be signed in to change notification settings - Fork 1
/
testfilter.rb
98 lines (81 loc) · 3.45 KB
/
testfilter.rb
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
97
# $Id$
#
#
require 'test/unit'
$:.unshift "lib"
require 'net/ldap'
class TestFilter < Test::Unit::TestCase
def setup
end
def teardown
end
# Note that the RFC doesn't define either less-than or greater-than.
def test_rfc_2254
Net::LDAP::Filter.from_rfc2254( " ( uid=george* ) " )
Net::LDAP::Filter.from_rfc2254( "uid!=george*" )
Net::LDAP::Filter.from_rfc2254( "uid <= george*" )
Net::LDAP::Filter.from_rfc2254( "uid>=george*" )
Net::LDAP::Filter.from_rfc2254( "uid!=george*" )
Net::LDAP::Filter.from_rfc2254( "(& (uid!=george* ) (mail=*))" )
Net::LDAP::Filter.from_rfc2254( "(| (uid!=george* ) (mail=*))" )
Net::LDAP::Filter.from_rfc2254( "(! (mail=*))" )
end
def test_filters_from_ber
[
Net::LDAP::Filter.eq( "objectclass", "*" ),
Net::LDAP::Filter.pres( "objectclass" ),
Net::LDAP::Filter.eq( "objectclass", "ou" ),
Net::LDAP::Filter.ge( "uid", "500" ),
Net::LDAP::Filter.le( "uid", "500" ),
(~ Net::LDAP::Filter.pres( "objectclass" )),
(Net::LDAP::Filter.pres( "objectclass" ) & Net::LDAP::Filter.pres( "ou" )),
(Net::LDAP::Filter.pres( "objectclass" ) & Net::LDAP::Filter.pres( "ou" ) & Net::LDAP::Filter.pres("sn")),
(Net::LDAP::Filter.pres( "objectclass" ) | Net::LDAP::Filter.pres( "ou" ) | Net::LDAP::Filter.pres("sn")),
Net::LDAP::Filter.eq( "objectclass", "*aaa" ),
Net::LDAP::Filter.eq( "objectclass", "*aaa*bbb" ),
Net::LDAP::Filter.eq( "objectclass", "*aaa*bbb*ccc" ),
Net::LDAP::Filter.eq( "objectclass", "aaa*bbb" ),
Net::LDAP::Filter.eq( "objectclass", "aaa*bbb*ccc" ),
Net::LDAP::Filter.eq( "objectclass", "abc*def*1111*22*g" ),
Net::LDAP::Filter.eq( "objectclass", "*aaa*" ),
Net::LDAP::Filter.eq( "objectclass", "*aaa*bbb*" ),
Net::LDAP::Filter.eq( "objectclass", "*aaa*bbb*ccc*" ),
Net::LDAP::Filter.eq( "objectclass", "aaa*" ),
Net::LDAP::Filter.eq( "objectclass", "aaa*bbb*" ),
Net::LDAP::Filter.eq( "objectclass", "aaa*bbb*ccc*" ),
].each {|ber|
f = Net::LDAP::Filter.parse_ber( ber.to_ber.read_ber( Net::LDAP::AsnSyntax) )
assert( f == ber )
assert_equal( f.to_ber, ber.to_ber )
}
end
def test_ber_from_rfc2254_filter
[
Net::LDAP::Filter.construct( "objectclass=*" ),
Net::LDAP::Filter.construct("objectclass=ou" ),
Net::LDAP::Filter.construct("uid >= 500" ),
Net::LDAP::Filter.construct("uid <= 500" ),
Net::LDAP::Filter.construct("(!(uid=*))" ),
Net::LDAP::Filter.construct("(&(uid=*)(objectclass=*))" ),
Net::LDAP::Filter.construct("(&(uid=*)(objectclass=*)(sn=*))" ),
Net::LDAP::Filter.construct("(|(uid=*)(objectclass=*))" ),
Net::LDAP::Filter.construct("(|(uid=*)(objectclass=*)(sn=*))" ),
Net::LDAP::Filter.construct("objectclass=*aaa"),
Net::LDAP::Filter.construct("objectclass=*aaa*bbb"),
Net::LDAP::Filter.construct("objectclass=*aaa*bbb*ccc"),
Net::LDAP::Filter.construct("objectclass=aaa*bbb"),
Net::LDAP::Filter.construct("objectclass=aaa*bbb*ccc"),
Net::LDAP::Filter.construct("objectclass=abc*def*1111*22*g"),
Net::LDAP::Filter.construct("objectclass=*aaa*"),
Net::LDAP::Filter.construct("objectclass=*aaa*bbb*"),
Net::LDAP::Filter.construct("objectclass=*aaa*bbb*ccc*"),
Net::LDAP::Filter.construct("objectclass=aaa*"),
Net::LDAP::Filter.construct("objectclass=aaa*bbb*"),
Net::LDAP::Filter.construct("objectclass=aaa*bbb*ccc*"),
].each {|ber|
f = Net::LDAP::Filter.parse_ber( ber.to_ber.read_ber( Net::LDAP::AsnSyntax) )
assert( f == ber )
assert_equal( f.to_ber, ber.to_ber )
}
end
end