Merge remote branch 'tonyheadford/master'

Conflicts:
	lib/net/ldap.rb
This commit is contained in:
Rory O'Connell 2010-09-25 15:02:34 -05:00
commit 43d50d6498
2 changed files with 83 additions and 3 deletions

View file

@ -1507,16 +1507,23 @@ class Net::LDAP::Connection #:nodoc:
#-- #--
# TODO: need to support a time limit, in case the server fails to respond. # TODO: need to support a time limit, in case the server fails to respond.
#++ #++
def rename(args) def rename args
old_dn = args[:olddn] or raise "Unable to rename empty DN" old_dn = args[:olddn] or raise "Unable to rename empty DN"
new_rdn = args[:newrdn] or raise "Unable to rename to empty RDN" new_rdn = args[:newrdn] or raise "Unable to rename to empty RDN"
delete_attrs = args[:delete_attributes] ? true : false delete_attrs = args[:delete_attributes] ? true : false
new_superior = args[:new_superior]
request = [old_dn.to_ber, new_rdn.to_ber, delete_attrs.to_ber].to_ber_appsequence(12) request = [old_dn.to_ber, new_rdn.to_ber, delete_attrs.to_ber]
pkt = [next_msgid.to_ber, request].to_ber_sequence request << new_superior.to_ber unless new_superior == nil
pkt = [next_msgid.to_ber, request.to_ber_appsequence(12)].to_ber_sequence
@conn.write pkt @conn.write pkt
<<<<<<< HEAD
(be = @conn.read_ber(Net::LDAP::AsnSyntax)) && (pdu = Net::LDAP::PDU.new(be)) && (pdu.app_tag == 13) or raise Net::LDAP::LdapError, "response missing or invalid" (be = @conn.read_ber(Net::LDAP::AsnSyntax)) && (pdu = Net::LDAP::PDU.new(be)) && (pdu.app_tag == 13) or raise Net::LDAP::LdapError, "response missing or invalid"
=======
(be = @conn.read_ber(AsnSyntax)) && (pdu = LdapPdu.new( be )) && (pdu.app_tag == 13) or raise LdapError.new( "response missing or invalid" )
>>>>>>> tonyheadford/master
pdu.result_code pdu.result_code
end end

73
test/test_rename.rb Normal file
View file

@ -0,0 +1,73 @@
require 'common'
class TestRename < Test::Unit::TestCase
HOST= '10.10.10.71'
PORT = 389
BASE = "o=test"
AUTH = { :method => :simple, :username => "cn=testadmin,#{BASE}", :password => 'password' }
BASIC_USER = "cn=jsmith,ou=sales,#{BASE}"
RENAMED_USER = "cn=jbrown,ou=sales,#{BASE}"
MOVED_USER = "cn=jsmith,ou=marketing,#{BASE}"
RENAMED_MOVED_USER = "cn=jjones,ou=marketing,#{BASE}"
def setup
# create the entries we're going to manipulate
Net::LDAP::open(:host => HOST, :port => PORT, :auth => AUTH) do |ldap|
if ldap.add(:dn => "ou=sales,#{BASE}", :attributes => { :ou => "sales", :objectclass => "organizationalUnit" })
puts "Add failed: #{ldap.get_operation_result.message} - code: #{ldap.get_operation_result.code}"
end
ldap.add(:dn => "ou=marketing,#{BASE}", :attributes => { :ou => "marketing", :objectclass => "organizationalUnit" })
ldap.add(:dn => BASIC_USER, :attributes => { :cn => "jsmith", :objectclass => "inetOrgPerson", :sn => "Smith" })
end
end
def test_rename_entry
dn = nil
Net::LDAP::open(:host => HOST, :port => PORT, :auth => AUTH) do |ldap|
ldap.rename(:olddn => BASIC_USER, :newrdn => "cn=jbrown")
ldap.search(:base => RENAMED_USER) do |entry|
dn = entry.dn
end
end
assert_equal(RENAMED_USER, dn)
end
def test_move_entry
dn = nil
Net::LDAP::open(:host => HOST, :port => PORT, :auth => AUTH) do |ldap|
ldap.rename(:olddn => BASIC_USER, :newrdn => "cn=jsmith", :new_superior => "ou=marketing,#{BASE}")
ldap.search(:base => MOVED_USER) do |entry|
dn = entry.dn
end
end
assert_equal(MOVED_USER, dn)
end
def test_move_and_rename_entry
dn = nil
Net::LDAP::open(:host => HOST, :port => PORT, :auth => AUTH) do |ldap|
ldap.rename(:olddn => BASIC_USER, :newrdn => "cn=jjones", :new_superior => "ou=marketing,#{BASE}")
ldap.search(:base => RENAMED_MOVED_USER) do |entry|
dn = entry.dn
end
end
assert_equal(RENAMED_MOVED_USER, dn)
end
def teardown
# delete the entries
# note: this doesn't always completely clear up on eDirectory as objects get locked while
# the rename/move is being completed on the server and this prevents the delete from happening
Net::LDAP::open(:host => HOST, :port => PORT, :auth => AUTH) do |ldap|
ldap.delete(:dn => BASIC_USER)
ldap.delete(:dn => RENAMED_USER)
ldap.delete(:dn => MOVED_USER)
ldap.delete(:dn => RENAMED_MOVED_USER)
ldap.delete(:dn => "ou=sales,#{BASE}")
ldap.delete(:dn => "ou=marketing,#{BASE}")
end
end
end