ruby-activeldap 0.7.4 → 0.8.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.
Files changed (74) hide show
  1. data/CHANGES +375 -0
  2. data/COPYING +340 -0
  3. data/LICENSE +58 -0
  4. data/Manifest.txt +33 -0
  5. data/README +63 -0
  6. data/Rakefile +37 -0
  7. data/TODO +31 -0
  8. data/benchmark/bench-al.rb +152 -0
  9. data/lib/{activeldap.rb → active_ldap.rb} +280 -263
  10. data/lib/active_ldap/adaptor/base.rb +29 -0
  11. data/lib/active_ldap/adaptor/ldap.rb +466 -0
  12. data/lib/active_ldap/association/belongs_to.rb +38 -0
  13. data/lib/active_ldap/association/belongs_to_many.rb +40 -0
  14. data/lib/active_ldap/association/collection.rb +80 -0
  15. data/lib/active_ldap/association/has_many.rb +48 -0
  16. data/lib/active_ldap/association/has_many_wrap.rb +56 -0
  17. data/lib/active_ldap/association/proxy.rb +89 -0
  18. data/lib/active_ldap/associations.rb +162 -0
  19. data/lib/active_ldap/attributes.rb +199 -0
  20. data/lib/active_ldap/base.rb +1343 -0
  21. data/lib/active_ldap/callbacks.rb +19 -0
  22. data/lib/active_ldap/command.rb +46 -0
  23. data/lib/active_ldap/configuration.rb +96 -0
  24. data/lib/active_ldap/connection.rb +137 -0
  25. data/lib/{activeldap → active_ldap}/ldap.rb +1 -1
  26. data/lib/active_ldap/object_class.rb +70 -0
  27. data/lib/active_ldap/schema.rb +258 -0
  28. data/lib/{activeldap → active_ldap}/timeout.rb +0 -0
  29. data/lib/{activeldap → active_ldap}/timeout_stub.rb +0 -0
  30. data/lib/active_ldap/user_password.rb +92 -0
  31. data/lib/active_ldap/validations.rb +78 -0
  32. data/rails/plugin/active_ldap/README +54 -0
  33. data/rails/plugin/active_ldap/init.rb +6 -0
  34. data/test/TODO +2 -0
  35. data/test/al-test-utils.rb +337 -0
  36. data/test/command.rb +62 -0
  37. data/test/config.yaml +8 -0
  38. data/test/config.yaml.sample +6 -0
  39. data/test/run-test.rb +17 -0
  40. data/test/test-unit-ext.rb +2 -0
  41. data/test/test_associations.rb +334 -0
  42. data/test/test_attributes.rb +71 -0
  43. data/test/test_base.rb +345 -0
  44. data/test/test_base_per_instance.rb +32 -0
  45. data/test/test_bind.rb +53 -0
  46. data/test/test_callback.rb +35 -0
  47. data/test/test_connection.rb +38 -0
  48. data/test/test_connection_per_class.rb +50 -0
  49. data/test/test_find.rb +36 -0
  50. data/test/test_groupadd.rb +50 -0
  51. data/test/test_groupdel.rb +46 -0
  52. data/test/test_groupls.rb +107 -0
  53. data/test/test_groupmod.rb +51 -0
  54. data/test/test_lpasswd.rb +75 -0
  55. data/test/test_object_class.rb +32 -0
  56. data/test/test_reflection.rb +173 -0
  57. data/test/test_schema.rb +166 -0
  58. data/test/test_user.rb +209 -0
  59. data/test/test_user_password.rb +93 -0
  60. data/test/test_useradd-binary.rb +59 -0
  61. data/test/test_useradd.rb +55 -0
  62. data/test/test_userdel.rb +48 -0
  63. data/test/test_userls.rb +86 -0
  64. data/test/test_usermod-binary-add-time.rb +62 -0
  65. data/test/test_usermod-binary-add.rb +61 -0
  66. data/test/test_usermod-binary-del.rb +64 -0
  67. data/test/test_usermod-lang-add.rb +57 -0
  68. data/test/test_usermod.rb +56 -0
  69. data/test/test_validation.rb +38 -0
  70. metadata +94 -21
  71. data/lib/activeldap/associations.rb +0 -170
  72. data/lib/activeldap/base.rb +0 -1456
  73. data/lib/activeldap/configuration.rb +0 -59
  74. data/lib/activeldap/schema2.rb +0 -217
