Merge pull request #16 from mcarpenter/master
Issue #15: LDIF continuation character
This commit is contained in:
commit
5c3cbb7fe6
3 changed files with 88 additions and 76 deletions
|
@ -117,8 +117,8 @@ class Net::LDAP::Dataset < Hash
|
||||||
while line
|
while line
|
||||||
new_line = io.gets
|
new_line = io.gets
|
||||||
|
|
||||||
if new_line =~ /^[\s]+/
|
if new_line =~ /^ /
|
||||||
line << " " << $'
|
line << $'
|
||||||
else
|
else
|
||||||
nextline = new_line
|
nextline = new_line
|
||||||
|
|
||||||
|
|
|
@ -31,92 +31,92 @@ class TestFilter < Test::Unit::TestCase
|
||||||
assert_equal("(uid=*\\5C*)", Filter.contains("uid", "\\").to_s)
|
assert_equal("(uid=*\\5C*)", Filter.contains("uid", "\\").to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_c2
|
def test_c2
|
||||||
assert_equal("(uid=george *)",
|
assert_equal("(uid=george *)",
|
||||||
Filter.from_rfc2254("uid=george *").to_rfc2254)
|
Filter.from_rfc2254("uid=george *").to_rfc2254)
|
||||||
assert_equal("(uid:=george *)",
|
assert_equal("(uid:=george *)",
|
||||||
Filter.from_rfc2254("uid:=george *").to_rfc2254)
|
Filter.from_rfc2254("uid:=george *").to_rfc2254)
|
||||||
assert_equal("(uid=george*)",
|
assert_equal("(uid=george*)",
|
||||||
Filter.from_rfc2254(" ( uid = george* ) ").to_rfc2254)
|
Filter.from_rfc2254(" ( uid = george* ) ").to_rfc2254)
|
||||||
assert_equal("(!(uid=george*))",
|
assert_equal("(!(uid=george*))",
|
||||||
Filter.from_rfc2254("uid!=george*").to_rfc2254)
|
Filter.from_rfc2254("uid!=george*").to_rfc2254)
|
||||||
assert_equal("(uid<=george*)",
|
assert_equal("(uid<=george*)",
|
||||||
Filter.from_rfc2254("uid <= george*").to_rfc2254)
|
Filter.from_rfc2254("uid <= george*").to_rfc2254)
|
||||||
assert_equal("(uid>=george*)",
|
assert_equal("(uid>=george*)",
|
||||||
Filter.from_rfc2254("uid>=george*").to_rfc2254)
|
Filter.from_rfc2254("uid>=george*").to_rfc2254)
|
||||||
assert_equal("(&(uid=george*)(mail=*))",
|
assert_equal("(&(uid=george*)(mail=*))",
|
||||||
Filter.from_rfc2254("(& (uid=george* ) (mail=*))").to_rfc2254)
|
Filter.from_rfc2254("(& (uid=george* ) (mail=*))").to_rfc2254)
|
||||||
assert_equal("(|(uid=george*)(mail=*))",
|
assert_equal("(|(uid=george*)(mail=*))",
|
||||||
Filter.from_rfc2254("(| (uid=george* ) (mail=*))").to_rfc2254)
|
Filter.from_rfc2254("(| (uid=george* ) (mail=*))").to_rfc2254)
|
||||||
assert_equal("(!(mail=*))",
|
assert_equal("(!(mail=*))",
|
||||||
Filter.from_rfc2254("(! (mail=*))").to_rfc2254)
|
Filter.from_rfc2254("(! (mail=*))").to_rfc2254)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_filter_with_single_clause
|
def test_filter_with_single_clause
|
||||||
assert_equal("(cn=name)", Net::LDAP::Filter.construct("(&(cn=name))").to_s)
|
assert_equal("(cn=name)", Net::LDAP::Filter.construct("(&(cn=name))").to_s)
|
||||||
|
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 do |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
|
||||||
|
end
|
||||||
|
|
||||||
def test_filters_from_ber
|
def test_ber_from_rfc2254_filter
|
||||||
[
|
[
|
||||||
Net::LDAP::Filter.eq("objectclass", "*"),
|
Net::LDAP::Filter.construct("objectclass=*"),
|
||||||
Net::LDAP::Filter.pres("objectclass"),
|
Net::LDAP::Filter.construct("objectclass=ou"),
|
||||||
Net::LDAP::Filter.eq("objectclass", "ou"),
|
Net::LDAP::Filter.construct("uid >= 500"),
|
||||||
Net::LDAP::Filter.ge("uid", "500"),
|
Net::LDAP::Filter.construct("uid <= 500"),
|
||||||
Net::LDAP::Filter.le("uid", "500"),
|
Net::LDAP::Filter.construct("(!(uid=*))"),
|
||||||
(~ Net::LDAP::Filter.pres("objectclass")),
|
Net::LDAP::Filter.construct("(&(uid=*)(objectclass=*))"),
|
||||||
(Net::LDAP::Filter.pres("objectclass") & Net::LDAP::Filter.pres("ou")),
|
Net::LDAP::Filter.construct("(&(uid=*)(objectclass=*)(sn=*))"),
|
||||||
(Net::LDAP::Filter.pres("objectclass") & Net::LDAP::Filter.pres("ou") & Net::LDAP::Filter.pres("sn")),
|
Net::LDAP::Filter.construct("(|(uid=*)(objectclass=*))"),
|
||||||
(Net::LDAP::Filter.pres("objectclass") | Net::LDAP::Filter.pres("ou") | Net::LDAP::Filter.pres("sn")),
|
Net::LDAP::Filter.construct("(|(uid=*)(objectclass=*)(sn=*))"),
|
||||||
|
|
||||||
Net::LDAP::Filter.eq("objectclass", "*aaa"),
|
Net::LDAP::Filter.construct("objectclass=*aaa"),
|
||||||
Net::LDAP::Filter.eq("objectclass", "*aaa*bbb"),
|
Net::LDAP::Filter.construct("objectclass=*aaa*bbb"),
|
||||||
Net::LDAP::Filter.eq("objectclass", "*aaa*bbb*ccc"),
|
Net::LDAP::Filter.construct("objectclass=*aaa bbb"),
|
||||||
Net::LDAP::Filter.eq("objectclass", "aaa*bbb"),
|
Net::LDAP::Filter.construct("objectclass=*aaa bbb"),
|
||||||
Net::LDAP::Filter.eq("objectclass", "aaa*bbb*ccc"),
|
Net::LDAP::Filter.construct("objectclass=*aaa*bbb*ccc"),
|
||||||
Net::LDAP::Filter.eq("objectclass", "abc*def*1111*22*g"),
|
Net::LDAP::Filter.construct("objectclass=aaa*bbb"),
|
||||||
Net::LDAP::Filter.eq("objectclass", "*aaa*"),
|
Net::LDAP::Filter.construct("objectclass=aaa*bbb*ccc"),
|
||||||
Net::LDAP::Filter.eq("objectclass", "*aaa*bbb*"),
|
Net::LDAP::Filter.construct("objectclass=abc*def*1111*22*g"),
|
||||||
Net::LDAP::Filter.eq("objectclass", "*aaa*bbb*ccc*"),
|
Net::LDAP::Filter.construct("objectclass=*aaa*"),
|
||||||
Net::LDAP::Filter.eq("objectclass", "aaa*"),
|
Net::LDAP::Filter.construct("objectclass=*aaa*bbb*"),
|
||||||
Net::LDAP::Filter.eq("objectclass", "aaa*bbb*"),
|
Net::LDAP::Filter.construct("objectclass=*aaa*bbb*ccc*"),
|
||||||
Net::LDAP::Filter.eq("objectclass", "aaa*bbb*ccc*"),
|
Net::LDAP::Filter.construct("objectclass=aaa*"),
|
||||||
].each do |ber|
|
Net::LDAP::Filter.construct("objectclass=aaa*bbb*"),
|
||||||
f = Net::LDAP::Filter.parse_ber(ber.to_ber.read_ber(Net::LDAP::AsnSyntax))
|
Net::LDAP::Filter.construct("objectclass=aaa*bbb*ccc*"),
|
||||||
assert(f == ber)
|
].each do |ber|
|
||||||
assert_equal(f.to_ber, ber.to_ber)
|
f = Net::LDAP::Filter.parse_ber(ber.to_ber.read_ber(Net::LDAP::AsnSyntax))
|
||||||
end
|
assert(f == ber)
|
||||||
end
|
assert_equal(f.to_ber, ber.to_ber)
|
||||||
|
end
|
||||||
def test_ber_from_rfc2254_filter
|
end
|
||||||
[
|
|
||||||
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"),
|
|
||||||
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 do |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
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,8 +31,20 @@ class TestLdif < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ldif_with_continuation_lines
|
def test_ldif_with_continuation_lines
|
||||||
ds = Net::LDAP::Dataset::read_ldif(StringIO.new("dn: abcdefg\r\n hijklmn\r\n\r\n"))
|
ds = Net::LDAP::Dataset::read_ldif(StringIO.new("dn: abcdefg\r\n hijklmn\r\n\r\n"))
|
||||||
assert_equal(true, ds.has_key?("abcdefg hijklmn"))
|
assert_equal(true, ds.has_key?("abcdefghijklmn"))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_ldif_with_continuation_lines_and_extra_whitespace
|
||||||
|
ds1 = Net::LDAP::Dataset::read_ldif(StringIO.new("dn: abcdefg\r\n hijklmn\r\n\r\n"))
|
||||||
|
assert_equal(true, ds1.has_key?("abcdefg hijklmn"))
|
||||||
|
ds2 = Net::LDAP::Dataset::read_ldif(StringIO.new("dn: abcdefg\r\n hij klmn\r\n\r\n"))
|
||||||
|
assert_equal(true, ds2.has_key?("abcdefghij klmn"))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_ldif_tab_is_not_continuation
|
||||||
|
ds = Net::LDAP::Dataset::read_ldif(StringIO.new("dn: key\r\n\tnotcontinued\r\n\r\n"))
|
||||||
|
assert_equal(true, ds.has_key?("key"))
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO, INADEQUATE. We need some more tests
|
# TODO, INADEQUATE. We need some more tests
|
||||||
|
|
Loading…
Reference in a new issue