Merge branch 'filter_single_clauses' of https://github.com/Jamstah/ruby-net-ldap into jamstah-filter_single_clauses

This commit is contained in:
Austin Ziegler 2011-03-17 22:33:16 -04:00
commit 7ae8e28550
3 changed files with 13 additions and 8 deletions

View file

@ -696,7 +696,7 @@ class Net::LDAP::Filter
filter = nil
branches = parse_branches(scanner)
if branches.size >= 2
if branches.size >= 1
filter = branches.shift
while not branches.empty?
filter = filter.__send__(op, branches.shift)

View file

@ -24,7 +24,8 @@ describe Net::LDAP::Filter do
'(o:dn:=Ace Industry)',
'(:dn:2.4.8.10:=Dino)',
'(cn:dn:1.2.3.4.5:=John Smith)',
'(sn:dn:2.4.6.8.10:=Barbara Jones)',
'(sn:dn:2.4.6.8.10:=Barbara Jones)',
'(&(sn:dn:2.4.6.8.10:=Barbara Jones))'
].each do |filter_str|
context "from_rfc2254(#{filter_str.inspect})" do
attr_reader :filter
@ -80,4 +81,4 @@ describe Net::LDAP::Filter do
Net::LDAP::Filter.escape('!&*:|~').should == "\\21\\26\\2A\\3A\\7C\\7E"
end
end
end
end

View file

@ -45,6 +45,10 @@ class TestFilter < Test::Unit::TestCase
Filter.from_rfc2254("(! (mail=*))").to_rfc2254)
end
def test_filter_with_single_clause
assert_equal("(cn=name)", Net::LDAP::Filter.construct("(&(cn=name))").to_s)
end
def test_filters_from_ber
[
Net::LDAP::Filter.eq("objectclass", "*"),
@ -69,11 +73,11 @@ class TestFilter < Test::Unit::TestCase
Net::LDAP::Filter.eq("objectclass", "aaa*"),
Net::LDAP::Filter.eq("objectclass", "aaa*bbb*"),
Net::LDAP::Filter.eq("objectclass", "aaa*bbb*ccc*"),
].each {|ber|
].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
def test_ber_from_rfc2254_filter
@ -102,10 +106,10 @@ class TestFilter < Test::Unit::TestCase
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))
].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