activeldap 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/CHANGES +61 -0
  2. data/README +8 -1
  3. data/Rakefile +4 -1
  4. data/benchmark/bench-al.rb +12 -2
  5. data/examples/al-admin/app/controllers/account_controller.rb +4 -3
  6. data/examples/al-admin/app/controllers/application.rb +5 -2
  7. data/examples/al-admin/app/controllers/directory_controller.rb +3 -1
  8. data/examples/al-admin/app/controllers/users_controller.rb +19 -4
  9. data/examples/al-admin/app/controllers/welcome_controller.rb +4 -2
  10. data/examples/al-admin/app/helpers/application_helper.rb +7 -1
  11. data/examples/al-admin/app/helpers/url_helper.rb +4 -0
  12. data/examples/al-admin/app/models/ldap_user.rb +4 -0
  13. data/examples/al-admin/app/views/_entry/{_attributes_information.rhtml → _attributes_information.html.erb} +0 -0
  14. data/examples/al-admin/app/views/_entry/{_entry.rhtml → _entry.html.erb} +0 -0
  15. data/examples/al-admin/app/views/_schema/{_aliases.rhtml → _aliases.html.erb} +0 -0
  16. data/examples/al-admin/app/views/_switcher/{_after.rhtml → _after.html.erb} +0 -0
  17. data/examples/al-admin/app/views/_switcher/{_before.rhtml → _before.html.erb} +0 -0
  18. data/examples/al-admin/app/views/account/{login.rhtml → login.html.erb} +0 -0
  19. data/examples/al-admin/app/views/account/{sign_up.rhtml → sign_up.html.erb} +0 -0
  20. data/examples/al-admin/app/views/attributes/{_attributes.rhtml → _attributes.html.erb} +0 -0
  21. data/examples/al-admin/app/views/attributes/{_detail.rhtml → _detail.html.erb} +0 -0
  22. data/examples/al-admin/app/views/attributes/{index.rhtml → index.html.erb} +0 -0
  23. data/examples/al-admin/app/views/attributes/{show.rhtml → show.html.erb} +0 -0
  24. data/examples/al-admin/app/views/directory/{_tree.rhtml → _tree.html.erb} +0 -0
  25. data/examples/al-admin/app/views/directory/{_tree_view_js.rhtml → _tree_view_js.html.erb} +4 -5
  26. data/examples/al-admin/app/views/directory/{index.rhtml → index.html.erb} +0 -0
  27. data/examples/al-admin/app/views/directory/{populate.rhtml → populate.html.erb} +0 -0
  28. data/examples/al-admin/app/views/layouts/{_footer.rhtml → _footer.html.erb} +0 -0
  29. data/examples/al-admin/app/views/layouts/{_header_menu.rhtml → _header_menu.html.erb} +0 -0
  30. data/examples/al-admin/app/views/layouts/{_main_menu.rhtml → _main_menu.html.erb} +0 -0
  31. data/examples/al-admin/app/views/layouts/{application.rhtml → application.html.erb} +3 -2
  32. data/examples/al-admin/app/views/object_classes/{_attributes.rhtml → _attributes.html.erb} +0 -0
  33. data/examples/al-admin/app/views/object_classes/{_object_classes.rhtml → _object_classes.html.erb} +0 -0
  34. data/examples/al-admin/app/views/object_classes/{index.rhtml → index.html.erb} +0 -0
  35. data/examples/al-admin/app/views/object_classes/{show.rhtml → show.html.erb} +0 -0
  36. data/examples/al-admin/app/views/syntaxes/{_detail.rhtml → _detail.html.erb} +0 -0
  37. data/examples/al-admin/app/views/syntaxes/{_syntaxes.rhtml → _syntaxes.html.erb} +0 -0
  38. data/examples/al-admin/app/views/syntaxes/{index.rhtml → index.html.erb} +0 -0
  39. data/examples/al-admin/app/views/syntaxes/{show.rhtml → show.html.erb} +0 -0
  40. data/examples/al-admin/app/views/users/{_attributes_update_form.rhtml → _attributes_update_form.html.erb} +0 -0
  41. data/examples/al-admin/app/views/users/{_form.rhtml → _form.html.erb} +0 -0
  42. data/examples/al-admin/app/views/users/{_object_classes_update_form.rhtml → _object_classes_update_form.html.erb} +7 -1
  43. data/examples/al-admin/app/views/users/{_password_change_form.rhtml → _password_change_form.html.erb} +0 -0
  44. data/examples/al-admin/app/views/users/{edit.rhtml → edit.html.erb} +0 -0
  45. data/examples/al-admin/app/views/users/{index.rhtml → index.html.erb} +0 -0
  46. data/examples/al-admin/app/views/users/{show.rhtml → show.html.erb} +0 -0
  47. data/examples/al-admin/app/views/welcome/{index.rhtml → index.html.erb} +0 -0
  48. data/examples/al-admin/config/boot.rb +96 -32
  49. data/examples/al-admin/config/environment.rb +30 -36
  50. data/examples/al-admin/config/environments/development.rb +2 -5
  51. data/examples/al-admin/config/environments/production.rb +1 -0
  52. data/examples/al-admin/config/environments/test.rb +4 -1
  53. data/examples/al-admin/config/initializers/exception_notifier.rb +2 -0
  54. data/examples/al-admin/config/initializers/gettext.rb +1 -0
  55. data/examples/al-admin/config/initializers/inflections.rb +10 -0
  56. data/examples/al-admin/config/initializers/mime_types.rb +5 -0
  57. data/examples/al-admin/config/initializers/ralative_url_support.rb +1 -0
  58. data/examples/al-admin/config/routes.rb +24 -12
  59. data/examples/al-admin/lib/authenticated_system.rb +1 -1
  60. data/examples/al-admin/lib/tasks/gettext.rake +1 -1
  61. data/examples/al-admin/po/en/al-admin.po +102 -100
  62. data/examples/al-admin/po/ja/al-admin.po +112 -110
  63. data/examples/al-admin/po/nl/al-admin.po +117 -110
  64. data/examples/al-admin/public/javascripts/controls.js +484 -354
  65. data/examples/al-admin/public/javascripts/dragdrop.js +88 -58
  66. data/examples/al-admin/public/javascripts/effects.js +396 -364
  67. data/examples/al-admin/public/javascripts/prototype.js +2817 -1107
  68. data/examples/al-admin/public/stylesheets/base.css +5 -0
  69. data/examples/al-admin/script/performance/request +3 -0
  70. data/lib/active_ldap.rb +13 -10
  71. data/lib/active_ldap/adapter/base.rb +159 -43
  72. data/lib/active_ldap/adapter/jndi.rb +175 -0
  73. data/lib/active_ldap/adapter/jndi_connection.rb +180 -0
  74. data/lib/active_ldap/adapter/ldap.rb +91 -46
  75. data/lib/active_ldap/adapter/ldap_ext.rb +19 -5
  76. data/lib/active_ldap/adapter/net_ldap.rb +52 -44
  77. data/lib/active_ldap/association/has_many_wrap.rb +1 -1
  78. data/lib/active_ldap/attributes.rb +20 -95
  79. data/lib/active_ldap/base.rb +195 -186
  80. data/lib/active_ldap/callbacks.rb +33 -0
  81. data/lib/active_ldap/command.rb +3 -3
  82. data/lib/active_ldap/connection.rb +21 -3
  83. data/lib/active_ldap/distinguished_name.rb +18 -11
  84. data/lib/active_ldap/entry_attribute.rb +78 -0
  85. data/lib/active_ldap/human_readable.rb +20 -0
  86. data/lib/active_ldap/ldif.rb +860 -10
  87. data/lib/active_ldap/object_class.rb +6 -4
  88. data/lib/active_ldap/operations.rb +129 -22
  89. data/lib/active_ldap/schema.rb +118 -9
  90. data/lib/active_ldap/schema/syntaxes.rb +33 -16
  91. data/lib/active_ldap/validations.rb +74 -65
  92. data/po/en/active-ldap.po +378 -768
  93. data/po/ja/active-ldap.po +935 -868
  94. data/rails/plugin/active_ldap/init.rb +40 -2
  95. data/test/al-test-utils.rb +78 -58
  96. data/test/command.rb +51 -1
  97. data/test/test-unit-ext/priority.rb +29 -6
  98. data/test/test_adapter.rb +21 -2
  99. data/test/test_attributes.rb +13 -0
  100. data/test/test_base.rb +51 -1
  101. data/test/test_connection.rb +2 -1
  102. data/test/test_connection_per_class.rb +55 -1
  103. data/test/test_connection_per_dn.rb +29 -1
  104. data/test/test_find.rb +73 -0
  105. data/test/test_ldif.rb +1829 -15
  106. data/test/test_load.rb +126 -0
  107. data/test/test_object_class.rb +23 -5
  108. data/test/test_schema.rb +28 -0
  109. data/test/test_syntax.rb +22 -11
  110. data/test/test_user.rb +16 -25
  111. data/test/test_useradd-binary.rb +1 -1
  112. data/test/test_usermod-binary-add-time.rb +1 -1
  113. data/test/test_usermod-binary-add.rb +1 -1
  114. data/test/test_validation.rb +100 -22
  115. metadata +77 -71
  116. data/data/locale/en/LC_MESSAGES/active-ldap.mo +0 -0
  117. data/data/locale/ja/LC_MESSAGES/active-ldap.mo +0 -0
  118. data/examples/al-admin/app/views/layouts/_flash_box.rhtml +0 -4
  119. data/examples/al-admin/public/stylesheets/common.css +0 -2
  120. data/examples/al-admin/script/breakpointer +0 -3
