activeldap 5.2.4 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,11 +17,12 @@ module ActiveLdap
17
17
  if attribute_or_name.is_a?(Schema::Attribute)
18
18
  name = attribute_or_name.name
19
19
  else
20
- attribute = schema.attribute(attribute_or_name.to_s)
20
+ attribute_name = attribute_or_name.to_s
21
+ attribute = schema.attribute(attribute_name)
21
22
  return nil if attribute.id.nil?
22
- if attribute.name == attribute_or_name or
23
- attribute.aliases.include?(attribute_or_name.to_s)
24
- name = attribute_or_name
23
+ if attribute.name == attribute_name or
24
+ attribute.aliases.include?(attribute_name)
25
+ name = attribute_name
25
26
  else
26
27
  return nil
27
28
  end
@@ -22,9 +22,23 @@ module ActiveLdap
22
22
  end
23
23
 
24
24
  module Common
25
- VALID_SEARCH_OPTIONS = [:attribute, :value, :filter, :prefix,
26
- :classes, :scope, :limit, :attributes,
27
- :sort_by, :order, :connection, :base, :offset]
25
+ VALID_SEARCH_OPTIONS = [
26
+ :attribute,
27
+ :value,
28
+ :filter,
29
+ :prefix,
30
+ :classes,
31
+ :scope,
32
+ :limit,
33
+ :attributes,
34
+ :sort_by,
35
+ :order,
36
+ :connection,
37
+ :base,
38
+ :offset,
39
+ :use_paged_results,
40
+ :page_size,
41
+ ]
28
42
 
29
43
  def search(options={}, &block)
30
44
  validate_search_options(options)
@@ -62,6 +76,8 @@ module ActiveLdap
62
76
  :attributes => requested_attributes,
63
77
  :sort_by => options[:sort_by] || sort_by,
64
78
  :order => options[:order] || order,
79
+ :use_paged_results => options[:use_paged_results],
80
+ :page_size => options[:page_size],
65
81
  }
66
82
  options[:connection] ||= connection
67
83
  values = []
@@ -96,10 +112,11 @@ module ActiveLdap
96
112
  }
97
113
 
98
114
  attribute = attr || ensure_search_attribute
115
+ escaped_value = DN.escape_value(value)
99
116
  options_for_non_leaf = {
100
117
  :attribute => attr,
101
118
  :value => value,
102
- :prefix => ["#{attribute}=#{value}", prefix].compact.join(","),
119
+ :prefix => ["#{attribute}=#{escaped_value}", prefix].compact.join(","),
103
120
  :limit => 1,
104
121
  :scope => :base,
105
122
  }
@@ -1,3 +1,3 @@
1
1
  module ActiveLdap
2
- VERSION = "5.2.4"
2
+ VERSION = "6.0.0"
3
3
  end
@@ -23,6 +23,7 @@ module AlTestUtils
23
23
  include TemporaryEntry
24
24
  include CommandSupport
25
25
  include MockLogger
26
+ include Omittable
26
27
  end
27
28
  end
28
29
 
@@ -39,7 +40,13 @@ module AlTestUtils
39
40
  @top_dir = File.expand_path(File.join(@base_dir, ".."))
40
41
  @example_dir = File.join(@top_dir, "examples")
41
42
  @fixtures_dir = File.join(@base_dir, "fixtures")
42
- @config_file = File.join(@base_dir, "config.yaml")
43
+ current_config_file = File.expand_path("config.yaml")
44
+ test_config_file = File.join(@base_dir, "config.yaml")
45
+ if File.exist?(current_config_file)
46
+ @config_file = current_config_file
47
+ else
48
+ @config_file = test_config_file
49
+ end
43
50
  ActiveLdap::Base.configurations = read_config
44
51
  end
45
52
 
@@ -273,41 +280,69 @@ module AlTestUtils
273
280
  super
274
281
  @user_index = 0
275
282
  @group_index = 0
