powerhome-activeldap 3.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +6 -0
  3. data/COPYING +340 -0
  4. data/Gemfile +12 -0
  5. data/LICENSE +59 -0
  6. data/README.textile +140 -0
  7. data/TODO +32 -0
  8. data/benchmark/README.md +64 -0
  9. data/benchmark/bench-backend.rb +247 -0
  10. data/benchmark/bench-instantiate.rb +98 -0
  11. data/benchmark/config.yaml.sample +5 -0
  12. data/doc/text/development.textile +54 -0
  13. data/doc/text/news.textile +811 -0
  14. data/doc/text/rails.textile +144 -0
  15. data/doc/text/tutorial.textile +1010 -0
  16. data/examples/config.yaml.example +5 -0
  17. data/examples/example.der +0 -0
  18. data/examples/example.jpg +0 -0
  19. data/examples/groupadd +41 -0
  20. data/examples/groupdel +35 -0
  21. data/examples/groupls +49 -0
  22. data/examples/groupmod +42 -0
  23. data/examples/lpasswd +55 -0
  24. data/examples/objects/group.rb +13 -0
  25. data/examples/objects/ou.rb +4 -0
  26. data/examples/objects/user.rb +20 -0
  27. data/examples/ouadd +38 -0
  28. data/examples/useradd +45 -0
  29. data/examples/useradd-binary +53 -0
  30. data/examples/userdel +34 -0
  31. data/examples/userls +50 -0
  32. data/examples/usermod +42 -0
  33. data/examples/usermod-binary-add +50 -0
  34. data/examples/usermod-binary-add-time +54 -0
  35. data/examples/usermod-binary-del +48 -0
  36. data/examples/usermod-lang-add +43 -0
  37. data/lib/active_ldap.rb +85 -0
  38. data/lib/active_ldap/action_controller/ldap_benchmarking.rb +55 -0
  39. data/lib/active_ldap/acts/tree.rb +78 -0
  40. data/lib/active_ldap/adapter/base.rb +707 -0
  41. data/lib/active_ldap/adapter/jndi.rb +184 -0
  42. data/lib/active_ldap/adapter/jndi_connection.rb +185 -0
  43. data/lib/active_ldap/adapter/ldap.rb +290 -0
  44. data/lib/active_ldap/adapter/ldap_ext.rb +105 -0
  45. data/lib/active_ldap/adapter/net_ldap.rb +309 -0
  46. data/lib/active_ldap/adapter/net_ldap_ext.rb +23 -0
  47. data/lib/active_ldap/association/belongs_to.rb +47 -0
  48. data/lib/active_ldap/association/belongs_to_many.rb +58 -0
  49. data/lib/active_ldap/association/children.rb +21 -0
  50. data/lib/active_ldap/association/collection.rb +105 -0
  51. data/lib/active_ldap/association/has_many.rb +31 -0
  52. data/lib/active_ldap/association/has_many_utils.rb +44 -0
  53. data/lib/active_ldap/association/has_many_wrap.rb +75 -0
  54. data/lib/active_ldap/association/proxy.rb +107 -0
  55. data/lib/active_ldap/associations.rb +205 -0
  56. data/lib/active_ldap/attribute_methods.rb +23 -0
  57. data/lib/active_ldap/attribute_methods/before_type_cast.rb +24 -0
  58. data/lib/active_ldap/attribute_methods/dirty.rb +43 -0
  59. data/lib/active_ldap/attribute_methods/query.rb +31 -0
  60. data/lib/active_ldap/attribute_methods/read.rb +44 -0
  61. data/lib/active_ldap/attribute_methods/write.rb +38 -0
  62. data/lib/active_ldap/attributes.rb +176 -0
  63. data/lib/active_ldap/base.rb +1410 -0
  64. data/lib/active_ldap/callbacks.rb +71 -0
  65. data/lib/active_ldap/command.rb +49 -0
  66. data/lib/active_ldap/compatible.rb +44 -0
  67. data/lib/active_ldap/configuration.rb +147 -0
  68. data/lib/active_ldap/connection.rb +299 -0
  69. data/lib/active_ldap/distinguished_name.rb +291 -0
  70. data/lib/active_ldap/entry_attribute.rb +78 -0
  71. data/lib/active_ldap/escape.rb +12 -0
  72. data/lib/active_ldap/get_text.rb +20 -0
  73. data/lib/active_ldap/get_text/parser.rb +161 -0
  74. data/lib/active_ldap/helper.rb +92 -0
  75. data/lib/active_ldap/human_readable.rb +133 -0
  76. data/lib/active_ldap/ldap_error.rb +74 -0
  77. data/lib/active_ldap/ldif.rb +930 -0
  78. data/lib/active_ldap/log_subscriber.rb +50 -0
  79. data/lib/active_ldap/object_class.rb +95 -0
  80. data/lib/active_ldap/operations.rb +624 -0
  81. data/lib/active_ldap/persistence.rb +100 -0
  82. data/lib/active_ldap/populate.rb +53 -0
  83. data/lib/active_ldap/railtie.rb +43 -0
  84. data/lib/active_ldap/railties/controller_runtime.rb +48 -0
  85. data/lib/active_ldap/schema.rb +701 -0
  86. data/lib/active_ldap/schema/syntaxes.rb +422 -0
  87. data/lib/active_ldap/timeout.rb +75 -0
  88. data/lib/active_ldap/timeout_stub.rb +17 -0
  89. data/lib/active_ldap/user_password.rb +99 -0
  90. data/lib/active_ldap/validations.rb +200 -0
  91. data/lib/active_ldap/version.rb +3 -0
  92. data/lib/active_ldap/xml.rb +139 -0
  93. data/lib/rails/generators/active_ldap/model/USAGE +18 -0
  94. data/lib/rails/generators/active_ldap/model/model_generator.rb +47 -0
  95. data/lib/rails/generators/active_ldap/model/templates/model_active_ldap.rb +3 -0
  96. data/lib/rails/generators/active_ldap/scaffold/scaffold_generator.rb +14 -0
  97. data/lib/rails/generators/active_ldap/scaffold/templates/ldap.yml +19 -0
  98. data/po/en/active-ldap.po +4029 -0
  99. data/po/ja/active-ldap.po +4060 -0
  100. data/test/add-phonetic-attribute-options-to-slapd.ldif +10 -0
  101. data/test/al-test-utils.rb +428 -0
  102. data/test/command.rb +111 -0
  103. data/test/config.yaml.sample +6 -0
  104. data/test/fixtures/lower_case_object_class_schema.rb +802 -0
  105. data/test/run-test.rb +34 -0
  106. data/test/test_acts_as_tree.rb +60 -0
  107. data/test/test_adapter.rb +121 -0
  108. data/test/test_associations.rb +701 -0
  109. data/test/test_attributes.rb +117 -0
  110. data/test/test_base.rb +1214 -0
  111. data/test/test_base_per_instance.rb +61 -0
  112. data/test/test_bind.rb +62 -0
  113. data/test/test_callback.rb +31 -0
  114. data/test/test_configuration.rb +40 -0
  115. data/test/test_connection.rb +82 -0
  116. data/test/test_connection_per_class.rb +112 -0
  117. data/test/test_connection_per_dn.rb +112 -0
  118. data/test/test_dirty.rb +98 -0
  119. data/test/test_dn.rb +172 -0
  120. data/test/test_find.rb +176 -0
  121. data/test/test_groupadd.rb +50 -0
  122. data/test/test_groupdel.rb +46 -0
  123. data/test/test_groupls.rb +107 -0
  124. data/test/test_groupmod.rb +51 -0
  125. data/test/test_ldif.rb +1890 -0
  126. data/test/test_load.rb +133 -0
  127. data/test/test_lpasswd.rb +75 -0
  128. data/test/test_object_class.rb +74 -0
  129. data/test/test_persistence.rb +131 -0
  130. data/test/test_reflection.rb +175 -0
  131. data/test/test_schema.rb +559 -0
  132. data/test/test_syntax.rb +444 -0
  133. data/test/test_user.rb +217 -0
  134. data/test/test_user_password.rb +108 -0
  135. data/test/test_useradd-binary.rb +62 -0
  136. data/test/test_useradd.rb +57 -0
  137. data/test/test_userdel.rb +48 -0
  138. data/test/test_userls.rb +91 -0
  139. data/test/test_usermod-binary-add-time.rb +65 -0
  140. data/test/test_usermod-binary-add.rb +64 -0
  141. data/test/test_usermod-binary-del.rb +66 -0
  142. data/test/test_usermod-lang-add.rb +59 -0
  143. data/test/test_usermod.rb +58 -0
  144. data/test/test_validation.rb +274 -0
  145. metadata +379 -0