@@ -1,7 +1,7 @@
1
1
  require_library_or_gem 'active_ldap'
2
2
  ActiveLdap::Base.logger ||= RAILS_DEFAULT_LOGGER
3
3
 
4
- required_version = ["0", "8", "4"]
4
+ required_version = ["0", "9", "1"]
5
5
  if (ActiveLdap::VERSION.split(".") <=> required_version) < 0
6
6
  ActiveLdap::Base.class_eval do
7
7
  format = _("You need ActiveLdap %s or later")
@@ -21,6 +21,44 @@ else
21
21
  end
22
22
  end
23
23
 
24
- class ActionView::Base
24
+ class ::ActionView::Base
25
25
  include ActiveLdap::Helper
26
26
  end
27
+
28
+ module ::ActionController
29
+ module LdapBenchmarking
30
+ def self.included(base)
31
+ base.class_eval do
32
+ alias_method_chain :render, :active_ldap_benchmark
33
+ alias_method_chain :rendering_runtime, :active_ldap
34
+ end
35
+ end
36
+
37
+ protected
38
+ def render_with_active_ldap_benchmark(*args, &block)
39
+ if logger
40
+ @ldap_runtime_before_render = ActiveLdap::Base.reset_runtime
41
+ result = render_without_active_ldap_benchmark(*args, &block)
42
+ @ldap_runtime_after_render = ActiveLdap::Base.reset_runtime
43
+ @rendering_runtime -= @ldap_runtime_after_render
44
+ result
45
+ else
46
+ render_without_active_ldap_benchmark(*args, &block)
47
+ end
48
+ end
49
+
50
+ private
51
+ def rendering_runtime_with_active_ldap(runtime)
52
+ result = rendering_runtime_without_active_ldap(runtime)
53
+ ldap_runtime = ActiveLdap::Base.reset_runtime
54
+ ldap_runtime += @ldap_runtime_before_render || 0
55
+ ldap_runtime += @ldap_runtime_after_render || 0
56
+ ldap_percentage = ldap_runtime * 100 / runtime
57
+ result + (" | LDAP: %.5f (%d%%)" % [ldap_runtime, ldap_percentage])
58
+ end
59
+ end
60
+
61
+ class Base
62
+ include LdapBenchmarking
63
+ end
64
+ end
@@ -17,6 +17,7 @@ module AlTestUtils
17
17
  def self.included(base)