283
+ @temporary_uids = []
284
+ end
285
+
286
+ def teardown
287
+ @temporary_uids.each do |uid|
288
+ delete_temporary_user(uid)
289
+ end
290
+ super
291
+ end
292
+
293
+ def delete_temporary_user(uid)
294
+ return unless @user_class.exists?(uid)
295
+ @user_class.search(:value => uid) do |dn, attribute|
296
+ @user_class.remove_connection(dn)
297
+ @user_class.delete(dn)
298
+ end
299
+ end
300
+
301
+ def build_temporary_user(config={})
302
+ uid = config[:uid] || "temp-user#{@user_index}"
303
+ password = config[:password] || "password#{@user_index}"
304
+ uid_number = config[:uid_number] || default_uid
305
+ gid_number = config[:gid_number] || default_gid
306
+ home_directory = config[:home_directory] || "/nonexistent"
307
+ see_also = config[:see_also]
308
+ user = nil
309
+ _wrap_assertion do
310
+ assert(!@user_class.exists?(uid))
311
+ assert_raise(ActiveLdap::EntryNotFound) do
312
+ @user_class.find(uid).dn
313
+ end
314
+ user = @user_class.new(uid)
315
+ assert(user.new_entry?)
316
+ user.cn = user.uid
317
+ user.sn = user.uid
318
+ user.uid_number = uid_number
319
+ user.gid_number = gid_number
320
+ user.home_directory = home_directory
321
+ user.user_password = ActiveLdap::UserPassword.ssha(password)
322
+ user.see_also = see_also
323
+ unless config[:simple]
324
+ user.add_class('shadowAccount', 'inetOrgPerson',
325
+ 'organizationalPerson')
326
+ user.user_certificate = certificate
327
+ user.jpeg_photo = jpeg_photo
328
+ end
329
+ user.save
330
+ assert(!user.new_entry?)
331
+ end
332
+ [@user_class.find(user.uid), password]
276
333
  end
277
334
 
278
335
  def make_temporary_user(config={})
279
336
  @user_index += 1
280
- uid = config[:uid] || "temp-user#{@user_index}"
281
- ensure_delete_user(uid) do
282
- password = config[:password] || "password#{@user_index}"
283
- uid_number = config[:uid_number] || default_uid
284
- gid_number = config[:gid_number] || default_gid
285
- home_directory = config[:home_directory] || "/nonexistent"
286
- see_also = config[:see_also]
287
- _wrap_assertion do
288
- assert(!@user_class.exists?(uid))
289
- assert_raise(ActiveLdap::EntryNotFound) do
290
- @user_class.find(uid).dn
291
- end
292
- user = @user_class.new(uid)
293
- assert(user.new_entry?)
294
- user.cn = user.uid
295
- user.sn = user.uid
296
- user.uid_number = uid_number
297
- user.gid_number = gid_number
298
- user.home_directory = home_directory
299
- user.user_password = ActiveLdap::UserPassword.ssha(password)
300
- user.see_also = see_also
301
- unless config[:simple]
302
- user.add_class('shadowAccount', 'inetOrgPerson',
303
- 'organizationalPerson')
304
- user.user_certificate = certificate
305
- user.jpeg_photo = jpeg_photo
306
- end
307
- user.save
308
- assert(!user.new_entry?)
309
- yield(@user_class.find(user.uid), password)
337
+ config = config.merge(uid: config[:uid] || "temp-user#{@user_index}")
338
+ uid = config[:uid]
339
+ @temporary_uids << uid
340
+ if block_given?
341
+ ensure_delete_user(uid) do
342
+ yield(*build_temporary_user(config))
310
343
  end
344
+ else
345
+ build_temporary_user(config)
311
346
  end
312
347
  end
313
348
 
@@ -334,12 +369,8 @@ module AlTestUtils
334
369
  def ensure_delete_user(uid)
335
370
  yield(uid)
336
371
  ensure
337
- if @user_class.exists?(uid)
338
- @user_class.search(:value => uid) do |dn, attribute|
339
- @user_class.remove_connection(dn)
340
- @user_class.delete(dn)
341
- end
342
- end
372
+ delete_temporary_user(uid)
373
+ @temporary_uids.delete(uid)
343
374
  end
344
375
 
345
376
  def ensure_delete_group(cn)
@@ -373,6 +404,10 @@ module AlTestUtils
373
404
  end
374
405
 
375
406
  def run_command(*args, &block)
407
+ if RUBY_VERSION >= "2.7"
408
+ omit("Need to fix an optional arguments warning in net-ldap: " +
409
+ "ruby-ldap/ruby-net-ldap/pull/342")
410
+ end
376
411
  file = Tempfile.new("al-command-support")
377
412
  file.open
378
413
  file.puts(ActiveLdap::Base.configurations["test"].to_yaml)
@@ -425,4 +460,16 @@ module AlTestUtils
425
460
  ActiveLdap::Base.logger = original_logger
426
461
  end
427
462
  end
