Skip to content

Commit 43d50d6

Browse files
author
Rory O'Connell
committed
Merge remote branch 'tonyheadford/master'
Conflicts: lib/net/ldap.rb
2 parents 4159643 + 1761db8 commit 43d50d6

File tree

2 files changed

+83
-3
lines changed

2 files changed

+83
-3
lines changed

lib/net/ldap.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,16 +1507,23 @@ def add(args)
15071507
#--
15081508
# TODO: need to support a time limit, in case the server fails to respond.
15091509
#++
1510-
def rename(args)
1510+
def rename args
15111511
old_dn = args[:olddn] or raise "Unable to rename empty DN"
15121512
new_rdn = args[:newrdn] or raise "Unable to rename to empty RDN"
15131513
delete_attrs = args[:delete_attributes] ? true : false
1514+
new_superior = args[:new_superior]
15141515

1515-
request = [old_dn.to_ber, new_rdn.to_ber, delete_attrs.to_ber].to_ber_appsequence(12)
1516-
pkt = [next_msgid.to_ber, request].to_ber_sequence
1516+
request = [old_dn.to_ber, new_rdn.to_ber, delete_attrs.to_ber]
1517+
request << new_superior.to_ber unless new_superior == nil
1518+
1519+
pkt = [next_msgid.to_ber, request.to_ber_appsequence(12)].to_ber_sequence
15171520
@conn.write pkt
15181521

1522+
<<<<<<< HEAD
15191523
(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"
1524+
=======
1525+
(be = @conn.read_ber(AsnSyntax)) && (pdu = LdapPdu.new( be )) && (pdu.app_tag == 13) or raise LdapError.new( "response missing or invalid" )
1526+
>>>>>>> tonyheadford/master
15201527
pdu.result_code
15211528
end
15221529

test/test_rename.rb

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
require 'common'
2+
3+
class TestRename < Test::Unit::TestCase
4+
HOST= '10.10.10.71'
5+
PORT = 389
6+
BASE = "o=test"
7+
AUTH = { :method => :simple, :username => "cn=testadmin,#{BASE}", :password => 'password' }
8+
BASIC_USER = "cn=jsmith,ou=sales,#{BASE}"
9+
RENAMED_USER = "cn=jbrown,ou=sales,#{BASE}"
10+
MOVED_USER = "cn=jsmith,ou=marketing,#{BASE}"
11+
RENAMED_MOVED_USER = "cn=jjones,ou=marketing,#{BASE}"
12+
13+
def setup
14+
# create the entries we're going to manipulate
15+
Net::LDAP::open(:host => HOST, :port => PORT, :auth => AUTH) do |ldap|
16+
if ldap.add(:dn => "ou=sales,#{BASE}", :attributes => { :ou => "sales", :objectclass => "organizationalUnit" })
17+
puts "Add failed: #{ldap.get_operation_result.message} - code: #{ldap.get_operation_result.code}"
18+
end
19+
ldap.add(:dn => "ou=marketing,#{BASE}", :attributes => { :ou => "marketing", :objectclass => "organizationalUnit" })
20+
ldap.add(:dn => BASIC_USER, :attributes => { :cn => "jsmith", :objectclass => "inetOrgPerson", :sn => "Smith" })
21+
end
22+
end
23+
24+
def test_rename_entry
25+
dn = nil
26+
Net::LDAP::open(:host => HOST, :port => PORT, :auth => AUTH) do |ldap|
27+
ldap.rename(:olddn => BASIC_USER, :newrdn => "cn=jbrown")
28+
29+
ldap.search(:base => RENAMED_USER) do |entry|
30+
dn = entry.dn
31+
end
32+
end
33+
assert_equal(RENAMED_USER, dn)
34+
end
35+
36+
def test_move_entry
37+
dn = nil
38+
Net::LDAP::open(:host => HOST, :port => PORT, :auth => AUTH) do |ldap|
39+
ldap.rename(:olddn => BASIC_USER, :newrdn => "cn=jsmith", :new_superior => "ou=marketing,#{BASE}")
40+
41+
ldap.search(:base => MOVED_USER) do |entry|
42+
dn = entry.dn
43+
end
44+
end
45+
assert_equal(MOVED_USER, dn)
46+
end
47+
48+
def test_move_and_rename_entry
49+
dn = nil
50+
Net::LDAP::open(:host => HOST, :port => PORT, :auth => AUTH) do |ldap|
51+
ldap.rename(:olddn => BASIC_USER, :newrdn => "cn=jjones", :new_superior => "ou=marketing,#{BASE}")
52+
53+
ldap.search(:base => RENAMED_MOVED_USER) do |entry|
54+
dn = entry.dn
55+
end
56+
end
57+
assert_equal(RENAMED_MOVED_USER, dn)
58+
end
59+
60+
def teardown
61+
# delete the entries
62+
# note: this doesn't always completely clear up on eDirectory as objects get locked while
63+
# the rename/move is being completed on the server and this prevents the delete from happening
64+
Net::LDAP::open(:host => HOST, :port => PORT, :auth => AUTH) do |ldap|
65+
ldap.delete(:dn => BASIC_USER)
66+
ldap.delete(:dn => RENAMED_USER)
67+
ldap.delete(:dn => MOVED_USER)
68+
ldap.delete(:dn => RENAMED_MOVED_USER)
69+
ldap.delete(:dn => "ou=sales,#{BASE}")
70+
ldap.delete(:dn => "ou=marketing,#{BASE}")
71+
end
72+
end
73+
end

0 commit comments

Comments
 (0)