|
| 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