463
+
464
+ module Omittable
465
+ def omit_if_jruby(message=nil)
466
+ return unless RUBY_PLATFORM == "java"
467
+ omit(message || "This test is not for JRuby")
468
+ end
469
+
470
+ def omit_if_ldap(message=nil)
471
+ return unless current_configuration[:adapter] == "ldap"
472
+ omit(message || "This test is not for ruby-ldap")
473
+ end
474
+ end
428
475
  end
@@ -150,13 +150,13 @@ class TestBase < Test::Unit::TestCase
150
150
  _ou_class.create("root2")
151
151
  assert_equal(["base",
152
152
  "root1", "child1", "child2", "domain", "child3",
153
- "root2"],
154
- _entry_class.find(:all).collect(&:id))
153
+ "root2"].sort,
154
+ _entry_class.find(:all).collect(&:id).sort)
155
155
  assert_raise(ActiveLdap::DeleteError) do
156
156
  root1.destroy_all
157
157
  end
158
- assert_equal(["base", "root1", "domain", "root2"],
159
- _entry_class.find(:all).collect(&:id))
158
+ assert_equal(["base", "root1", "domain", "root2"].sort,
159
+ _entry_class.find(:all).collect(&:id).sort)
160
160
  end
161
161
 
162
162
  def test_delete_mixed_tree_by_instance
@@ -173,13 +173,13 @@ class TestBase < Test::Unit::TestCase
173
173
  _ou_class.create("root2")
174
174
  assert_equal(["base",
175
175
  "root1", "child1", "child2", "domain", "child3",
176
- "root2"],
177
- _entry_class.find(:all).collect(&:id))
176
+ "root2"].sort,
177
+ _entry_class.find(:all).collect(&:id).sort)
178
178
  assert_raise(ActiveLdap::DeleteError) do
179
179
  root1.delete_all
180
180
  end
181
- assert_equal(["base", "root1", "domain", "root2"],
182
- _entry_class.find(:all).collect(&:id))
181
+ assert_equal(["base", "root1", "domain", "root2"].sort,
182
+ _entry_class.find(:all).collect(&:id).sort)
183
183
  end
184
184
 
185
185
  def test_delete_tree
@@ -189,8 +189,8 @@ class TestBase < Test::Unit::TestCase
189
189
  _ou_class.create(:ou => "child1", :parent => root1)
190
190
  _ou_class.create(:ou => "child2", :parent => root1)
191
191
  _ou_class.create("root2")
192
- assert_equal(["base", "root1", "child1", "child2", "root2"],
193
- _ou_class.find(:all).collect(&:ou))
192
+ assert_equal(["base", "root1", "child1", "child2", "root2"].sort,
193
+ _ou_class.find(:all).collect(&:ou).sort)
194
194
  _ou_class.delete_all(:base => root1.dn)
195
195
  assert_equal(["base", "root2"],
196
196
  _ou_class.find(:all).collect(&:ou))
@@ -217,11 +217,11 @@ class TestBase < Test::Unit::TestCase
217
217
  :classes => ["top"]
218
218
  entry_class.dn_attribute = nil
219
219
  assert_equal(["base", "root1", "child1", "domain1", "grandchild1",
220
- "child2", "domain2", "root2"],
221
- entry_class.find(:all).collect(&:id))
220
+ "child2", "domain2", "root2"].sort,
221
+ entry_class.find(:all).collect(&:id).sort)
222
222
  entry_class.delete_all(nil, :base => child2.dn)
223
- assert_equal(["base", "root1", "child1", "domain1", "grandchild1", "root2"],
224
- entry_class.find(:all).collect(&:id))
223
+ assert_equal(["base", "root1", "child1", "domain1", "grandchild1", "root2"].sort,
224
+ entry_class.find(:all).collect(&:id).sort)
225
225
  end
226
226
 
227
227
  def test_first
@@ -3,6 +3,7 @@ require 'al-test-utils'
3
3
  class TestConnection < Test::Unit::TestCase
4
4
  include AlTestUtils::Config
5
5
  include AlTestUtils::MockLogger
6
+ include AlTestUtils::Omittable
6
7
 
7
8
  def setup
8
9
  super
@@ -23,6 +24,9 @@ class TestConnection < Test::Unit::TestCase
23
24
  end
24
25
 
25
26
  def test_retry_limit_0_with_nonexistent_host_with_timeout
27
+ omit_if_ldap("this test will take a long time...")
28
+ omit_if_jruby("JNI adapter returns connection error immediately. " +
29
+ "So timeout isn't invoked.")
26
30
  config = current_configuration.merge("host" => "192.168.29.29",
27
31
  "retry_limit" => 0,
28
32
  "timeout" => 1)