18
18
  base.class_eval do
19
19
  include ActiveLdap::GetTextSupport
20
+ include Assertions
20
21
  include Config
21
22
  include Connection
22
23
  include Populate
@@ -26,6 +27,16 @@ module AlTestUtils
26
27
  end
27
28
  end
28
29
 
30
+ module Assertions
31
+ def assert_true(actual, *args)
32
+ assert_equal(true, actual, *args)
33
+ end
34
+
35
+ def assert_false(actual, *args)
36
+ assert_equal(false, actual, *args)
37
+ end
38
+ end
39
+
29
40
  module Config
30
41
  def setup
31
42
  super
@@ -49,12 +60,72 @@ module AlTestUtils
49
60
  raise "config file for testing doesn't exist: #{@config_file}"
50
61
  end
51
62
  config = YAML.load(ERB.new(File.read(@config_file)).result)
63
+ _adapter = adapter
52
64
  config.each do |key, value|
53
- adapter = ENV["ACTIVE_LDAP_TEST_ADAPTER"]
54
- value[:adapter] = adapter if adapter
65
+ value[:adapter] = _adapter if _adapter
55
66
  end
56
67
  config
57
68
  end
69
+
70
+ def adapter
71
+ ENV["ACTIVE_LDAP_TEST_ADAPTER"]
72
+ end
73
+ end
74
+
75
+ module ExampleFile
76
+ def certificate_path
77
+ File.join(@example_dir, 'example.der')
78
+ end
79
+
80
+ @@certificate = nil
81
+ def certificate
82
+ return @@certificate if @@certificate
83
+ if File.exists?(certificate_path)
84
+ @@certificate = File.read(certificate_path)
85
+ return @@certificate
86
+ end
87
+
88
+ require 'openssl'
89
+ rsa = OpenSSL::PKey::RSA.new(512)
90
+ comment = "Generated by Ruby/OpenSSL"
91
+
92
+ cert = OpenSSL::X509::Certificate.new
93
+ cert.version = 3
94
+ cert.serial = 0
95
+ subject = [["OU", "test"],
96
+ ["CN", Socket.gethostname]]
97
+ name = OpenSSL::X509::Name.new(subject)
98
+ cert.subject = name
99
+ cert.issuer = name
100
+ cert.not_before = Time.now
101
+ cert.not_after = Time.now + (365*24*60*60)
102
+ cert.public_key = rsa.public_key
103
+
104
+ ef = OpenSSL::X509::ExtensionFactory.new(nil, cert)
105
+ ef.issuer_certificate = cert
106
+ cert.extensions = [
107
+ ef.create_extension("basicConstraints","CA:FALSE"),
108
+ ef.create_extension("keyUsage", "keyEncipherment"),
109
+ ef.create_extension("subjectKeyIdentifier", "hash"),
110
+ ef.create_extension("extendedKeyUsage", "serverAuth"),
111
+ ef.create_extension("nsComment", comment),
112
+ ]
113
+ aki = ef.create_extension("authorityKeyIdentifier",
114
+ "keyid:always,issuer:always")
115
+ cert.add_extension(aki)
116
+ cert.sign(rsa, OpenSSL::Digest::SHA1.new)
117
+
118
+ @@certificate = cert.to_der
119
+ @@certificate
120
+ end
121
+
122
+ def jpeg_photo_path
123
+ File.join(@example_dir, 'example.jpg')
124
+ end
125
+
126
+ def jpeg_photo
127
+ File.open(jpeg_photo_path, "rb") {|f| f.read}
128
+ end
58
129
  end
