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,61 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestBasePerInstance < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ def setup
7
+ super
8
+ ou_class("ou=Users").new("Sub").save!
9
+ end
10
+
11
+ priority :must
12
+ def test_set_base
13
+ guest = @user_class.new("guest")
14
+ guest.base = "ou=Sub"
15
+ assert_equal("uid=guest,ou=Sub,#{@user_class.base}", guest.dn)
16
+ end
17
+
18
+ priority :normal
19
+ def test_dn_is_base
20
+ entry_class = Class.new(ActiveLdap::Base)
21
+ entry_class.ldap_mapping :prefix => "",
22
+ :classes => ["top"],
23
+ :scope => :sub
24
+ entry_class.dn_attribute = nil
25
+
26
+ entry = entry_class.root
27
+ assert_equal(entry_class.base, entry.dn)
28
+ assert_equal(entry_class.base, entry.base)
29
+ end
30
+
31
+ def test_loose_dn
32
+ user = @user_class.new("test-user , ou = Sub")
33
+ assert_equal("uid=test-user,ou=Sub,#{@user_class.base}", user.dn)
34
+
35
+ user = @user_class.new("test-user , ou = Sub, #{@user_class.base}")
36
+ assert_equal("uid=test-user,ou=Sub,#{@user_class.base}", user.dn)
37
+ end
38
+
39
+ def test_exists?
40
+ make_temporary_user(:uid => "test-user,ou=Sub") do |user, password|
41
+ assert(@user_class.exists?(user.uid))
42
+ assert(@user_class.exists?("uid=#{user.uid}"))
43
+ assert(@user_class.exists?(user.dn))
44
+
45
+ assert(@user_class.exists?("test-user,ou=Sub"))
46
+ assert(@user_class.exists?("uid=test-user,ou=Sub"))
47
+ end
48
+ end
49
+
50
+ def test_add
51
+ make_temporary_user(:uid => "test-user,ou=Sub") do |user, password|
52
+ assert_equal("uid=test-user,ou=Sub,#{@user_class.base}", user.dn)
53
+ assert_equal("test-user", user.uid)
54
+ end
55
+
56
+ make_temporary_user(:uid => "uid=test-user,ou=Sub") do |user, password|
57
+ assert_equal("uid=test-user,ou=Sub,#{@user_class.base}", user.dn)
58
+ assert_equal("test-user", user.uid)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,62 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestBind < 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_anonymous
16
+ assert(!ActiveLdap::Base.connected?)
17
+ assert_nothing_raised do
18
+ config = ActiveLdap::Base.configurations[LDAP_ENV].symbolize_keys
19
+ config = ActiveLdap::Base.prepare_configuration(config)
20
+ config.delete(:bind_dn)
21
+ config[:allow_anonymous] = true
22
+ connect(config)
23
+ end
24
+ assert(ActiveLdap::Base.connected?,
25
+ "Checking is the connection was established.")
26
+ end
27
+
28
+ def test_bind
29
+ assert(!ActiveLdap::Base.connected?)
30
+ config = ActiveLdap::Base.configurations[LDAP_ENV].symbolize_keys
31
+ config = ActiveLdap::Base.prepare_configuration(config)
32
+ if config[:bind_dn].nil? and !config[:try_sasl]
33
+ omit("need user configuration")
34
+ end
35
+ assert_nothing_raised do
36
+ config[:allow_anonymous] = false
37
+ connect(config)
38
+ end
39
+ assert(ActiveLdap::Base.connected?,
40
+ "Checking is the connection was established.")
41
+ assert(ActiveLdap::Base.connection.bound?)
42
+ end
43
+
44
+ def test_failed_bind
45
+ assert(!ActiveLdap::Base.connected?)
46
+ assert_raises(ActiveLdap::AuthenticationError) do
47
+ config = ActiveLdap::Base.configurations[LDAP_ENV].symbolize_keys
48
+ config = ActiveLdap::Base.prepare_configuration(config)
49
+ config.delete(:bind_dn)
50
+ config[:try_sasl] = false
51
+ config[:allow_anonymous] = false
52
+ connect(config)
53
+ end
54
+ assert(!ActiveLdap::Base.connection.bound?)
55
+ end
56
+
57
+ private
58
+ def connect(config)
59
+ ActiveLdap::Base.setup_connection(config)
60
+ ActiveLdap::Base.connection.connect
61
+ end
62
+ end
@@ -0,0 +1,31 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestCallback < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ priority :must
7
+
8
+ priority :normal
9
+ def test_callback_after_find_and_after_initialize
10
+ make_temporary_group do |group|
11
+ found_entries = []
12
+ initialized_entries = []
13
+ @group_class.instance_variable_set("@found_entries", found_entries)
14
+ @group_class.instance_variable_set("@initialized_entries",
15
+ initialized_entries)
16
+ @group_class.module_eval do
17
+ after_find "self.class.instance_variable_get('@found_entries') << self"
18
+ after_initialize "self.class.instance_variable_get('@initialized_entries') << self"
19
+ end
20
+
21
+ assert_equal([], found_entries)
22
+ assert_equal([], initialized_entries)
23
+
24
+ found_group = @group_class.find(group.dn)
25
+
26
+ assert_equal([found_group.cn].sort, found_entries.collect {|g| g.cn}.sort)
27
+ assert_equal([found_group.cn].sort,
28
+ initialized_entries.collect {|g| g.cn}.sort)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,40 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestConfiguration < Test::Unit::TestCase
4
+ priority :must
5
+
6
+ priority :normal
7
+ def test_prepare_configuration_with_silent_uri
8
+ configuration = {
9
+ :bind_dn => "cn=admin,dc=example,dc=com",
10
+ :password => "secret",
11
+ :uri => "ldap://example.com/cn=ignore,dc=me"
12
+ }
13
+ prepared_configuration =
14
+ ActiveLdap::Base.prepare_configuration(configuration)
15
+ assert_equal({
16
+ :host => "example.com",
17
+ :port => 389,
18
+ :bind_dn => "cn=admin,dc=example,dc=com",
19
+ :password => "secret",
20
+ },
21
+ prepared_configuration)
22
+ end
23
+
24
+ def test_prepare_configuration_with_detailed_uri
25
+ configuration = {
26
+ :host => "example.net",
27
+ :uri => "ldaps://example.com/cn=admin,dc=example,dc=com??sub"
28
+ }
29
+ prepared_configuration =
30
+ ActiveLdap::Base.prepare_configuration(configuration)
31
+ assert_equal({
32
+ :host => "example.net",
33
+ :port => 636,
34
+ :method => :ssl,
35
+ :bind_dn => "cn=admin,dc=example,dc=com",
36
+ :scope => "sub",
37
+ },
38
+ prepared_configuration)
39
+ end
40
+ end
@@ -0,0 +1,82 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestConnection < Test::Unit::TestCase
4
+ include AlTestUtils::Config
5
+ include AlTestUtils::MockLogger
6
+
7
+ def setup
8
+ super
9
+ end
10
+
11
+ def teardown
12
+ ActiveLdap::Base.clear_active_connections!
13
+ super
14
+ end
15
+
16
+ priority :must
17
+ def test_retry_limit_0_with_existent_host
18
+ config = current_configuration.merge("retry_limit" => 0)
19
+ ActiveLdap::Base.setup_connection(config)
20
+ assert_nothing_raised do
21
+ ActiveLdap::Base.find(:all)
22
+ end
23
+ end
24
+
25
+ def test_retry_limit_0_with_nonexistent_host_with_timeout
26
+ config = current_configuration.merge("host" => "192.168.29.29",
27
+ "retry_limit" => 0,
28
+ "timeout" => 1)
29
+ ActiveLdap::Base.setup_connection(config)
30
+ assert_raise(ActiveLdap::TimeoutError) do
31
+ ActiveLdap::Base.find(:first)
32
+ end
33
+ end
34
+
35
+ def test_bind_format_check
36
+ connector = Class.new(ActiveLdap::Base)
37
+ assert(!connector.connected?)
38
+ exception = nil
39
+ assert_raises(ArgumentError) do
40
+ begin
41
+ connector.setup_connection(:adapter => adapter,
42
+ :bind_format => "uid=%s,dc=test",
43
+ :allow_anonymous => false)
44
+ connector.connection.connect
45
+ rescue Exception
46
+ exception = $!
47
+ raise
48
+ end
49
+ end
50
+ assert_equal("Unknown key: bind_format", exception.message)
51
+ end
52
+
53
+ def test_can_reconnect?
54
+ assert(!ActiveLdap::Base.connected?)
55
+
56
+ config = current_configuration.merge("retry_limit" => 10)
57
+ ActiveLdap::Base.setup_connection(config)
58
+ connection = ActiveLdap::Base.connection
59
+ assert(!connection.send(:can_reconnect?, :reconnect_attempts => 11))
60
+
61
+ config = current_configuration.merge("retry_limit" => 10)
62
+ ActiveLdap::Base.setup_connection(config)
63
+ connection = ActiveLdap::Base.connection
64
+ assert(connection.send(:can_reconnect?, :reconnect_attempts => 10))
65
+
66
+ config = current_configuration.merge("retry_limit" => -1)
67
+ ActiveLdap::Base.setup_connection(config)
68
+ connection = ActiveLdap::Base.connection
69
+ assert(connection.send(:can_reconnect?, :reconnect_attempts => -10))
70
+ end
71
+
72
+ priority :low
73
+ def test_retry_limit_0_with_nonexistent_host
74
+ omit("this test will take a long time...")
75
+ config = current_configuration.merge("host" => "192.168.29.29",
76
+ "retry_limit" => 0)
77
+ ActiveLdap::Base.setup_connection(config)
78
+ assert_raise(ActiveLdap::ConnectionError) do
79
+ ActiveLdap::Base.find(:first)
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,112 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestConnectionPerClass < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ priority :must
7
+ def test_multi_setup_connections_with_association
8
+ make_ou("Sub,ou=Users")
9
+ make_ou("Sub2,ou=Users")
10
+
11
+ sub_user_class = Class.new(@user_class)
12
+ sub_user_class.prefix = "ou=Sub"
13
+ sub2_user_class = Class.new(@user_class)
14
+ sub2_user_class.prefix = "ou=Sub2"
15
+ sub_user_class.has_many(:related_entries, :wrap => "seeAlso")
16
+ sub_user_class.set_associated_class(:related_entries, sub2_user_class)
17
+
18
+ make_temporary_user(:uid => "uid=user1,ou=Sub") do |user,|
19
+ make_temporary_user(:uid => "uid=user2,ou=Sub2") do |user2,|
20
+ sub_user = sub_user_class.find(user.uid)
21
+ sub2_user = sub2_user_class.find(user2.uid)
22
+ sub_user.see_also = sub2_user.dn
23
+ assert(sub_user.save)
24
+
25
+ sub_user = sub_user_class.find(user.uid)
26
+ assert_equal(["ou=Sub2"],
27
+ sub_user.related_entries.collect {|e| e.class.prefix})
28
+ end
29
+ end
30
+ end
31
+
32
+ priority :normal
33
+ def test_multi_setup_connections
34
+ make_ou("Sub")
35
+ make_ou("Sub2")
36
+ sub_class = ou_class("ou=Sub")
37
+ sub2_class = ou_class("ou=Sub2")
38
+
39
+ configuration = current_configuration.symbolize_keys
40
+ configuration[:scope] = :base
41
+ current_base = configuration[:base]
42
+ sub_configuration = configuration.dup
43
+ sub_base = "ou=Sub,#{current_base}"
44
+ sub_configuration[:base] = sub_base
45
+ sub2_configuration = configuration.dup
46
+ sub2_base = "ou=Sub2,#{current_base}"
47
+ sub2_configuration[:base] = sub2_base
48
+
49
+ sub_class.setup_connection(sub_configuration)
50
+ sub_class.prefix = nil
51
+ sub2_class.setup_connection(sub2_configuration)
52
+ sub2_class.prefix = nil
53
+
54
+ assert_equal([sub_base], sub_class.find(:all).collect(&:dn))
55
+ assert_equal([sub2_base], sub2_class.find(:all).collect(&:dn))
56
+ assert_equal([sub_base], sub_class.find(:all).collect(&:dn))
57
+ assert_equal([sub2_base], sub2_class.find(:all).collect(&:dn))
58
+ end
59
+
60
+ def test_bind
61
+ non_anon_class = ou_class("ou=NonAnonymous")
62
+ anon_class = ou_class("ou=Anonymous")
63
+
64
+ assert(non_anon_class.connection.bound?)
65
+ assert(anon_class.connection.bound?)
66
+
67
+ anon_class.connection.unbind
68
+ assert(!non_anon_class.connection.bound?)
69
+ assert(!anon_class.connection.bound?)
70
+
71
+ anon_class.connection.rebind
72
+ assert(non_anon_class.connection.bound?)
73
+ assert(anon_class.connection.bound?)
74
+
75
+ assert_raises(ActiveLdap::AuthenticationError) do
76
+ connect(non_anon_class,
77
+ :bind_dn => nil,
78
+ :allow_anonymous => false,
79
+ :retry_limit => 0)
80
+ end
81
+
82
+ assert(!non_anon_class.connection.bound?)
83
+ assert(anon_class.connection.bound?)
84
+
85
+ anon_class.connection.unbind
86
+ assert(!non_anon_class.connection.bound?)
87
+ assert(!anon_class.connection.bound?)
88
+
89
+ anon_class.connection.rebind
90
+ assert(!non_anon_class.connection.bound?)
91
+ assert(anon_class.connection.bound?)
92
+
93
+ anon_class.connection.unbind
94
+ assert(!non_anon_class.connection.bound?)
95
+ assert(!anon_class.connection.bound?)
96
+
97
+ assert_nothing_raised do
98
+ connect(anon_class,
99
+ :bind_dn => nil,
100
+ :allow_anonymous => true)
101
+ end
102
+
103
+ assert(!non_anon_class.connection.bound?)
104
+ assert(anon_class.connection.bound?)
105
+ end
106
+
107
+ private
108
+ def connect(klass, config)
109
+ klass.setup_connection({:adapter => adapter}.merge(config))
110
+ klass.connection.connect
111
+ end
112
+ end
@@ -0,0 +1,112 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestConnectionPerDN < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ priority :must
7
+ def test_bind_with_empty_password
8
+ make_temporary_user do |user, password|
9
+ assert_equal(user.class.connection, user.connection)
10
+ assert_raises(ActiveLdap::AuthenticationError) do
11
+ user.bind("", :try_sasl => false)
12
+ end
13
+ assert_equal(user.class.connection, user.connection)
14
+
15
+ assert_nothing_raised do
16
+ user.bind("", :try_sasl => false, :allow_anonymous => true)
17
+ end
18
+ assert_not_equal(user.class.connection, user.connection)
19
+ end
20
+ end
21
+
22
+ priority :normal
23
+ def test_rebind_with_invalid_password
24
+ make_temporary_user do |user, password|
25
+ assert_equal(user.class.connection, user.connection)
26
+ assert_nothing_raised do
27
+ user.bind(password)
28
+ end
29
+ assert_not_equal(user.class.connection, user.connection)
30
+
31
+ assert_raises(ActiveLdap::AuthenticationError) do
32
+ user.bind(password + "-WRONG", :try_sasl => false)
33
+ end
34
+ end
35
+ end
36
+
37
+ def test_bind
38
+ make_temporary_user do |user, password|
39
+ assert_equal(user.class.connection, user.connection)
40
+ assert_raises(ActiveLdap::AuthenticationError) do
41
+ user.bind(:bind_dn => nil,
42
+ :try_sasl => false,
43
+ :allow_anonymous => false,
44
+ :retry_limit => 0)
45
+ end
46
+ assert_equal(user.class.connection, user.connection)
47
+
48
+ assert_nothing_raised do
49
+ user.bind(:bind_dn => nil,
50
+ :try_sasl => false,
51
+ :allow_anonymous => true)
52
+ end
53
+ assert_not_equal(user.class.connection, user.connection)
54
+
55
+ assert_equal(user.connection, user.class.find(user.dn).connection)
56
+ begin
57
+ assert_equal(user.connection, user.find(user.dn).connection)
58
+ rescue ActiveLdap::EntryNotFound
59
+ omit("requires permission for searching by 'uid' to anonymous user.")
60
+ end
61
+ end
62
+ end
63
+
64
+ def test_find
65
+ make_temporary_user do |user, password|
66
+ make_temporary_user do |user2, password2|
67
+ user.bind(password)
68
+ assert_not_equal(user.class.connection, user.connection)
69
+
70
+ found_user2 = user.find(user2.dn)
71
+ assert_not_equal(user2.connection, found_user2.connection)
72
+ assert_equal(user.connection, found_user2.connection)
73
+
74
+ assert_equal(found_user2.class.connection,
75
+ found_user2.class.find(found_user2.dn).connection)
76
+
77
+ found_user2.bind(password2)
78
+ assert_not_equal(user.connection, found_user2.connection)
79
+ assert_equal(user2.connection, found_user2.connection)
80
+ end
81
+ end
82
+ end
83
+
84
+ def test_associations
85
+ make_temporary_user do |user, password|
86
+ make_temporary_group do |group1|
87
+ make_temporary_group do |group2|
88
+ user.groups = [group1]
89
+ assert_equal(group1.connection, user.connection)
90
+
91
+ user.bind(password, :try_sasl => false)
92
+ assert_not_equal(user.class.connection, user.connection)
93
+ assert_not_equal(group1.connection, user.connection)
94
+ assert_equal(user.groups[0].connection, user.connection)
95
+
96
+ assert_raise(ActiveLdap::OperationNotPermitted) do
97
+ user.groups << group2
98
+ end
99
+ assert_equal([group1.cn], user.groups.collect(&:cn))
100
+
101
+ assert_not_equal(group1.connection, user.connection)
102
+ assert_equal(user.groups[0].connection, user.connection)
103
+
104
+ found_user = user.class.find(user.dn)
105
+ assert_equal(user.connection, found_user.connection)
106
+ assert_equal(found_user.connection,
107
+ found_user.groups[0].connection)
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end