test/test_base.rb in activeldap-1.1.0 vs test/test_base.rb in activeldap-1.2.0
- old
+ new
@@ -4,10 +4,110 @@
class TestBase < Test::Unit::TestCase
include AlTestUtils
priority :must
+ def test_rename_with_superior
+ make_ou("sub,ou=users")
+ make_temporary_user(:simple => true) do |user,|
+ user.id = "user2,ou=sub,#{@user_class.base}"
+ assert_raise(ActiveLdap::NotImplemented) do
+ assert_true(user.save)
+
+ # the following codes aren't reached for now. :<
+ found_user = nil
+ assert_nothing_raised do
+ found_user = @user_class.find("user2")
+ end
+ base = @user_class.base
+ assert_equal("#{@user_class.dn_attribute}=user2,ou=sub,#{base}",
+ found_user.dn.to_s)
+ end
+ end
+ end
+
+ def test_rename
+ make_temporary_user(:simple => true) do |user,|
+ assert_not_equal("user2", user.id)
+ assert_raise(ActiveLdap::EntryNotFound) do
+ @user_class.find("user2")
+ end
+ user.id = "user2"
+ assert_true(user.save)
+ assert_equal("user2", user.id)
+
+ found_user = nil
+ assert_nothing_raised do
+ found_user = @user_class.find("user2")
+ end
+ assert_equal("user2", found_user.id)
+ end
+ end
+
+ priority :normal
+ def test_operational_attributes
+ make_temporary_group do |group|
+ dn, attributes = @group_class.search(:attributes => ["*"])[0]
+ normal_attributes = attributes.keys
+ dn, attributes = @group_class.search(:attributes => ["*", "+"])[0]
+ operational_attributes = attributes.keys - normal_attributes
+ operational_attribute = operational_attributes[0]
+
+ group = @group_class.find(:first, :attributes => ["*", "+"])
+ operational_attribute_value = group[operational_attribute]
+ assert_not_nil(operational_attribute_value)
+ group.save!
+ assert_equal(operational_attribute_value, group[operational_attribute])
+ end
+ end
+
+ def test_destroy_mixed_tree_by_instance
+ make_ou("base")
+ _entry_class = entry_class("ou=base")
+ _ou_class = ou_class("ou=base")
+ _dc_class = dc_class("ou=base")
+
+ root1 = _ou_class.create("root1")
+ child1 = _ou_class.create(:ou => "child1", :parent => root1)
+ child2 = _ou_class.create(:ou => "child2", :parent => root1)
+ domain = _dc_class.create(:dc => "domain", :o => "domain", :parent => root1)
+ child3 = _ou_class.create(:ou => "child3", :parent => root1)
+ root2 = _ou_class.create("root2")
+ assert_equal(["base",
+ "root1", "child1", "child2", "domain", "child3",
+ "root2"],
+ _entry_class.find(:all).collect(&:id))
+ assert_raise(ActiveLdap::DeleteError) do
+ root1.destroy_all
+ end
+ assert_equal(["base", "root1", "domain", "root2"],
+ _entry_class.find(:all).collect(&:id))
+ end
+
+ def test_delete_mixed_tree_by_instance
+ make_ou("base")
+ _entry_class = entry_class("ou=base")
+ _ou_class = ou_class("ou=base")
+ _dc_class = dc_class("ou=base")
+
+ root1 = _ou_class.create("root1")
+ child1 = _ou_class.create(:ou => "child1", :parent => root1)
+ child2 = _ou_class.create(:ou => "child2", :parent => root1)
+ domain = _dc_class.create(:dc => "domain", :o => "domain", :parent => root1)
+ child3 = _ou_class.create(:ou => "child3", :parent => root1)
+ root2 = _ou_class.create("root2")
+ assert_equal(["base",
+ "root1", "child1", "child2", "domain", "child3",
+ "root2"],
+ _entry_class.find(:all).collect(&:id))
+ assert_raise(ActiveLdap::DeleteError) do
+ root1.delete_all
+ end
+ assert_equal(["base", "root1", "domain", "root2"],
+ _entry_class.find(:all).collect(&:id))
+ end
+
def test_delete_tree
make_ou("base")
_ou_class = ou_class("ou=base")
root1 = _ou_class.create("root1")
child1 = _ou_class.create(:ou => "child1", :parent => root1)
@@ -46,11 +146,10 @@
entry_class.delete_all(nil, :base => child2.dn)
assert_equal(["base", "root1", "child1", "domain1", "grandchild1", "root2"],
entry_class.find(:all).collect(&:id))
end
- priority :normal
def test_first
make_temporary_user(:simple => true) do |user1,|
make_temporary_user(:simple => true) do |user2,|
assert_equal(user1, @user_class.find(:first))
assert_equal(user2, @user_class.find(:first, user2.cn))
@@ -288,11 +387,11 @@
def test_case_insensitive_nested_ou
ou_class("ou=Users").new("Sub").save!
make_temporary_user(:uid => "test-user,ou=SUB") do |user, password|
sub_user_class = Class.new(@user_class)
sub_user_class.ldap_mapping :prefix => "ou=sub"
- assert_equal("uid=test-user,ou=sub,#{@user_class.base}",
+ assert_equal(dn("uid=test-user,ou=sub,#{@user_class.base}"),
sub_user_class.find(user.uid).dn)
end
end
def test_nested_ou
@@ -396,12 +495,12 @@
end
end
def test_loose_dn
make_temporary_user do |user,|
- assert(user.class.exists?(user.dn))
- assert(user.class.exists?(user.dn.gsub(/,/, " , ")))
- assert(user.class.exists?(user.dn.gsub(/=/, " = ")))
+ assert(user.class.exists?(user.dn.to_s))
+ assert(user.class.exists?(user.dn.to_s.gsub(/,/, " , ")))
+ assert(user.class.exists?(user.dn.to_s.gsub(/=/, " = ")))
end
end
def test_new_without_class
no_class_class = Class.new(ActiveLdap::Base)