59
130
 
60
131
  module Connection
@@ -153,7 +224,8 @@ module AlTestUtils
153
224
  end
154
225
 
155
226
  module TemporaryEntry
156
- @@certificate = nil
227
+ include ExampleFile
228
+
157
229
  def setup
158
230
  super
159
231
  @user_index = 0
@@ -218,8 +290,9 @@ module AlTestUtils
218
290
  yield(uid)
219
291
  ensure
220
292
  if @user_class.exists?(uid)
221
- @user_class.find(uid).remove_connection
222
- @user_class.delete(uid)
293
+ user = @user_class.find(uid)
294
+ user.remove_connection
295
+ @user_class.delete(user.dn)
223
296
  end
224
297
  end
225
298
 
@@ -236,59 +309,6 @@ module AlTestUtils
236
309
  def default_gid
237
310
  "10000#{@group_index}"
238
311
  end
239
-
240
- def certificate_path
241
- File.join(@example_dir, 'example.der')
242
- end
243
-
244
- def certificate
245
- return @@certificate if @@certificate
246
- if File.exists?(certificate_path)
247
- @@certificate = File.read(certificate_path)
248
- return @@certificate
249
- end
250
-
251
- require 'openssl'
252
- rsa = OpenSSL::PKey::RSA.new(512)
253
- comment = "Generated by Ruby/OpenSSL"
254
-
255
- cert = OpenSSL::X509::Certificate.new
256
- cert.version = 3
257
- cert.serial = 0
258
- subject = [["OU", "test"],
259
- ["CN", Socket.gethostname]]
260
- name = OpenSSL::X509::Name.new(subject)
261
- cert.subject = name
262
- cert.issuer = name
263
- cert.not_before = Time.now
264
- cert.not_after = Time.now + (365*24*60*60)
265
- cert.public_key = rsa.public_key
266
-
267
- ef = OpenSSL::X509::ExtensionFactory.new(nil, cert)
268
- ef.issuer_certificate = cert
269
- cert.extensions = [
270
- ef.create_extension("basicConstraints","CA:FALSE"),
271
- ef.create_extension("keyUsage", "keyEncipherment"),
272
- ef.create_extension("subjectKeyIdentifier", "hash"),
273
- ef.create_extension("extendedKeyUsage", "serverAuth"),
274
- ef.create_extension("nsComment", comment),
275
- ]
276
- aki = ef.create_extension("authorityKeyIdentifier",
277
- "keyid:always,issuer:always")
278
- cert.add_extension(aki)
279
- cert.sign(rsa, OpenSSL::Digest::SHA1.new)
280
-
281
- @@certificate = cert.to_der
282
- @@certificate
283
- end
284
-
285
- def jpeg_photo_path
286
- File.join(@example_dir, 'example.jpg')
287
- end
288
-
289
- def jpeg_photo
290
- File.read(jpeg_photo_path)
291
- end
292
312
  end
