activeldap 4.0.5 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.yardopts +3 -1
- data/doc/text/development.md +26 -0
- data/doc/text/{news.textile → news.md} +451 -241
- data/doc/text/{rails.textile → rails.md} +44 -33
- data/doc/text/{tutorial.textile → tutorial.md} +177 -185
- data/lib/active_ldap/adapter/base.rb +40 -17
- data/lib/active_ldap/adapter/jndi.rb +21 -9
- data/lib/active_ldap/adapter/jndi_connection.rb +83 -20
- data/lib/active_ldap/adapter/ldap.rb +50 -28
- data/lib/active_ldap/adapter/ldap_ext.rb +32 -13
- data/lib/active_ldap/adapter/net_ldap.rb +26 -24
- data/lib/active_ldap/associations.rb +5 -5
- data/lib/active_ldap/attribute_methods/before_type_cast.rb +1 -1
- data/lib/active_ldap/attribute_methods/dirty.rb +4 -7
- data/lib/active_ldap/attribute_methods/query.rb +1 -1
- data/lib/active_ldap/attribute_methods/read.rb +5 -1
- data/lib/active_ldap/attribute_methods/write.rb +1 -1
- data/lib/active_ldap/attribute_methods.rb +1 -2
- data/lib/active_ldap/base.rb +61 -14
- data/lib/active_ldap/callbacks.rb +7 -8
- data/lib/active_ldap/configuration.rb +27 -3
- data/lib/active_ldap/connection.rb +4 -22
- data/lib/active_ldap/distinguished_name.rb +1 -1
- data/lib/active_ldap/human_readable.rb +5 -4
- data/lib/active_ldap/operations.rb +24 -4
- data/lib/active_ldap/persistence.rb +3 -2
- data/lib/active_ldap/populate.rb +5 -3
- data/lib/active_ldap/railties/controller_runtime.rb +1 -2
- data/lib/active_ldap/schema/syntaxes.rb +8 -4
- data/lib/active_ldap/validations.rb +12 -4
- data/lib/active_ldap/version.rb +1 -1
- data/lib/active_ldap.rb +0 -7
- data/po/en/active-ldap.po +2 -2
- data/po/ja/active-ldap.po +3 -3
- data/test/add-phonetic-attribute-options-to-slapd.ldif +3 -3
- data/test/al-test-utils.rb +125 -38
- data/test/command.rb +13 -16
- data/test/enable-dynamic-groups.ldif +22 -0
- data/test/enable-start-tls.ldif +27 -0
- data/test/run-test.rb +0 -4
- data/test/test_base.rb +223 -22
- data/test/test_base_per_instance.rb +33 -1
- data/test/test_callback.rb +10 -8
- data/test/test_connection.rb +4 -0
- data/test/test_connection_per_class.rb +34 -0
- data/test/test_dn.rb +7 -0
- data/test/test_entry.rb +1 -0
- data/test/test_find.rb +14 -3
- data/test/test_supported_control.rb +1 -1
- data/test/test_syntax.rb +5 -0
- data/test/test_validation.rb +28 -15
- metadata +23 -24
- data/README.textile +0 -141
- data/doc/text/development.textile +0 -54
- data/lib/active_ldap/timeout.rb +0 -75
- data/lib/active_ldap/timeout_stub.rb +0 -17
data/test/al-test-utils.rb
CHANGED
@@ -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
|
-
|
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
|
|
@@ -175,6 +182,7 @@ module AlTestUtils
|
|
175
182
|
populate_ou
|
176
183
|
populate_user_class
|
177
184
|
populate_group_class
|
185
|
+
populate_group_of_urls_class
|
178
186
|
populate_associations
|
179
187
|
end
|
180
188
|
|
@@ -208,7 +216,7 @@ module AlTestUtils
|
|
208
216
|
end
|
209
217
|
|
210
218
|
def populate_ou
|
211
|
-
%w(Users Groups).each do |name|
|
219
|
+
%w(Users Groups GroupOfURLsSet).each do |name|
|
212
220
|
make_ou(name)
|
213
221
|
end
|
214
222
|
end
|
@@ -239,6 +247,14 @@ module AlTestUtils
|
|
239
247
|
assign_class_name(@group_class, "Group")
|
240
248
|
end
|
241
249
|
|
250
|
+
def populate_group_of_urls_class
|
251
|
+
@group_of_urls_class = Class.new(ActiveLdap::Base)
|
252
|
+
@group_of_urls_class.ldap_mapping :prefix => "ou=GroupOfURLsSet",
|
253
|
+
:scope => :sub,
|
254
|
+
:classes => ["groupOfURLs"]
|
255
|
+
assign_class_name(@group_of_urls_class, "GroupOfURLs")
|
256
|
+
end
|
257
|
+
|
242
258
|
def populate_associations
|
243
259
|
@user_class.belongs_to :groups, :many => "memberUid"
|
244
260
|
@user_class.belongs_to :primary_group,
|
@@ -273,41 +289,70 @@ module AlTestUtils
|
|
273
289
|
super
|
274
290
|
@user_index = 0
|
275
291
|
@group_index = 0
|
292
|
+
@group_of_urls_index = 0
|
293
|
+
@temporary_uids = []
|
294
|
+
end
|
295
|
+
|
296
|
+
def teardown
|
297
|
+
@temporary_uids.each do |uid|
|
298
|
+
delete_temporary_user(uid)
|
299
|
+
end
|
300
|
+
super
|
301
|
+
end
|
302
|
+
|
303
|
+
def delete_temporary_user(uid)
|
304
|
+
return unless @user_class.exists?(uid)
|
305
|
+
@user_class.search(:value => uid) do |dn, attribute|
|
306
|
+
@user_class.remove_connection(dn)
|
307
|
+
@user_class.delete(dn)
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
def build_temporary_user(config={})
|
312
|
+
uid = config[:uid] || "temp-user#{@user_index}"
|
313
|
+
password = config[:password] || "password#{@user_index}"
|
314
|
+
uid_number = config[:uid_number] || default_uid
|
315
|
+
gid_number = config[:gid_number] || default_gid
|
316
|
+
home_directory = config[:home_directory] || "/nonexistent"
|
317
|
+
see_also = config[:see_also]
|
318
|
+
user = nil
|
319
|
+
_wrap_assertion do
|
320
|
+
assert(!@user_class.exists?(uid))
|
321
|
+
assert_raise(ActiveLdap::EntryNotFound) do
|
322
|
+
@user_class.find(uid).dn
|
323
|
+
end
|
324
|
+
user = @user_class.new(uid)
|
325
|
+
assert(user.new_entry?)
|
326
|
+
user.cn = user.uid
|
327
|
+
user.sn = user.uid
|
328
|
+
user.uid_number = uid_number
|
329
|
+
user.gid_number = gid_number
|
330
|
+
user.home_directory = home_directory
|
331
|
+
user.user_password = ActiveLdap::UserPassword.ssha(password)
|
332
|
+
user.see_also = see_also
|
333
|
+
unless config[:simple]
|
334
|
+
user.add_class('shadowAccount', 'inetOrgPerson',
|
335
|
+
'organizationalPerson')
|
336
|
+
user.user_certificate = certificate
|
337
|
+
user.jpeg_photo = jpeg_photo
|
338
|
+
end
|
339
|
+
user.save
|
340
|
+
assert(!user.new_entry?)
|
341
|
+
end
|
342
|
+
[@user_class.find(user.uid), password]
|
276
343
|
end
|
277
344
|
|
278
345
|
def make_temporary_user(config={})
|
279
346
|
@user_index += 1
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
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)
|
347
|
+
config = config.merge(uid: config[:uid] || "temp-user#{@user_index}")
|
348
|
+
uid = config[:uid]
|
349
|
+
@temporary_uids << uid
|
350
|
+
if block_given?
|
351
|
+
ensure_delete_user(uid) do
|
352
|
+
yield(*build_temporary_user(config))
|
310
353
|
end
|
354
|
+
else
|
355
|
+
build_temporary_user(config)
|
311
356
|
end
|
312
357
|
end
|
313
358
|
|
@@ -331,15 +376,30 @@ module AlTestUtils
|
|
331
376
|
end
|
332
377
|
end
|
333
378
|
|
379
|
+
def make_temporary_group_of_urls(config={})
|
380
|
+
@group_of_urls_index += 1
|
381
|
+
cn = config[:cn] || "temp-group-of-urls-#{@group_of_urls_index}"
|
382
|
+
ensure_delete_group_of_urls(cn) do
|
383
|
+
_wrap_assertion do
|
384
|
+
assert(!@group_of_urls_class.exists?(cn))
|
385
|
+
assert_raise(ActiveLdap::EntryNotFound) do
|
386
|
+
@group_of_urls_class.find(cn)
|
387
|
+
end
|
388
|
+
group_of_urls = @group_of_urls_class.new(cn)
|
389
|
+
assert(group_of_urls.new_entry?)
|
390
|
+
group_of_urls.member_url = config[:member_url]
|
391
|
+
assert(group_of_urls.save!)
|
392
|
+
assert(!group_of_urls.new_entry?)
|
393
|
+
yield(@group_of_urls_class.find(group_of_urls.cn))
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
334
398
|
def ensure_delete_user(uid)
|
335
399
|
yield(uid)
|
336
400
|
ensure
|
337
|
-
|
338
|
-
|
339
|
-
@user_class.remove_connection(dn)
|
340
|
-
@user_class.delete(dn)
|
341
|
-
end
|
342
|
-
end
|
401
|
+
delete_temporary_user(uid)
|
402
|
+
@temporary_uids.delete(uid)
|
343
403
|
end
|
344
404
|
|
345
405
|
def ensure_delete_group(cn)
|
@@ -348,6 +408,12 @@ module AlTestUtils
|
|
348
408
|
@group_class.delete(cn) if @group_class.exists?(cn)
|
349
409
|
end
|
350
410
|
|
411
|
+
def ensure_delete_group_of_urls(cn)
|
412
|
+
yield(cn)
|
413
|
+
ensure
|
414
|
+
@group_of_urls_class.delete(cn) if @group_of_urls_class.exists?(cn)
|
415
|
+
end
|
416
|
+
|
351
417
|
def default_uid
|
352
418
|
"10000#{@user_index}"
|
353
419
|
end
|
@@ -373,6 +439,10 @@ module AlTestUtils
|
|
373
439
|
end
|
374
440
|
|
375
441
|
def run_command(*args, &block)
|
442
|
+
if RUBY_VERSION >= "2.7"
|
443
|
+
omit("Need to fix an optional arguments warning in net-ldap: " +
|
444
|
+
"ruby-ldap/ruby-net-ldap/pull/342")
|
445
|
+
end
|
376
446
|
file = Tempfile.new("al-command-support")
|
377
447
|
file.open
|
378
448
|
file.puts(ActiveLdap::Base.configurations["test"].to_yaml)
|
@@ -425,4 +495,21 @@ module AlTestUtils
|
|
425
495
|
ActiveLdap::Base.logger = original_logger
|
426
496
|
end
|
427
497
|
end
|
498
|
+
|
499
|
+
module Omittable
|
500
|
+
def omit_if_jruby(message=nil)
|
501
|
+
return unless RUBY_PLATFORM == "java"
|
502
|
+
omit(message || "This test is not for JRuby")
|
503
|
+
end
|
504
|
+
|
505
|
+
def omit_unless_jruby(message=nil)
|
506
|
+
return if RUBY_PLATFORM == "java"
|
507
|
+
omit(message || "This test is only for JRuby")
|
508
|
+
end
|
509
|
+
|
510
|
+
def omit_if_ldap(message=nil)
|
511
|
+
return if current_configuration[:adapter] == "ldap"
|
512
|
+
omit(message || "This test is not for ruby-ldap")
|
513
|
+
end
|
514
|
+
end
|
428
515
|
end
|
data/test/command.rb
CHANGED
@@ -36,24 +36,21 @@ module Command
|
|
36
36
|
return java_run(cmd, *args, &block) if Object.respond_to?(:java)
|
37
37
|
in_r, in_w = IO.pipe
|
38
38
|
out_r, out_w = IO.pipe
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
$VERBOSE = nil
|
44
|
-
pid = fork do
|
45
|
-
$VERBOSE = verbose
|
46
|
-
detach_io
|
47
|
-
STDIN.reopen(in_r)
|
48
|
-
in_r.close
|
49
|
-
STDOUT.reopen(out_w)
|
50
|
-
STDERR.reopen(out_w)
|
51
|
-
out_w.close
|
52
|
-
exec(cmd, *args)
|
53
|
-
exit!(-1)
|
54
|
-
end
|
39
|
+
verbose = $VERBOSE
|
40
|
+
# ruby(>=1.8)'s fork terminates other threads with warning messages
|
41
|
+
$VERBOSE = nil
|
42
|
+
pid = fork do
|
55
43
|
$VERBOSE = verbose
|
44
|
+
detach_io
|
45
|
+
STDIN.reopen(in_r)
|
46
|
+
in_r.close
|
47
|
+
STDOUT.reopen(out_w)
|
48
|
+
STDERR.reopen(out_w)
|
49
|
+
out_w.close
|
50
|
+
exec(cmd, *args)
|
51
|
+
exit!(-1)
|
56
52
|
end
|
53
|
+
$VERBOSE = verbose
|
57
54
|
yield(out_r, in_w) if block_given?
|
58
55
|
in_r.close unless in_r.closed?
|
59
56
|
out_w.close unless out_w.closed?
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Your LDAP server needs to support dynamic list for test.
|
2
|
+
# This is a LDIF file for OpenLDAP to do the configuration.
|
3
|
+
# You can use this file by the following command line on Debian GNU/Linux
|
4
|
+
# or Ubuntu:
|
5
|
+
#
|
6
|
+
# % sudo -H ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/dyngroup.ldif
|
7
|
+
# % sudo -H ldapmodify -Y EXTERNAL -H ldapi:/// -f test/enable-dynamic-groups.ldif
|
8
|
+
version: 1
|
9
|
+
|
10
|
+
# Enable dynlist module
|
11
|
+
dn: cn=module{0},cn=config
|
12
|
+
changetype: modify
|
13
|
+
add: olcModuleLoad
|
14
|
+
olcModuleLoad: dynlist
|
15
|
+
|
16
|
+
# Set up dynlist overlay
|
17
|
+
dn: olcOverlay=dynlist,olcDatabase={1}mdb,cn=config
|
18
|
+
changetype: add
|
19
|
+
objectClass: olcOverlayConfig
|
20
|
+
objectClass: olcDynamicList
|
21
|
+
olcOverlay: dynlist
|
22
|
+
olcDlAttrSet: groupOfURLs memberURL member
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Your LDAP server needs to support StartTLS when you test StartTLS related
|
2
|
+
# feature. This is a LDIF file for OpenLDAP to do the configuration.
|
3
|
+
# You can use this file by the following command line on Debian GNU/Linux
|
4
|
+
# or Ubuntu:
|
5
|
+
#
|
6
|
+
# % sudo usermod -a -G ssl-cert openldap
|
7
|
+
# % sudo systemctl restart slapd
|
8
|
+
# % sudo -H ldapmodify -Y EXTERNAL -H ldapi:/// -f test/enable-start-tls.ldif
|
9
|
+
#
|
10
|
+
# Adding the openldap user to the ssl-cert group is required to read
|
11
|
+
# certification related files.
|
12
|
+
version: 1
|
13
|
+
dn: cn=config
|
14
|
+
delete: olcTLSCACertificateFile
|
15
|
+
-
|
16
|
+
add: olcTLSCACertificateFile
|
17
|
+
olcTLSCACertificateFile: /etc/ssl/certs/ca-certificates.crt
|
18
|
+
-
|
19
|
+
delete: olcTLSCertificateKeyFile
|
20
|
+
-
|
21
|
+
add: olcTLSCertificateKeyFile
|
22
|
+
olcTLSCertificateKeyFile: /etc/ssl/private/ssl-cert-snakeoil.key
|
23
|
+
-
|
24
|
+
delete: olcTLSCertificateFile
|
25
|
+
-
|
26
|
+
add: olcTLSCertificateFile
|
27
|
+
olcTLSCertificateFile: /etc/ssl/certs/ssl-cert-snakeoil.pem
|
data/test/run-test.rb
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
$VERBOSE = true
|
4
4
|
|
5
|
-
$KCODE = 'u' if RUBY_VERSION < "1.9"
|
6
|
-
|
7
5
|
base_dir = File.expand_path(File.dirname(__FILE__))
|
8
6
|
top_dir = File.expand_path(File.join(base_dir, ".."))
|
9
7
|
lib_dir = File.join(top_dir, "lib")
|
@@ -11,11 +9,9 @@ test_dir = File.join(top_dir, "test")
|
|
11
9
|
$LOAD_PATH.unshift(lib_dir)
|
12
10
|
$LOAD_PATH.unshift(test_dir)
|
13
11
|
|
14
|
-
require "rubygems"
|
15
12
|
require "bundler/setup"
|
16
13
|
|
17
14
|
require "test/unit"
|
18
|
-
require "test/unit/notify"
|
19
15
|
Test::Unit::Priority.enable
|
20
16
|
|
21
17
|
Dir.glob(File.join(test_dir, "**", "test_*.rb")) do |test_file|
|