@@ -3,7 +3,18 @@ require 'al-test-utils'
3
3
  class TestFind < Test::Unit::TestCase
4
4
  include AlTestUtils
5
5
 
6
- priority :must
6
+ def test_find_paged
7
+ page_size = 126
8
+ n_users = page_size + 1
9
+ uids = n_users.times.collect do
10
+ user, _password = make_temporary_user
11
+ user.uid
12
+ end
13
+ users = @user_class.find(:all, page_size: page_size)
14
+ assert_equal(uids.sort,
15
+ users.collect(&:uid).sort)
16
+ end
17
+
7
18
  def test_find_with_dn
8
19
  make_temporary_user do |user,|
9
20
  assert_equal(user.dn, @user_class.find(user.dn).dn)
@@ -11,7 +22,6 @@ class TestFind < Test::Unit::TestCase
11
22
  end
12
23
  end
13
24
 
14
- priority :normal
15
25
  def test_find_with_special_value_prefix
16
26
  # \2C == ','
17
27
  make_ou("a\\2Cb,ou=Users")
@@ -17,7 +17,7 @@ class TestSupportedControl < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  def test_false
20
- assert_true(paged_results?(ActiveLdap::LdapControls::PAGED_RESULTS))
20
+ assert_false(paged_results?(ActiveLdap::LdapControls::ASSERTION))
21
21
  end
22
22
  end
23
23
  end
@@ -52,8 +52,8 @@ class TestValidation < Test::Unit::TestCase
52
52
  user1.id = user2.id
53
53
  assert_false(user1.save)
54
54
 
55
- format = la_('distinguishedName').humanize
56
- format << ' ' << _("is duplicated: %s")
55
+ format = human_attribute_name("distinguishedName")
56
+ format << " " << _("is duplicated: %s")
57
57
  assert_equal([format % [user2.dn.to_s]],
58
58
  user1.errors.full_messages)
59
59
  end
@@ -66,8 +66,8 @@ class TestValidation < Test::Unit::TestCase
66
66
  user.jpeg_photo = "XXX"
67
67
  assert_not_predicate(user, :save)
68
68
 
69
- format = la_('jpegPhoto').humanize
70
- format << ' ' << _("has invalid format: %s: required syntax: %s: %s")
69
+ format = human_attribute_name('jpegPhoto')
70
+ format << " " << _("has invalid format: %s: required syntax: %s: %s")
71
71
  arguments = [_("<binary-value>"),
72
72
  lsd_("1.3.6.1.4.1.1466.115.121.1.28"),
73
73
  _("invalid JPEG format")]
@@ -112,8 +112,8 @@ class TestValidation < Test::Unit::TestCase
112
112
  reason = _("attribute value is missing")
113
113
  invalid_format = _("%s is invalid distinguished name (DN): %s")
114
114
  invalid_message = invalid_format % ["uid==,#{user.class.base}", reason]
115
- format = la_('distinguishedName').humanize
116
- format << ' ' << _("is invalid: %s")
115
+ format = human_attribute_name("distinguishedName")
116
+ format << " " << _("is invalid: %s")
117
117
  message = format % invalid_message
118
118
  assert_equal([message],
119
119
  user.errors.full_messages.find_all {|m| /DN/ =~ m})
@@ -126,8 +126,8 @@ class TestValidation < Test::Unit::TestCase
126
126
  reason = _("attribute value is missing")
127
127
  invalid_format = _("%s is invalid distinguished name (DN): %s")
128
128
  invalid_message = invalid_format % ["uid==,#{user.class.base}", reason]
129
- format = la_('distinguishedName').humanize
130
- format << ' ' << _("is invalid: %s")
129
+ format = human_attribute_name("distinguishedName")
130
+ format << " " << _("is invalid: %s")
131
131
  message = format % invalid_message
132
132
  assert_equal([message], user.errors.full_messages)
133
133
  end
@@ -138,8 +138,8 @@ class TestValidation < Test::Unit::TestCase
138
138
  assert(user.valid?)
139
139
  user.uid_number = ""
140
140
  assert(!user.valid?)
141
- format = la_('uidNumber').humanize
142
- format << ' ' << _("is required attribute by objectClass '%s'")
141
+ format = human_attribute_name("uidNumber")
142
+ format << " " << _("is required attribute by objectClass '%s'")
143
143
  blank_message = format % loc_("posixAccount")
144
144
  assert_equal([blank_message], user.errors.full_messages)
145
145
  end
@@ -150,8 +150,8 @@ class TestValidation < Test::Unit::TestCase
150
150
  assert(user.save)