293
313
 
294
314
  module CommandSupport
@@ -27,11 +27,12 @@ module Command
27
27
  end
28
28
  end
29
29
 
30
- def run(cmd, *args)
30
+ def run(cmd, *args, &block)
31
31
  raise ArgumentError, "command isn't specified" if cmd.nil?
32
32
  if args.any? {|x| x.nil?}
33
33
  raise ArgumentError, "args has nil: #{args.inspect}"
34
34
  end
35
+ return java_run(cmd, *args, &block) unless Kernel.respond_to?(:fork)
35
36
  in_r, in_w = IO.pipe
36
37
  out_r, out_w = IO.pipe
37
38
  pid = exit_status = nil
@@ -59,4 +60,53 @@ module Command
59
60
  pid, status = Process.waitpid2(pid)
60
61
  [status.exited? && status.exitstatus.zero?, out_r.read]
61
62
  end
63
+
64
+ def java_run(cmd, *args, &block)
65
+ runtime = java.lang.Runtime.get_runtime
66
+ process = runtime.exec([cmd, *args].to_java(:string))
67
+ input = JavaReaderWrapper.new(process.get_input_stream)
68
+ output = JavaWriterWrapper.new(process.get_output_stream)
69
+ error = JavaReaderWrapper.new(process.get_error_stream)
70
+ yield(input, output) if block_given?
71
+ output.close
72
+ success = process.wait_for.zero?
73
+
74
+ [success, input.read + error.read]
75
+ end
76
+
77
+ class JavaReaderWrapper
78
+ def initialize(input)
79
+ @input = input
80
+ end
81
+
82
+ def read
83
+ result = ""
84
+ while (c = @input.read) != -1
85
+ result << c.chr
86
+ end
87
+ result
88
+ end
89
+ end
90
+
91
+ class JavaWriterWrapper
92
+ def initialize(output)
93
+ output = java.io.OutputStreamWriter.new(output)
94
+ @output = java.io.BufferedWriter.new(output)
95
+ end
96
+
97
+ def puts(*messages)
98
+ messages.each do |message|
99
+ message += "\n" if /\n/ !~ message
100
+ @output.write(message)
101
+ end
102
+ end
103
+
104
+ def flush
105
+ @output.flush
106
+ end
107
+
108
+ def close
109
+ @output.close
110
+ end
111
+ end
62
112
  end
@@ -23,12 +23,16 @@ module Test
23
23
  end
24
24
  end
25
25
 
26
+ alias_method :method_added_without_priority, :method_added
26
27
  def method_added(name)
28
+ method_added_without_priority(name)
27
29
  set_priority(name) if defined?(@priority_initialized)
28
30
  end
29
31
 
30
32
  def priority(name, *tests)
31
- unless private_methods.include?(priority_check_method_name(name))
33
+ singleton_class = (class << self; self; end)
34
+ priority_check_method = priority_check_method_name(name)
35
+ unless singleton_class.private_method_defined?(priority_check_method)
32
36
  raise ArgumentError, "unknown priority: #{name}"
33
37
  end
34
38
  if tests.empty?
@@ -106,16 +110,35 @@ module Test
106
110
  end
107
111
 
108
112
  def result_dir
109
- dir = File.join(File.dirname($0), ".test-result",
110
- self.class.name, @method_name.to_s)
113
+ components = [".test-result", self.class.name, @method_name.to_s]
114
+ dir = File.join(File.dirname($0), *components)
111
115
  dir = File.expand_path(dir)