@@ -0,0 +1,98 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestDirty < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ priority :must
7
+
8
+ priority :normal
9
+ def test_clean_after_load
10
+ make_temporary_user do |user, password|
11
+ attributes = (user.must + user.may).collect(&:name) - ['objectClass']
12
+ _wrap_assertion do
13
+ attributes.each do |name|
14
+ assert_false(user.send("#{name}_changed?"))
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ def test_clean_after_reload
21
+ make_temporary_user do |user, password|
22
+ attributes = (user.must + user.may).collect(&:name) - ['objectClass']
23
+
24
+ user.cn = 'New cn'
25
+ assert_true(user.cn_changed?)
26
+ user.reload
27
+ assert_false(user.cn_changed?)
28
+
29
+ _wrap_assertion do
30
+ attributes.each do |name|
31
+ assert_false(user.send("#{name}_changed?"))
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ def test_setter
38
+ make_temporary_user do |user, password|
39
+ attributes = (user.must + user.may).collect(&:name) - ['objectClass', 'cn']
40
+ user.cn = 'New cn'
41
+ assert_true(user.cn_changed?)
42
+
43
+ _wrap_assertion do
44
+ (attributes - ['cn']).each do |name|
45
+ assert_false(user.send("#{name}_changed?"))
46
+ end
47
+
48
+ assert_true(user.cn_changed?)
49
+ end
50
+ end
51
+ end
52
+
53
+ def test_save
54
+ make_temporary_user do |user, password|
55
+ attributes = (user.must + user.may).collect(&:name) - ['objectClass', 'cn']
56
+ user.cn = 'New cn'
57
+ assert_true(user.cn_changed?)
58
+ user.save
59
+ assert_false(user.cn_changed?)
60
+
61
+ _wrap_assertion do
62
+ attributes.each do |name|
63
+ assert_false(user.send("#{name}_changed?"))
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ def test_save!
70
+ make_temporary_user do |user, password|
71
+ attributes = (user.must + user.may).collect(&:name) - ['objectClass', 'cn']
72
+ user.cn = 'New cn'
73
+ assert_true(user.cn_changed?)
74
+ user.save!
75
+ assert_false(user.cn_changed?)
76
+
77
+ _wrap_assertion do
78
+ attributes.each do |name|
79
+ assert_false(user.send("#{name}_changed?"))
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ class TestDNChange
86
+ def test_direct_base_use
87
+ leaf = ActiveLdap::Base.create
88
+ leaf.add_class("organizationalUnit")
89
+ leaf_dn = "ou=addressbook,#{user.dn}"
90
+ leaf.dn = leaf_dn
91
+ begin
92
+ leaf.save
93
+ ensure
94
+ ActiveLdap::Base.delete_entry(leaf_dn) if leaf.exists?
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,172 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'al-test-utils'
4
+
5
+ class TestDN < Test::Unit::TestCase
6
+ include AlTestUtils
7
+
8
+ def setup
9
+ end
10
+
11
+ def teardown
12
+ end
13
+
14
+ priority :must
15
+ def test_parent
16
+ dn = parse("o=xxx,dc=local,dc=net")
17
+ assert_equal(parse("dc=local,dc=net"), dn.parent)
18
+ assert_equal(parse("dc=net"), dn.parent.parent)
19
+ assert_nil(dn.parent.parent.parent)
20
+ end
21
+
22
+ priority :normal
23
+ def test_case_insensitive_dn_minus
24
+ assert_dn_minus("dc=xxx", "dc=xxx,dc=LoCaL,dc=net", "dc=LOCAL,dc=net")
25
+ end
26
+
27
+ def test_dn_hash
28
+ dn1 = ActiveLdap::DN.parse("o=xxx,dc=local,dc=net")
29
+ dn2 = ActiveLdap::DN.parse("O = xxx , DC = local , DC = net")
30
+ assert_equal(dn1.hash, dn2.hash)
31
+
32
+ hash = {dn1 => :dn}
33
+ assert_equal(:dn, hash[dn2])
34
+ end
35
+
36
+ def test_dn_to_s
37
+ assert_dn_to_s("dc=xxx,dc=local,dc=net",
38
+ "dc = xxx, dc = \"local\",dc=net")
39
+ assert_dn_to_s("dc=l\\,o\\=c\\+a\\<l\\>,dc=\\#n\\;e\\\\t",
40
+ "dc = \"l,o=c+a<l>\" , dc=\"#n;e\\\\t\"")
41
+ assert_dn_to_s("dc=\" l\\\"o c\\\\a l \",dc=\" n e t \"",
42
+ "dc = \" l\\\"o c\\\\a l \" , dc= \\20n\\20e\\20t\\20")
43
+ end
44
+
45
+ def test_dn_minus
46
+ assert_dn_minus("dc=xxx", "dc=xxx,dc=local,dc=net", "dc=local,dc=net")
47
+ assert_dn_minus_raise("dc=xxx,dc=net", "dc=local,dc=net")
48
+ end
49
+
50
+ def test_parse_good_manner_dn
51
+ assert_dn([["dc", "local"], ["dc", "net"]], "dc=local,dc=net")
52
+ assert_dn([["dc", "net"]], "dc=net")
53
+ assert_dn([], "")
54
+ end
55
+
56
+ def test_parse_dn_with_space
57
+ assert_dn([["dc", "net"]], "dc =net")
58
+ assert_dn([["dc", "net"]], "dc = net")
59
+ assert_dn([["dc", "local"], ["dc", "net"]], "dc = local , dc = net")
60
+ assert_dn([["dc", "local"], ["dc", "net "]], "dc = local , dc = net ")
61
+ end
62
+
63
+ def test_parse_dn_with_hex_pairs
64
+ assert_dn([["dc", "local"], ["dc", "net"]],
65
+ "dc = #6C6f63616C , dc = net")
66
+ assert_dn([["dc", "lo cal "], ["dc", "net"]],
67
+ "dc = #6C6f2063616C20 ,dc=net")
68
+ end
69
+
70
+ def test_parse_dn_with_quoted_attribute_value
71
+ assert_dn([["dc", " l o c a l "], ["dc", "+n,\"e\";t"]],
72
+ "dc = \" l o c a l \" , dc = \"+n,\\\"e\\\";t\"")
73
+ end
74
+
75
+ def test_parse_dn_in_rfc2253
76
+ assert_dn([
77
+ {"cn" => "Steve Kille"},
78
+ {"o" => "Isode Limited"},
79
+ {"c" => "GB"}
80
+ ],
81
+ "CN=Steve Kille,O=Isode Limited,C=GB")
82
+ assert_dn([
83
+ {"ou" => "Sales", "cn" => "J. Smith"},
84
+ {"o" => "Widget Inc."},
85
+ {"c" => "US"},
86
+ ],
87
+ "OU=Sales+CN=J. Smith,O=Widget Inc.,C=US")
88
+ assert_dn([
89
+ {"cn" => "L. Eagle"},
90
+ {"o" => "Sue, Grabbit and Runn"},
91
+ {"c" => "GB"},
92
+ ],
93
+ "CN=L. Eagle,O=Sue\\, Grabbit and Runn,C=GB")
94
+ assert_dn([
95
+ {"cn" => "Before\rAfter"},
96
+ {"o" => "Test"},
97
+ {"c" => "GB"}
98
+ ],
99
+ "CN=Before\\0DAfter,O=Test,C=GB")
100
+ assert_dn([
101
+ {"1.3.6.1.4.1.1466.0" => [0x04, 0x02, 0x48, 0x69].pack("C*")},
102
+ {"o" => "Test"},
103
+ {"c" => "GB"}
104
+ ],
105
+ "1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB")
106
+ assert_dn([{"sn" => "Lučić"}], "SN=Lu\\C4\\8Di\\C4\\87")
107
+ end
108
+
109
+ def test_parse_invalid_dn
110
+ assert_invalid_dn("attribute value is missing", "net")
111
+ assert_invalid_dn("attribute value is missing", "local,dc=net")
112
+ assert_invalid_dn("attribute value is missing", "dc=,dc=net")
113
+ assert_invalid_dn("attribute type is missing", "=local,dc=net")
114
+ assert_invalid_dn("name component is missing", ",dc=net")
115
+ assert_invalid_dn("name component is missing", "dc=local,")
116
+ assert_invalid_dn("found unmatched quotation", "dc=\"local")
117
+ assert_invalid_dn("found unmatched quotation", "dc=\"loc\\al\"")
118
+ end
119
+
120
+ def test_parse_quoted_comma_dn
121
+ assert_dn([["dc", "local,"]], "dc=local\\,")
122
+ end
123
+
124
+ def test_parser_collect_pairs
125
+ assert_dn_parser_collect_pairs(",", "\\,")
126
+ end
127
+
128
+ private
129
+ def assert_dn(expected, dn)
130
+ assert_equal(ActiveLdap::DN.new(*expected), ActiveLdap::DN.parse(dn))
131
+ end
132
+
133
+ def assert_invalid_dn(reason, dn)
134
+ exception = nil
135
+ assert_raise(ActiveLdap::DistinguishedNameInvalid) do
136
+ begin
137
+ ActiveLdap::DN.parse(dn)
138
+ rescue Exception
139
+ exception = $!
140
+ raise
141
+ end
142
+ end
143
+ assert_not_nil(exception)
144
+ assert_equal(dn, exception.dn)
145
+ assert_equal(_(reason), exception.reason)
146
+ end
147
+
148
+ def assert_dn_parser_collect_pairs(expected, source)
149
+ parser = ActiveLdap::DN::Parser.new(source)
150
+ assert_equal(expected,
151
+ parser.send(:collect_pairs, StringScanner.new(source)))
152
+ end
153
+
154
+ def assert_dn_minus(expected, subtrahend, minuend)
155
+ result = ActiveLdap::DN.parse(subtrahend) - ActiveLdap::DN.parse(minuend)
156
+ assert_equal(ActiveLdap::DN.parse(expected), result)
157
+ end
158
+
159
+ def assert_dn_minus_raise(subtrahend, minuend)
160
+ assert_raise(ArgumentError) do
161
+ ActiveLdap::DN.parse(subtrahend) - ActiveLdap::DN.parse(minuend)
162
+ end
163
+ end
164
+
165
+ def assert_dn_to_s(expected, dn)
166
+ assert_equal(expected, ActiveLdap::DN.parse(dn).to_s)
167
+ end
168
+
169
+ def parse(dn)
170
+ ActiveLdap::DN.parse(dn)
171
+ end
172
+ end
@@ -0,0 +1,176 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestFind < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ priority :must
7
+ def test_find_with_dn
8
+ make_temporary_user do |user,|
9
+ assert_equal(user.dn, @user_class.find(user.dn).dn)
10
+ assert_equal(user.dn, @user_class.find(ActiveLdap::DN.parse(user.dn)).dn)
11
+ end
12
+ end
13
+
14
+ priority :normal
15
+ def test_find_with_special_value_prefix
16
+ # \2C == ','
17
+ make_ou("a\\2Cb,ou=Users")
18
+ make_temporary_user(:uid => "user1,ou=a\\2Cb") do |user1,|
19
+ assert_equal([], @user_class.find(:all, :prefix => "ou=a,b").collect(&:dn))
20
+ params = {:prefix => "ou=a\\2Cb"}
21
+ assert_equal([user1.dn], @user_class.find(:all, params).collect(&:dn))
22
+ params = {:prefix => [["ou", "a,b"]]}
23
+ assert_equal([user1.dn], @user_class.find(:all, params).collect(&:dn))
24
+ end
25
+ end
26
+
27
+ def test_find_with_special_value_base
28
+ # \5C == '\'
29
+ make_ou("a\\5Cb,ou=Users")
30
+ make_temporary_user(:uid => "user1,ou=a\\5Cb") do |user1,|
31
+ base = @user_class.base
32
+ params = {:base => "ou=a\\b,#{base}"}
33
+ assert_equal([], @user_class.find(:all, params).collect(&:dn))
34
+ params = {:base => "ou=a\\5Cb,#{base}"}
35
+ assert_equal([user1.dn], @user_class.find(:all, params).collect(&:dn))
36
+ base_rdns = ActiveLdap::DN.parse(base).rdns
37
+ params = {:base => [["ou", "a\\b"]] + base_rdns}
38
+ assert_equal([user1.dn], @user_class.find(:all, params).collect(&:dn))
39
+ end
40
+ end
41
+
42
+ def test_find_with_sort_by_in_ldap_mapping
43
+ @user_class.ldap_mapping(:dn_attribute => @user_class.dn_attribute,
44
+ :prefix => @user_class.prefix,
45
+ :scope => @user_class.scope,
46
+ :classes => @user_class_classes,
47
+ :sort_by => "uid",
48
+ :order => "desc")
49
+ make_temporary_user(:uid => "user1") do |user1,|
50
+ make_temporary_user(:uid => "user2") do |user2,|
51
+ make_temporary_user(:uid => "user3") do |user3,|
52
+ users = @user_class.find(:all)
53
+ assert_equal(["user3", "user2", "user1"],
54
+ users.collect {|u| u.uid})
55
+
56
+ users = @user_class.find(:all, :order => "asc")
57
+ assert_equal(["user1", "user2", "user3"],
58
+ users.collect {|u| u.uid})
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ def test_find_operational_attributes
65
+ make_temporary_user do |user, password|
66
+ found_user = @user_class.find(user.uid, :attributes => ["*", "+"])
67
+ assert_equal(Time.now.utc.iso8601,
68
+ found_user.modify_timestamp.utc.iso8601)
69
+ end
70
+ end
71
+
72
+ def test_find_with_attributes_without_object_class
73
+ make_temporary_user do |user, password|
74
+ found_user = @user_class.find(user.uid, :attributes => ["uidNumber"])
75
+ assert_equal(user.uid_number, found_user.uid_number)
76
+ assert_equal(user.classes, found_user.classes)
77
+ assert_nil(found_user.gid_number)
78
+ end
79
+ end
80
+
81
+ def test_find_with_integer_value
82
+ make_temporary_user do |user, password|
83
+ found_user = @user_class.find(:attribute => "gidNumber",
84
+ :value => user.gid_number)
85
+ assert_equal(user.dn, found_user.dn)
86
+ end
87
+ end
88
+
89
+ def test_find_with_limit
90
+ make_temporary_user(:uid => "user1") do |user1,|
91
+ make_temporary_user(:uid => "user2") do |user2,|
92
+ make_temporary_user(:uid => "user3") do |user3,|
93
+ users = @user_class.find(:all)
94
+ assert_equal(["user1", "user2", "user3"].sort,
95
+ users.collect {|u| u.uid}.sort)
96
+
97
+ users = @user_class.find(:all, :limit => 2)
98
+ assert_operator([["user1", "user2"].sort,
99
+ ["user2", "user3"].sort,
100
+ ["user3", "user1"].sort],
101
+ :include?,
102
+ users.collect {|u| u.uid}.sort)
103
+
104
+ users = @user_class.find(:all, :limit => 1)
105
+ assert_operator([["user1"], ["user2"], ["user3"]],
106
+ :include?,
107
+ users.collect {|u| u.uid})
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ def test_find_all_with_dn_attribute_value
114
+ make_temporary_user(:uid => "user1") do |user1,|
115
+ make_temporary_user(:uid => "user2") do |user2,|
116
+ assert_equal(["user1"],
117
+ @user_class.find(:all, "*1").collect {|u| u.uid})
118
+ end
119
+ end
120
+ end
121
+
122
+ def test_find_with_sort
123
+ make_temporary_user(:uid => "user1") do |user1,|
124
+ make_temporary_user(:uid => "user2") do |user2,|
125
+ users = @user_class.find(:all, :sort_by => "uid", :order => 'asc')
126
+ assert_equal(["user1", "user2"], users.collect {|u| u.uid})
127
+ users = @user_class.find(:all, :sort_by => "uid", :order => 'desc')
128
+ assert_equal(["user2", "user1"], users.collect {|u| u.uid})
129
+
130
+ users = @user_class.find(:all, :order => 'asc')
131
+ assert_equal(["user1", "user2"], users.collect {|u| u.uid})
132
+ users = @user_class.find(:all, :order => 'desc')
133
+ assert_equal(["user2", "user1"], users.collect {|u| u.uid})
134
+
135
+ users = @user_class.find(:all, :order => 'asc', :limit => 1)
136
+ assert_equal(["user1"], users.collect {|u| u.uid})
137
+ users = @user_class.find(:all, :order => 'desc', :limit => 1)
138
+ assert_equal(["user2"], users.collect {|u| u.uid})
139
+ end
140
+ end
141
+ end
142
+
143
+ def test_split_search_value
144
+ assert_split_search_value([nil, "test-user", nil], "test-user")
145
+ assert_split_search_value([nil, "test-user", "ou=Sub"], "test-user,ou=Sub")
146
+ assert_split_search_value(["uid", "test-user", "ou=Sub"],
147
+ "uid=test-user,ou=Sub")
148
+ assert_split_search_value(["uid", "test-user", nil], "uid=test-user")
149
+ end
150
+
151
+ def test_find
152
+ make_temporary_user do |user, password|
153
+ assert_equal(user.uid, @user_class.find(:first).uid)
154
+ assert_equal(user.uid, @user_class.find(user.uid).uid)
155
+ options = {:attribute => "cn", :value => user.cn}
156
+ assert_equal(user.uid, @user_class.find(:first, options).uid)
157
+ assert_equal(user.uid, @user_class.find(options).uid)
158
+ assert_equal(user.to_ldif, @user_class.find(:first).to_ldif)
159
+ assert_equal([user.uid], @user_class.find(:all).collect {|u| u.uid})
160
+
161
+ make_temporary_user do |user2, password2|
162
+ assert_equal(user2.uid, @user_class.find(user2.uid).uid)
163
+ assert_equal([user2.uid],
164
+ @user_class.find(user2.uid(true)).collect {|u| u.uid})
165
+ assert_equal(user2.to_ldif, @user_class.find(user2.uid).to_ldif)
166
+ assert_equal([user.uid, user2.uid].sort,
167
+ @user_class.find(:all).collect {|u| u.uid}.sort)
168
+ end
169
+ end
170
+ end
171
+
172
+ private
173
+ def assert_split_search_value(expected, value)
174
+ assert_equal(expected, ActiveLdap::Base.send(:split_search_value, value))
175
+ end
176
+ end
@@ -0,0 +1,50 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestGroupadd < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ def setup
7
+ super
8
+ @command = File.join(@examples_dir, "groupadd")
9
+ end
10
+
11
+ priority :must
12
+
13
+ priority :normal
14
+ def test_exist_group
15
+ make_temporary_group do |group|
16
+ assert(@group_class.exists?(group.id))
17
+ assert_equal([false, "Group #{group.id} already exists.\n"],
18
+ run_command(group.id))
19
+ assert(@group_class.exists?(group.id))
20
+ end
21
+ end
22
+
23
+ def test_add_group
24
+ ensure_delete_group("test-group") do |gid|
25
+ assert_groupadd_successfully(gid)
26
+ end
27
+ end
28
+
29
+ private
30
+ def assert_groupadd_successfully(name, *args, &block)
31
+ _wrap_assertion do
32
+ assert(!@group_class.exists?(name))
33
+ args.concat([name])
34
+ assert_equal([true, ""], run_command(*args, &block))
35
+ assert(@group_class.exists?(name))
36
+
37
+ group = @group_class.find(name)
38
+ assert_equal(name, group.id)
39
+ end
40
+ end
41
+
42
+ def assert_groupadd_failed(name, message, *args, &block)
43
+ _wrap_assertion do
44
+ assert(!@group_class.exists?(name))
45
+ args.concat([name])
46
+ assert_equal([false, message], run_command(*args, &block))
47
+ assert(!@group_class.exists?(name))
48
+ end
49
+ end
50
+ end