151
151
  user.class.excluded_classes = ['person']
152
152
  assert(!user.save)
153
- format = la_("objectClass").humanize
154
- format << ' ' << n_("has excluded value: %s",
153
+ format = human_attribute_name("objectClass")
154
+ format << " " << n_("has excluded value: %s",
155
155
  "has excluded values: %s",
156
156
  1)
157
157
  message = format % loc_("person")
@@ -222,8 +222,8 @@ class TestValidation < Test::Unit::TestCase
222
222
  assert(ou_class.new("YYY").save)
223
223
  ou = ou_class.new("YYY")
224
224
  assert(!ou.save)
225
- format = la_("distinguishedName").humanize
226
- format << ' ' << _("is duplicated: %s")
225
+ format = human_attribute_name("distinguishedName")
226
+ format << " " << _("is duplicated: %s")
227
227
  message = format % ou.dn
228
228
  assert_equal([message], ou.errors.full_messages)
229
229
  end
@@ -259,12 +259,16 @@ class TestValidation < Test::Unit::TestCase
259
259
  end
260
260
 
261
261
  private
262
+ def human_attribute_name(name)
263
+ la_(name).dup
264
+ end
265
+
262
266
  def assert_invalid_value(name, formatted_value, syntax, reason, model, option)
263
267
  syntax_description = lsd_(syntax)
264
268
  assert_not_nil(syntax_description)
265
269
  params = [formatted_value, syntax_description, reason]
266
270
  params.unshift(option) if option
267
- localized_name = la_(name).humanize
271
+ localized_name = human_attribute_name(name)
268
272
  format = localized_name << ' '
269
273
  if option
270
274
  format << _("(%s) has invalid format: %s: required syntax: %s: %s")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeldap
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.4
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Drewry
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-04-26 00:00:00.000000000 Z
12
+ date: 2020-04-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -96,7 +96,7 @@ dependencies:
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  - !ruby/object:Gem::Dependency
99
- name: rake
99
+ name: kramdown
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - ">="
@@ -110,7 +110,7 @@ dependencies:
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  - !ruby/object:Gem::Dependency
113
- name: test-unit
113
+ name: packnga
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - ">="
@@ -124,7 +124,7 @@ dependencies:
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  - !ruby/object:Gem::Dependency
127
- name: test-unit-notify
127
+ name: rake
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  requirements:
130
130
  - - ">="
@@ -138,7 +138,7 @@ dependencies:
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
140
  - !ruby/object:Gem::Dependency
141
- name: yard
141
+ name: test-unit
142
142
  requirement: !ruby/object:Gem::Requirement
143
143
  requirements:
144
144
  - - ">="
@@ -152,7 +152,7 @@ dependencies:
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  - !ruby/object:Gem::Dependency
155
- name: RedCloth
155
+ name: test-unit-notify
156
156
  requirement: !ruby/object:Gem::Requirement
157
157
  requirements:
158
158
  - - ">="
@@ -166,7 +166,7 @@ dependencies:
166
166
  - !ruby/object:Gem::Version
167
167
  version: '0'
168
168
  - !ruby/object:Gem::Dependency
169
- name: packnga
169
+ name: yard
170
170
  requirement: !ruby/object:Gem::Requirement
171
171
  requirements:
172
172
  - - ">="
@@ -196,16 +196,15 @@ files:
196
196
  - COPYING
197
197
  - Gemfile
198
198
  - LICENSE
199
- - README.textile
200
199
  - TODO
201
200
  - benchmark/README.md
202
201
  - benchmark/bench-backend.rb
203
202
  - benchmark/bench-instantiate.rb
204
203
  - benchmark/config.yaml.sample
205
- - doc/text/development.textile
206
- - doc/text/news.textile
207
- - doc/text/rails.textile
208
- - doc/text/tutorial.textile
204
+ - doc/text/development.md
205
+ - doc/text/news.md
206
+ - doc/text/rails.md
207
+ - doc/text/tutorial.md
209
208
  - examples/config.yaml.example
210
209
  - examples/example.der
211
210
  - examples/example.jpg
@@ -359,8 +358,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
359
358
  - !ruby/object:Gem::Version
360
359
  version: '0'
361
360
  requirements: []
362
- rubyforge_project: ruby-activeldap
363
- rubygems_version: 2.7.6.2
361
+ rubygems_version: 3.2.0.pre1
364
362
  signing_key:
365
363
  specification_version: 4
366
364
  summary: ActiveLdap is a object-oriented API to LDAP