112
- FileUtils.mkdir_p(dir)
116
+ begin
117
+ FileUtils.mkdir_p(dir)
118
+ rescue Errno::EACCES
119
+ retry_dir = File.join(File.dirname(__FILE__), "..", *components)
120
+ retry_dir = File.expand_path(retry_dir)
121
+ raise if retry_dir == dir
122
+ dir = retry_dir
123
+ retry
124
+ end
113
125
  dir
114
126
  end
115
127
 
116
128
  def passed_file
117
129
  File.join(result_dir, "passed")
118
130
  end
131
+
132
+ def escaped_method_name
133
+ @method_name.to_s.gsub(/[!?]$/) do |matched|
134
+ case matched
135
+ when "!"
136
+ ".destructive"
137
+ when "?"
138
+ ".predicate"
139
+ end
140
+ end
141
+ end
119
142
  end
120
143
 
121
144
  class TestSuite
@@ -150,9 +173,9 @@ module Test
150
173
  end
151
174
 
152
175
  class AutoRunner
153
- alias_method :original_options, :options
176
+ alias_method :options_without_priority, :options
154
177
  def options
155
- opts = original_options
178
+ opts = options_without_priority
156
179
  opts.on("--[no-]priority", "use priority mode") do |bool|
157
180
  TestSuite.priority_mode = bool
158
181
  end
@@ -10,6 +10,19 @@ class TestAdapter < Test::Unit::TestCase
10
10
  end
11
11
 
12
12
  priority :must
13
+ def test_operator
14
+ assert_parse_filter("(uid~=Alice)", ["uid", "~=", "Alice"])
15
+ assert_parse_filter("(&(uid~=Alice)(uid~=Bob))",
16
+ ["uid", "~=", "Alice", "Bob"])
17
+ assert_parse_filter("(uid~=Alice)", [["uid", "~=", "Alice"]])
18
+ assert_parse_filter("(|(uid~=Alice)(uid~=Bob))",
19
+ [:or,
20
+ ["uid", "~=", "Alice"],
21
+ ["uid", "~=", "Bob"]])
22
+ assert_parse_filter("(|(uid~=Alice)(uid~=Bob))",
23
+ [:or,
24
+ ["uid", "~=", "Alice", "Bob"]])
25
+ end
13
26
 
14
27
  priority :normal
15
28
  def test_filter_with_escaped_character
@@ -73,14 +86,20 @@ class TestAdapter < Test::Unit::TestCase
73
86
  assert_parse_filter("(&(gidNumber=100001)" +
74
87
  "(|(uid=temp-user1)(uid=temp-user2)))",
75
88
  [:and,
76
- [:and, {"gidNumber"=>["100001"]}],
77
- [:or, {"uid"=>["temp-user1", "temp-user2"]}]])
89
+ [:and, {"gidNumber" => ["100001"]}],
90
+ [:or, {"uid" => ["temp-user1", "temp-user2"]}]])
78
91
  assert_parse_filter("(&(gidNumber=100001)" +
79
92
  "(objectClass=person)(objectClass=posixAccount))",
80
93
  [:and,
81
94
  [:or, ["gidNumber", "100001"]],
82
95
  ["objectClass", "person"],
83
96
  ["objectClass", "posixAccount"]])
97
+ assert_parse_filter("(&(!(|(gidNumber=100001)(gidNumber=100002)))" +
98
+ "(objectClass=person)(!(objectClass=posixAccount)))",
99
+ [:and,
100
+ [:not, [:or, ["gidNumber", "100001", "100002"]]],
101
+ ["objectClass", "person"],
102
+ [:not, ["objectClass", "posixAccount"]]])
84
103
  end
85
104
 
86
105
  def test_invalid_operator
@@ -34,12 +34,25 @@ class TestAttributes < Test::Unit::TestCase
34
34
  ActiveLdap::Base.normalize_attribute("userCertificate", []))
35
35
  assert_equal(["usercertificate", [{"binary" => []}]],
36
36
  ActiveLdap::Base.normalize_attribute("userCertificate", nil))
