test/test_base.rb in activeldap-3.1.1 vs test/test_base.rb in activeldap-3.2.0
- old
+ new
@@ -156,15 +156,15 @@
_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")
+ _ou_class.create(:ou => "child1", :parent => root1)
+ _ou_class.create(:ou => "child2", :parent => root1)
+ _dc_class.create(:dc => "domain", :o => "domain", :parent => root1)
+ _ou_class.create(:ou => "child3", :parent => root1)
+ _ou_class.create("root2")
assert_equal(["base",
"root1", "child1", "child2", "domain", "child3",
"root2"],
_entry_class.find(:all).collect(&:id))
assert_raise(ActiveLdap::DeleteError) do
@@ -179,15 +179,15 @@
_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")
+ _ou_class.create(:ou => "child1", :parent => root1)
+ _ou_class.create(:ou => "child2", :parent => root1)
+ _dc_class.create(:dc => "domain", :o => "domain", :parent => root1)
+ _ou_class.create(:ou => "child3", :parent => root1)
+ _ou_class.create("root2")
assert_equal(["base",
"root1", "child1", "child2", "domain", "child3",
"root2"],
_entry_class.find(:all).collect(&:id))
assert_raise(ActiveLdap::DeleteError) do
@@ -199,13 +199,13 @@
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)
- child2 = _ou_class.create(:ou => "child2", :parent => root1)
- root2 = _ou_class.create("root2")
+ _ou_class.create(:ou => "child1", :parent => root1)
+ _ou_class.create(:ou => "child2", :parent => root1)
+ _ou_class.create("root2")
assert_equal(["base", "root1", "child1", "child2", "root2"],
_ou_class.find(:all).collect(&:ou))
_ou_class.delete_all(:base => root1.dn)
assert_equal(["base", "root2"],
_ou_class.find(:all).collect(&:ou))
@@ -219,15 +219,15 @@
:prefix => "",
:classes => ['domain']
root1 = _ou_class.create("root1")
child1 = _ou_class.create(:ou => "child1", :parent => root1)
- domain1 = domain_class.create(:dc => "domain1", :parent => child1)
- grandchild1 = _ou_class.create(:ou => "grandchild1", :parent => child1)
+ domain_class.create(:dc => "domain1", :parent => child1)
+ _ou_class.create(:ou => "grandchild1", :parent => child1)
child2 = _ou_class.create(:ou => "child2", :parent => root1)
- domain2 = domain_class.create(:dc => "domain2", :parent => child2)
- root2 = _ou_class.create("root2")
+ domain_class.create(:dc => "domain2", :parent => child2)
+ _ou_class.create("root2")
entry_class = Class.new(ActiveLdap::Base)
entry_class.ldap_mapping :prefix => "ou=base",
:classes => ["top"]
entry_class.dn_attribute = nil
@@ -581,11 +581,11 @@
assert_equal(@user_class_classes, user.classes)
assert(user.respond_to?(:cn))
end
def test_new_with_invalid_argument
- user = @user_class.new
+ @user_class.new
assert_raises(ArgumentError) do
@user_class.new(100)
end
end
@@ -874,13 +874,14 @@
:prefix => "",
:classes => ["top", "organizationalUnit"]
end
end
- def test_to_xml
- ou = ou_class.new("Sample")
- assert_equal(<<-EOX, ou.to_xml(:root => "ou"))
+ class TestToXML < self
+ def test_root
+ ou = ou_class.new("Sample")
+ assert_equal(<<-EOX, ou.to_xml(:root => "ou"))
<ou>
<dn>#{ou.dn}</dn>
<objectClasses type="array">
<objectClass>organizationalUnit</objectClass>
<objectClass>top</objectClass>
@@ -888,12 +889,15 @@
<ous type="array">
<ou>Sample</ou>
</ous>
</ou>
EOX
+ end
- assert_equal(<<-EOX, ou.to_xml)
+ def test_default
+ ou = ou_class.new("Sample")
+ assert_equal(<<-EOX, ou.to_xml)
<anonymous>
<dn>#{ou.dn}</dn>
<objectClasses type="array">
<objectClass>organizationalUnit</objectClass>
<objectClass>top</objectClass>
@@ -901,14 +905,16 @@
<ous type="array">
<ou>Sample</ou>
</ous>
</anonymous>
EOX
+ end
- make_temporary_user do |user, password|
- xml = normalize_attributes_order(user.to_xml(:root => "user"))
- assert_equal(<<-EOX, xml)
+ def test_complex
+ make_temporary_user do |user, password|
+ xml = normalize_attributes_order(user.to_xml(:root => "user"))
+ assert_equal(<<-EOX, xml)
<user>
<dn>#{user.dn}</dn>
<cns type="array">
<cn>#{user.cn}</cn>
</cns>
@@ -937,40 +943,71 @@
<userPasswords type="array">
<userPassword>#{user.user_password}</userPassword>
</userPasswords>
</user>
EOX
+ end
end
- end
- def test_to_xml_except
- ou = ou_class.new("Sample")
- assert_equal(<<-EOX, ou.to_xml(:root => "sample", :except => [:objectClass]))
+ def test_except
+ ou = ou_class.new("Sample")
+ except = [:objectClass]
+ assert_equal(<<-EOX, ou.to_xml(:root => "sample", :except => except))
<sample>
<dn>#{ou.dn}</dn>
<ous type="array">
<ou>Sample</ou>
</ous>
</sample>
EOX
+ end
- except = [:dn, :object_class]
- assert_equal(<<-EOX, ou.to_xml(:root => "sample", :except => except))
+ def test_except_dn
+ ou = ou_class.new("Sample")
+ except = [:dn, :object_class]
+ assert_equal(<<-EOX, ou.to_xml(:root => "sample", :except => except))
<sample>
<ous type="array">
<ou>Sample</ou>
</ous>
</sample>
EOX
- end
+ end
- def test_to_xml_escape
- make_temporary_user do |user, password|
- sn = user.sn
- user.sn = "<#{sn}>"
- except = [:jpeg_photo, :user_certificate]
- assert_equal(<<-EOX, user.to_xml(:root => "user", :except => except))
+ def test_only
+ ou = ou_class.new("Sample")
+ only = [:objectClass]
+ assert_equal(<<-EOX, ou.to_xml(:root => "sample", :only => only))
+<sample>
+ <objectClasses type="array">
+ <objectClass>organizationalUnit</objectClass>
+ <objectClass>top</objectClass>
+ </objectClasses>
+</sample>
+EOX
+ end
+
+ def test_only_dn
+ ou = ou_class.new("Sample")
+ only = [:dn, :object_class]
+ assert_equal(<<-EOX, ou.to_xml(:root => "sample", :only => only))
+<sample>
+ <dn>#{ou.dn}</dn>
+ <objectClasses type="array">
+ <objectClass>organizationalUnit</objectClass>
+ <objectClass>top</objectClass>
+ </objectClasses>
+</sample>
+EOX
+ end
+
+ def test_escape
+ make_temporary_user do |user, password|
+ sn = user.sn
+ user.sn = "<#{sn}>"
+ except = [:jpeg_photo, :user_certificate]
+ assert_equal(<<-EOX, user.to_xml(:root => "user", :except => except))
<user>
<dn>#{user.dn}</dn>
<cns type="array">
<cn>#{user.cn}</cn>
</cns>
@@ -993,20 +1030,20 @@
<userPasswords type="array">
<userPassword>#{user.user_password}</userPassword>
</userPasswords>
</user>
EOX
+ end
end
- end
- def test_to_xml_type_ldif
- make_temporary_user do |user, password|
- sn = user.sn
- user.sn = "<#{sn}>"
- except = [:jpeg_photo, :user_certificate]
- options = {:root => "user", :except => except, :type => :ldif}
- assert_equal(<<-EOX, user.to_xml(options))
+ def test_type_ldif
+ make_temporary_user do |user, password|
+ sn = user.sn
+ user.sn = "<#{sn}>"
+ except = [:jpeg_photo, :user_certificate]
+ options = {:root => "user", :except => except, :type => :ldif}
+ assert_equal(<<-EOX, user.to_xml(options))
<user>
<dn>#{user.dn}</dn>
<cn>#{user.cn}</cn>
<gidNumber>#{user.gid_number}</gidNumber>
<homeDirectory>#{user.home_directory}</homeDirectory>
@@ -1019,17 +1056,17 @@
<uid>#{user.uid}</uid>
<uidNumber>#{user.uid_number}</uidNumber>
<userPassword>#{user.user_password}</userPassword>
</user>
EOX
+ end
end
- end
- def test_to_xml_nil
- ou = ou_class.new("Sample")
- ou.description = [nil]
- assert_equal(<<-EOX, ou.to_xml(:root => "sample"))
+ def test_nil
+ ou = ou_class.new("Sample")
+ ou.description = [nil]
+ assert_equal(<<-EOX, ou.to_xml(:root => "sample"))
<sample>
<dn>#{ou.dn}</dn>
<objectClasses type="array">
<objectClass>organizationalUnit</objectClass>
<objectClass>top</objectClass>
@@ -1037,9 +1074,34 @@
<ous type="array">
<ou>Sample</ou>
</ous>
</sample>
EOX
+ end
+
+ def test_single_value
+ make_temporary_user do |user, password|
+ only = [:dn, :uidNumber]
+ assert_equal(<<-EOX, user.to_xml(:root => "user", :only => only))
+<user>
+ <dn>#{user.dn}</dn>
+ <uidNumber>#{user.uid_number}</uidNumber>
+</user>
+EOX
+ end
+ end
+
+ def test_single_value_nil
+ make_temporary_user do |user, password|
+ only = [:dn, :uidNumber]
+ user.uid_number = nil
+ assert_equal(<<-EOX, user.to_xml(:root => "user", :only => only))
+<user>
+ <dn>#{user.dn}</dn>
+</user>
+EOX
+ end
+ end
end
def test_save
make_temporary_user do |user, password|
user.sn = nil