@@ -0,0 +1,38 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestConnection < Test::Unit::TestCase
4
+ include AlTestUtils::Config
5
+
6
+ def setup
7
+ super
8
+ end
9
+
10
+ def teardown
11
+ ActiveLdap::Base.clear_active_connections!
12
+ super
13
+ end
14
+
15
+ def test_can_reconnect?
16
+ assert(!ActiveLdap::Base.connected?)
17
+
18
+ config = current_configuration.merge("retry_limit" => 10)
19
+ ActiveLdap::Base.establish_connection(config)
20
+ connection = ActiveLdap::Base.connection
21
+ assert(!connection.send(:can_reconnect?, :reconnect_attempts => 10))
22
+
23
+ config = current_configuration.merge("retry_limit" => 10)
24
+ ActiveLdap::Base.establish_connection(config)
25
+ connection = ActiveLdap::Base.connection
26
+ assert(!connection.send(:can_reconnect?, :reconnect_attempts => 9))
27
+
28
+ config = current_configuration.merge("retry_limit" => 10)
29
+ ActiveLdap::Base.establish_connection(config)
30
+ connection = ActiveLdap::Base.connection
31
+ assert(connection.send(:can_reconnect?, :reconnect_attempts => 8))
32
+
33
+ config = current_configuration.merge("retry_limit" => -1)
34
+ ActiveLdap::Base.establish_connection(config)
35
+ connection = ActiveLdap::Base.connection
36
+ assert(connection.send(:can_reconnect?, :reconnect_attempts => -10))
37
+ end
38
+ end
@@ -0,0 +1,50 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestConnectionPerClass < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ def test_bind
7
+ non_anon_class = ou_class("ou=NonAnonymous")
8
+ anon_class = ou_class("ou=Anonymous")
9
+
10
+ assert(non_anon_class.connection.bound?)
11
+ assert(anon_class.connection.bound?)
12
+
13
+ anon_class.connection.unbind
14
+ assert(!non_anon_class.connection.bound?)
15
+ assert(!anon_class.connection.bound?)
16
+
17
+ anon_class.connection.rebind
18
+ assert(non_anon_class.connection.bound?)
19
+ assert(anon_class.connection.bound?)
20
+
21
+ assert_raises(ActiveLdap::AuthenticationError) do
22
+ non_anon_class.establish_connection(:bind_dn => nil,
23
+ :allow_anonymous => false,
24
+ :retry_limit => 0)
25
+ end
26
+
27
+ assert(!non_anon_class.connection.bound?)
28
+ assert(anon_class.connection.bound?)
29
+
30
+ anon_class.connection.unbind
31
+ assert(!non_anon_class.connection.bound?)
32
+ assert(!anon_class.connection.bound?)
33
+
34
+ anon_class.connection.rebind
35
+ assert(!non_anon_class.connection.bound?)
36
+ assert(anon_class.connection.bound?)
37
+
38
+ anon_class.connection.unbind
39
+ assert(!non_anon_class.connection.bound?)
40
+ assert(!anon_class.connection.bound?)
41
+
42
+ assert_nothing_raised do
43
+ anon_class.establish_connection(:bind_dn => nil,
44
+ :allow_anonymous => true)
45
+ end
46
+
47
+ assert(!non_anon_class.connection.bound?)
48
+ assert(anon_class.connection.bound?)
49
+ end
50
+ end
data/test/test_find.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestFind < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ def test_split_search_value
7
+ assert_split_search_value([nil, "test-user", nil], "test-user")
8
+ assert_split_search_value([nil, "test-user", "ou=Sub"], "test-user,ou=Sub")
9
+ assert_split_search_value(["uid", "test-user", "ou=Sub"],
10
+ "uid=test-user,ou=Sub")
11
+ assert_split_search_value(["uid", "test-user", nil], "uid=test-user")
12
+ end
13
+
14
+ def test_find
15
+ make_temporary_user do |user, password|
16
+ assert_equal(user.uid, @user_class.find(:first).uid)
17
+ assert_equal(user.uid, @user_class.find(user.uid).uid)
18
+ assert_equal(user.to_ldif, @user_class.find(:first).to_ldif)
19
+ assert_equal([user.uid], @user_class.find(:all).collect {|u| u.uid})
20
+
21
+ make_temporary_user do |user2, password2|
22
+ assert_equal(user2.uid, @user_class.find(user2.uid).uid)
23
+ assert_equal([user2.uid],
24
+ @user_class.find(user2.uid(true)).collect {|u| u.uid})
25
+ assert_equal(user2.to_ldif, @user_class.find(user2.uid).to_ldif)
26
+ assert_equal([user.uid, user2.uid].sort,
27
+ @user_class.find(:all).collect {|u| u.uid}.sort)
28
+ end
29
+ end
30
+ end
31
+
32
+ private
33
+ def assert_split_search_value(expected, value)
34
+ assert_equal(expected, ActiveLdap::Base.send(:split_search_value, value))
35
+ end
36
+ 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, password|
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
@@ -0,0 +1,46 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestGroupdel < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ def setup
7
+ super
8
+ @command = File.join(@examples_dir, "groupdel")
9
+ end
10
+
11
+ priority :must
12
+
13
+ priority :normal
14
+ def test_non_exist_group
15
+ ensure_delete_group("test-group") do |name,|
16
+ assert(!@group_class.exists?(name))
17
+ assert_equal([false, "Group #{name} doesn't exist.\n"], run_command(name))
18
+ assert(!@group_class.exists?(name))
19
+ end
20
+ end
21
+
22
+ def test_delete_group
23
+ make_temporary_group do |group, password|
24
+ assert_groupdel_successfully(group.id)
25
+ end
26
+ end
27
+
28
+ private
29
+ def assert_groupdel_successfully(name, *args, &block)
30
+ _wrap_assertion do
31
+ assert(@group_class.exists?(name))
32
+ args.concat([name])
33
+ assert_equal([true, ""], run_command(*args, &block))
34
+ assert(!@group_class.exists?(name))
35
+ end
36
+ end
37
+
38
+ def assert_groupdel_failed(name, message, *args, &block)
39
+ _wrap_assertion do
40
+ assert(@group_class.exists?(name))
41
+ args.concat([name])
42
+ assert_equal([false, message], run_command(*args, &block))
43
+ assert(@group_class.exists?(name))
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,107 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestGroupls < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ def setup
7
+ super
8
+ @command = File.join(@examples_dir, "groupls")
9
+ make_ou("People")
10
+ @user_class.instance_variable_set("@prefix", "ou=People")
11
+ end
12
+
13
+ priority :must
14
+
15
+ priority :normal
16
+ def test_non_exist_group
17
+ ensure_delete_group("test-group") do |name,|
18
+ assert(!@group_class.exists?(name))
19
+ assert_equal([false, "Group #{name} doesn't exist.\n"], run_command(name))
20
+ assert(!@group_class.exists?(name))
21
+ end
22
+ end
23
+
24
+ def test_list_group_no_group
25
+ make_temporary_group do |group|
26
+ assert_groupls_successfully(group.id, [])
27
+ end
28
+ end
29
+
30
+ def test_list_group_have_primary_members
31
+ make_temporary_group do |group|
32
+ make_temporary_user(:gid_number => group.gid_number) do |user1,|
33
+ make_temporary_user(:gid_number => group.gid_number) do |user2,|
34
+ assert_groupls_successfully(group.id, [user1, user2])
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ def test_list_group_have_members
41
+ make_temporary_user do |user1,|
42
+ make_temporary_user do |user2,|
43
+ make_temporary_group do |group|
44
+ group.members << user1
45
+ group.members << user2
46
+ assert_groupls_successfully(group.id, [user1, user2])
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ def test_list_group_have_members_and_primary_members
53
+ make_temporary_group do |group|
54
+ options = {:gid_number => group.gid_number}
55
+ make_temporary_user(options) do |primary_user1,|
56
+ make_temporary_user(options) do |primary_user2,|
57
+ options1 = {:gid_number => group.gid_number.succ}
58
+ options2 = {:gid_number => group.gid_number.succ.succ}
59
+ make_temporary_user(options1) do |user1,|
60
+ make_temporary_user(options2) do |user2,|
61
+ group.members << user1
62
+ group.members << user2
63
+ assert_groupls_successfully(group.id,
64
+ [primary_user1, primary_user2,
65
+ user1, user2])
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ def test_list_group_have_non_exist_member
74
+ make_temporary_group do |group|
75
+ options = {:gid_number => group.gid_number.succ}
76
+ make_temporary_user(options) do |user,|
77
+ group.member_uid = [user.id]
78
+ assert(group.save)
79
+ assert_groupls_successfully(group.id, [user])
80
+ end
81
+ end
82
+ end
83
+
84
+ private
85
+ def assert_groupls_successfully(name, members, *args, &block)
86
+ _wrap_assertion do
87
+ assert(@group_class.exists?(name))
88
+ args.concat([name])
89
+ group = @group_class.find(name)
90
+ members = members.collect do |m|
91
+ "#{m.uid}[#{m.new_entry? ? '????' : m.uid_number}]"
92
+ end
93
+ result = "#{group.cn}(#{group.gid_number}): #{members.join(', ')}\n"
94
+ assert_equal([true, result], run_command(*args, &block))
95
+ assert(@group_class.exists?(name))
96
+ end
97
+ end
98
+
99
+ def assert_groupls_failed(name, message, *args, &block)
100
+ _wrap_assertion do
101
+ assert(@group_class.exists?(name))
102
+ args.concat([name])
103
+ assert_equal([false, message], run_command(*args, &block))
104
+ assert(@group_class.exists?(name))
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,51 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestGroupmod < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ def setup
7
+ super
8
+ @command = File.join(@examples_dir, "groupmod")
9
+ end
10
+
11
+ priority :must
12
+
13
+ priority :normal
14
+ def test_non_exist_group
15
+ ensure_delete_group("test-group") do |name,|
16
+ assert(!@group_class.exists?(name))
17
+ assert_equal([false, "Group #{name} doesn't exist.\n"],
18
+ run_command(name, 111111))
19
+ assert(!@group_class.exists?(name))
20
+ end
21
+ end
22
+
23
+ def test_modify_group
24
+ make_temporary_group do |group, password|
25
+ assert_groupmod_successfully(group.cn, group.gid_number.succ)
26
+ end
27
+ end
28
+
29
+ private
30
+ def assert_groupmod_successfully(name, gid, *args, &block)
31
+ _wrap_assertion do
32
+ assert(@group_class.exists?(name))
33
+ args.concat([name, gid])
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.cn)
39
+ assert_equal(gid, group.gid_number)
40
+ end
41
+ end
42
+
43
+ def assert_groupmod_failed(name, gid, message, *args, &block)
44
+ _wrap_assertion do
45
+ assert(@group_class.exists?(name))
46
+ args.concat([name, gid])
47
+ assert_equal([false, message], run_command(*args, &block))
48
+ assert(@group_class.exists?(name))
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,75 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestLPasswd < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ def setup
7
+ super
8
+ @command = File.join(@examples_dir, "lpasswd")
9
+ make_ou("People")
10
+ @user_class.instance_variable_set("@prefix", "ou=People")
11
+ end
12
+
13
+ priority :must
14
+
15
+ priority :normal
16
+ def test_non_exist_user
17
+ ensure_delete_user("test-user") do |uid,|
18
+ assert(!@user_class.exists?(uid))
19
+ assert_equal([false, "User #{uid} doesn't exist.\n"], run_command(uid))
20
+ assert(!@user_class.exists?(uid))
21
+ end
22
+ end
23
+
24
+ def test_change_password
25
+ make_temporary_user do |user, password|
26
+ new_password = "new#{password}"
27
+ assert_lpasswd_successfully(user.uid, password, new_password)
28
+ end
29
+ end
30
+
31
+ def test_password_mismatch
32
+ make_temporary_user do |user, password|
33
+ message = "[#{user.dn}] Password: \n" * 2
34
+ message = "#{message}Password mismatch!\n" * 3
35
+ assert_lpasswd_failed(user.id, password, message) do |input, output|
36
+ 3.times do
37
+ output.puts("new#{password}1")
38
+ output.puts("new#{password}2")
39
+ output.flush
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ private
46
+ def assert_lpasswd_successfully(name, current, new, *args, &block)
47
+ _wrap_assertion do
48
+ assert(@user_class.exists?(name))
49
+ assert_send([ActiveLdap::UserPassword, :valid?,
50
+ current, @user_class.find(name).user_password])
51
+ args.concat([name])
52
+ block ||= Proc.new do |input, output|
53
+ output.puts(new)
54
+ output.puts(new)
55
+ output.flush
56
+ end
57
+ assert_equal([true, "[#{@user_class.find(name).dn}] Password: \n" * 2],
58
+ run_command(*args, &block))
59
+ assert_send([ActiveLdap::UserPassword, :valid?,
60
+ new, @user_class.find(name).user_password])
61
+ end
62
+ end
63
+
64
+ def assert_lpasswd_failed(name, current, message, *args, &block)
65
+ _wrap_assertion do
66
+ assert(@user_class.exists?(name))
67
+ assert_send([ActiveLdap::UserPassword, :valid?,
68
+ current, @user_class.find(name).user_password])
69
+ args.concat([name])
70
+ assert_equal([false, message], run_command(*args, &block))
71
+ assert_send([ActiveLdap::UserPassword, :valid?,
72
+ current, @user_class.find(name).user_password])
73
+ end
74
+ end
75
+ end