37
+ assert_equal(["usercertificate", [{"binary" => "BINARY DATA"}]],
38
+ ActiveLdap::Base.normalize_attribute("userCertificate",
39
+ "BINARY DATA"))
40
+ assert_equal(["usercertificate", [{"binary" => ["BINARY DATA"]}]],
41
+ ActiveLdap::Base.normalize_attribute("userCertificate",
42
+ {"binary" =>
43
+ ["BINARY DATA"]}))
37
44
  end
38
45
 
39
46
  def test_unnormalize_attribute
47
+ assert_equal({"sn" => ["Surname"]},
48
+ ActiveLdap::Base.unnormalize_attribute("sn", ["Surname"]))
40
49
  assert_equal({"userCertificate;binary" => []},
41
50
  ActiveLdap::Base.unnormalize_attribute("userCertificate",
42
51
  [{"binary" => []}]))
52
+ assert_equal({"userCertificate;binary" => ["BINARY DATA"]},
53
+ ActiveLdap::Base.unnormalize_attribute("userCertificate",
54
+ [{"binary" =>
55
+ ["BINARY DATA"]}]))
43
56
  end
44
57
 
45
58
  def test_attr_protected
@@ -1,11 +1,50 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'al-test-utils'
2
3
 
3
4
  class TestBase < Test::Unit::TestCase
4
5
  include AlTestUtils
5
6
 
6
7
  priority :must
8
+ def test_excluded_classes
9
+ mapping = {:classes => ["person"]}
10
+ person_class = Class.new(@user_class)
11
+ person_class.ldap_mapping(mapping)
12
+
13
+ no_organizational_person_class = Class.new(@user_class)
14
+ no_organizational_person_mapping =
15
+ mapping.merge(:excluded_classes => ["organizationalPerson"])
16
+ no_organizational_person_class.ldap_mapping(no_organizational_person_mapping)
17
+
18
+ no_simple_person_class = Class.new(@user_class)
19
+ no_simple_person_mapping =
20
+ mapping.merge(:excluded_classes => ['shadowAccount', 'inetOrgPerson',
21
+ "organizationalPerson"])
22
+ no_simple_person_class.ldap_mapping(no_simple_person_mapping)
23
+
24
+ make_temporary_user do |user1,|
25
+ make_temporary_user(:simple => true) do |user2,|
26
+ assert_equal([user1.dn, user2.dn].sort,
27
+ person_class.find(:all).collect(&:dn).sort)
28
+
29
+ no_organizational_people = no_organizational_person_class.find(:all)
30
+ assert_equal([user2.dn].sort,
31
+ no_organizational_people.collect(&:dn).sort)
32
+
33
+ assert_equal([user2.dn].sort,
34
+ no_simple_person_class.find(:all).collect(&:dn).sort)
35
+ end
36
+ end
37
+ end
7
38
 
8
39
  priority :normal
40
+ def test_new_with_dn
41
+ cn = "XXX"
42
+ dn = "cn=#{cn},#{@user_class.base}"
43
+ user = @user_class.new(ActiveLdap::DN.parse(dn))
44
+ assert_equal(cn, user.cn)
45
+ assert_equal(dn, user.dn)
46
+ end
47
+
9
48
  def test_dn_attribute_per_instance_with_invalid_value
10
49
  user = @user_class.new
11
50
  assert_equal("uid", user.dn_attribute)
@@ -134,6 +173,15 @@ class TestBase < Test::Unit::TestCase
134
173
  ou_class.search(:value => name).collect {|dn, attrs| dn})
135
174
  end
136
175
 
176
+ def test_search_with_attributes_without_object_class
177
+ make_temporary_user do |user, password|
178
+ entries = @user_class.search(:filter => "#{user.dn_attribute}=#{user.id}",
179
+ :attributes => ["uidNumber"])
180
+ assert_equal([[user.dn, {"uidNumber" => [user.uid_number.to_s]}]],
181
+ entries)
182
+ end
183
+ end
184
+
137
185
  def test_new_without_argument
138
186
  user = @user_class.new
139
187
  assert_equal(@user_class_classes, user.classes)
@@ -343,7 +391,9 @@ class TestBase < Test::Unit::TestCase
343
391
  user2.attributes.reject {|k, v| k == "cn"})
344
392
 
345
393
  user2.reload
346
- assert_equal(user1.attributes, user2.attributes)
394
+ assert_equal(user1.cn, user2.cn)
395
+ assert_equal(user1.attributes.reject {|k, v| k == "cn"},
396
+ user2.attributes.reject {|k, v| k == "cn"})
347
397
  end
348
398
  end
349
399