incorporated test data into the test LDAP server.
This commit is contained in:
parent
2ccd60bfc2
commit
f8440cdf36
|
@ -49,7 +49,7 @@ class TestLdapClient < Test::Unit::TestCase
|
|||
search = {:base => "dc=smalldomain,dc=com"}
|
||||
assert_equal( 32, ldap.search( search ))
|
||||
|
||||
search = {:base => "dc=bigdomain,dc=com"}
|
||||
search = {:base => "dc=bayshorenetworks,dc=com"}
|
||||
assert_equal( 0, ldap.search( search ))
|
||||
|
||||
ldap.search( search ) {|res|
|
||||
|
@ -64,7 +64,7 @@ class TestLdapClient < Test::Unit::TestCase
|
|||
assert_equal( 0, ldap.bind )
|
||||
|
||||
search = {
|
||||
:base => "dc=bigdomain,dc=com",
|
||||
:base => "dc=bayshorenetworks,dc=com",
|
||||
:attributes => ["mail"]
|
||||
}
|
||||
assert_equal( 0, ldap.search( search ))
|
||||
|
|
|
@ -110,11 +110,26 @@ module LdapServer
|
|||
end
|
||||
|
||||
treebase = pdu[1][0]
|
||||
if treebase != "dc=bigdomain,dc=com"
|
||||
if treebase != "dc=bayshorenetworks,dc=com"
|
||||
send_ldap_response 5, pdu[0].to_i, 32, "", "unknown treebase"
|
||||
return
|
||||
end
|
||||
|
||||
msgid = pdu[0].to_i.to_ber
|
||||
|
||||
$ldif.each {|dn, entry|
|
||||
|
||||
attrs = []
|
||||
entry.each {|k, v|
|
||||
attrvals = v.map {|v1| v1.to_ber}.to_ber_set
|
||||
attrs << [k.to_ber, attrvals].to_ber_sequence
|
||||
}
|
||||
|
||||
appseq = [dn.to_ber, attrs.to_ber_sequence].to_ber_appsequence(4)
|
||||
pkt = [msgid.to_ber, appseq].to_ber_sequence
|
||||
send_data pkt
|
||||
}
|
||||
|
||||
# pdu[1][7] is the attributes. It's an empty array to signify ALL attributes.
|
||||
puts "WARNING, not interpreting attributes specifier"
|
||||
=begin
|
||||
|
@ -131,6 +146,7 @@ Search Response ::=
|
|||
}
|
||||
=end
|
||||
|
||||
=begin
|
||||
send_data( [
|
||||
pdu[0].to_i.to_ber, [
|
||||
"abcdefghijklmnopqrstuvwxyz".to_ber, [
|
||||
|
@ -166,6 +182,7 @@ Search Response ::=
|
|||
].to_ber_sequence
|
||||
].to_ber_appsequence(4)
|
||||
].to_ber_sequence)
|
||||
=end
|
||||
|
||||
send_ldap_response 5, pdu[0].to_i, 0, "", "Was that what you wanted?"
|
||||
end
|
||||
|
@ -177,6 +194,28 @@ Search Response ::=
|
|||
end
|
||||
|
||||
|
||||
#------------------------------------------------
|
||||
|
||||
# Rather bogus, a global method, which reads a HARDCODED filename
|
||||
# parses out LDIF data. It will be used to serve LDAP queries out of this server.
|
||||
#
|
||||
def load_test_data
|
||||
ary = File.readlines( "./testdata.ldif" )
|
||||
hash = {}
|
||||
while line = ary.shift and line.chomp!
|
||||
if line =~ /^dn:[\s]*/i
|
||||
dn = $'
|
||||
hash[dn] = {}
|
||||
while attr = ary.shift and attr.chomp! and attr =~ /^([\w]+)[\s]*:[\s]*/
|
||||
hash[dn][$1.downcase] ||= []
|
||||
hash[dn][$1.downcase] << $'
|
||||
end
|
||||
end
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
||||
|
||||
#------------------------------------------------
|
||||
|
||||
if __FILE__ == $0
|
||||
|
@ -190,6 +229,8 @@ if __FILE__ == $0
|
|||
$logger.info "adding ../lib to loadpath, to pick up dev version of Net::LDAP."
|
||||
$:.unshift "../lib"
|
||||
|
||||
$ldif = load_test_data
|
||||
|
||||
require 'net/ldap'
|
||||
|
||||
EventMachine.run {
|
||||
|
|
Loading…
Reference in a new issue