activeldap 1.0.2 → 1.0.9
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.
- data/CHANGES +32 -0
- data/README +8 -1
- data/data/locale/en/LC_MESSAGES/active-ldap.mo +0 -0
- data/data/locale/ja/LC_MESSAGES/active-ldap.mo +0 -0
- data/examples/al-admin/app/controllers/{application.rb → application_controller.rb} +3 -1
- data/examples/al-admin/app/views/account/sign_up.html.erb +6 -5
- data/examples/al-admin/config/boot.rb +1 -0
- data/examples/al-admin/config/environment.rb +4 -2
- data/examples/al-admin/config.ru +7 -0
- data/examples/al-admin/lib/ldap_test_helper.rb +38 -0
- data/examples/al-admin/lib/tasks/gettext.rake +3 -2
- data/examples/al-admin/lib/tasks/testing.rake +10 -0
- data/examples/al-admin/po/en/al-admin.po +4 -4
- data/examples/al-admin/po/ja/al-admin.po +4 -4
- data/examples/al-admin/po/nl/al-admin.po +3 -3
- data/examples/al-admin/public/dispatch.cgi +2 -2
- data/examples/al-admin/public/dispatch.fcgi +1 -1
- data/examples/al-admin/public/dispatch.rb +2 -2
- data/examples/al-admin/test/functional/account_controller_test.rb +2 -14
- data/examples/al-admin/test/functional/attributes_controller_test.rb +2 -12
- data/examples/al-admin/test/functional/directory_controller_test.rb +2 -12
- data/examples/al-admin/test/functional/object_classes_controller_test.rb +2 -12
- data/examples/al-admin/test/functional/syntaxes_controller_test.rb +2 -12
- data/examples/al-admin/test/functional/users_controller_test.rb +2 -12
- data/examples/al-admin/test/functional/welcome_controller_test.rb +2 -12
- data/examples/al-admin/test/integration/sign_up_test.rb +44 -0
- data/examples/al-admin/test/run-test.sh +1 -1
- data/examples/al-admin/test/test_helper.rb +25 -1
- data/examples/al-admin/test/unit/user_test.rb +1 -2
- data/examples/groupadd +2 -2
- data/examples/groupdel +2 -2
- data/examples/groupls +2 -2
- data/examples/groupmod +2 -2
- data/examples/lpasswd +2 -2
- data/examples/objects/group.rb +2 -2
- data/examples/objects/user.rb +1 -1
- data/examples/ouadd +2 -2
- data/examples/useradd +2 -2
- data/examples/useradd-binary +6 -3
- data/examples/userdel +2 -2
- data/examples/userls +2 -2
- data/examples/usermod +2 -2
- data/examples/usermod-binary-add +6 -3
- data/examples/usermod-binary-add-time +6 -3
- data/examples/usermod-binary-del +2 -2
- data/examples/usermod-lang-add +2 -2
- data/lib/active_ldap/adapter/base.rb +47 -23
- data/lib/active_ldap/adapter/jndi.rb +30 -28
- data/lib/active_ldap/adapter/jndi_connection.rb +6 -0
- data/lib/active_ldap/adapter/ldap.rb +25 -26
- data/lib/active_ldap/adapter/net_ldap.rb +28 -33
- data/lib/active_ldap/adapter/net_ldap_ext.rb +0 -6
- data/lib/active_ldap/association/proxy.rb +2 -1
- data/lib/active_ldap/attributes.rb +31 -0
- data/lib/active_ldap/base.rb +75 -31
- data/lib/active_ldap/compatible.rb +44 -0
- data/lib/active_ldap/configuration.rb +3 -3
- data/lib/active_ldap/connection.rb +41 -12
- data/lib/active_ldap/distinguished_name.rb +1 -0
- data/lib/active_ldap/get_text.rb +0 -7
- data/lib/active_ldap/ldif.rb +59 -44
- data/lib/active_ldap/operations.rb +41 -10
- data/lib/active_ldap/schema.rb +41 -6
- data/lib/active_ldap/user_password.rb +7 -7
- data/lib/active_ldap/validations.rb +24 -12
- data/lib/active_ldap/xml.rb +2 -2
- data/lib/active_ldap.rb +120 -139
- data/po/en/active-ldap.po +5 -5
- data/po/ja/active-ldap.po +5 -5
- data/rails/README +2 -2
- data/rails/init.rb +2 -2
- data/test/al-test-utils.rb +11 -4
- data/test/run-test.rb +6 -2
- data/test/test_associations.rb +4 -4
- data/test/test_attributes.rb +3 -1
- data/test/test_base.rb +75 -15
- data/test/test_base_per_instance.rb +7 -1
- data/test/test_bind.rb +4 -4
- data/test/test_connection.rb +36 -14
- data/test/test_connection_per_class.rb +5 -5
- data/test/test_connection_per_dn.rb +11 -5
- data/test/test_groupadd.rb +2 -2
- data/test/test_groupdel.rb +2 -2
- data/test/test_groupls.rb +1 -1
- data/test/test_groupmod.rb +2 -2
- data/test/test_ldif.rb +11 -1
- data/test/test_schema.rb +38 -2
- data/test/test_syntax.rb +12 -2
- data/test/test_useradd-binary.rb +1 -0
- data/test/test_usermod-binary-add-time.rb +1 -0
- data/test/test_usermod-binary-add.rb +1 -0
- data/test/test_validation.rb +24 -13
- data/test-unit/lib/test/unit/assertions.rb +97 -14
- data/test-unit/lib/test/unit/autorunner.rb +20 -4
- data/test-unit/lib/test/unit/priority.rb +21 -1
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +7 -4
- data/test-unit/test/test_assertions.rb +52 -5
- metadata +10 -14
- data/rails/plugin/active_ldap/README +0 -54
- data/rails/plugin/active_ldap/generators/README +0 -2
- data/rails/plugin/active_ldap/generators/model_active_ldap/USAGE +0 -17
- data/rails/plugin/active_ldap/generators/model_active_ldap/model_active_ldap_generator.rb +0 -70
- data/rails/plugin/active_ldap/generators/model_active_ldap/templates/fixtures.yml +0 -11
- data/rails/plugin/active_ldap/generators/model_active_ldap/templates/model_active_ldap.rb +0 -3
- data/rails/plugin/active_ldap/generators/model_active_ldap/templates/unit_test.rb +0 -10
- data/rails/plugin/active_ldap/generators/scaffold_active_ldap/scaffold_active_ldap_generator.rb +0 -7
- data/rails/plugin/active_ldap/generators/scaffold_al/scaffold_al_generator.rb +0 -20
- data/rails/plugin/active_ldap/init.rb +0 -36
- data/rails_generators/scaffold_al/scaffold_al_generator.rb +0 -20
data/rails/README
CHANGED
|
@@ -32,8 +32,8 @@ Here is some examples.
|
|
|
32
32
|
app/model/member.rb:
|
|
33
33
|
class Member < ActiveLdap::Base
|
|
34
34
|
ldap_mapping :dn_attribute => 'uid',
|
|
35
|
-
|
|
36
|
-
belongs_to :primary_group, :
|
|
35
|
+
:classes => ['person', 'posixAccount']
|
|
36
|
+
belongs_to :primary_group, :class_name => "Group",
|
|
37
37
|
:foreign_key => "gidNumber", :primary_key => "gidNumber"
|
|
38
38
|
belongs_to :groups, :many => 'memberUid'
|
|
39
39
|
end
|
data/rails/init.rb
CHANGED
|
@@ -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 = ["1", "
|
|
4
|
+
required_version = ["1", "1", "0"]
|
|
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")
|
|
@@ -13,7 +13,7 @@ ldap_configuration_file = File.join(RAILS_ROOT, 'config', 'ldap.yml')
|
|
|
13
13
|
if File.exist?(ldap_configuration_file)
|
|
14
14
|
configurations = YAML.load(ERB.new(IO.read(ldap_configuration_file)).result)
|
|
15
15
|
ActiveLdap::Base.configurations = configurations
|
|
16
|
-
ActiveLdap::Base.
|
|
16
|
+
ActiveLdap::Base.setup_connection
|
|
17
17
|
else
|
|
18
18
|
ActiveLdap::Base.class_eval do
|
|
19
19
|
format = _("You should run 'script/generator scaffold_active_ldap' to make %s.")
|
data/test/al-test-utils.rb
CHANGED
|
@@ -80,7 +80,7 @@ module AlTestUtils
|
|
|
80
80
|
def certificate
|
|
81
81
|
return @@certificate if @@certificate
|
|
82
82
|
if File.exists?(certificate_path)
|
|
83
|
-
@@certificate =
|
|
83
|
+
@@certificate = read_binary_file(certificate_path)
|
|
84
84
|
return @@certificate
|
|
85
85
|
end
|
|
86
86
|
|
|
@@ -123,14 +123,21 @@ module AlTestUtils
|
|
|
123
123
|
end
|
|
124
124
|
|
|
125
125
|
def jpeg_photo
|
|
126
|
-
|
|
126
|
+
read_binary_file(jpeg_photo_path)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def read_binary_file(path)
|
|
130
|
+
File.open(path, "rb") do |input|
|
|
131
|
+
input.set_encoding("ascii-8bit") if input.respond_to?(:set_encoding)
|
|
132
|
+
input.read
|
|
133
|
+
end
|
|
127
134
|
end
|
|
128
135
|
end
|
|
129
136
|
|
|
130
137
|
module Connection
|
|
131
138
|
def setup
|
|
132
139
|
super
|
|
133
|
-
ActiveLdap::Base.
|
|
140
|
+
ActiveLdap::Base.setup_connection
|
|
134
141
|
end
|
|
135
142
|
|
|
136
143
|
def teardown
|
|
@@ -153,7 +160,7 @@ module AlTestUtils
|
|
|
153
160
|
|
|
154
161
|
def teardown
|
|
155
162
|
if @dumped_data
|
|
156
|
-
ActiveLdap::Base.
|
|
163
|
+
ActiveLdap::Base.setup_connection
|
|
157
164
|
ActiveLdap::Base.delete_all(nil, :scope => :sub)
|
|
158
165
|
ActiveLdap::Base.load(@dumped_data)
|
|
159
166
|
end
|
data/test/run-test.rb
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
$VERBOSE = true
|
|
4
4
|
|
|
5
|
-
$KCODE = 'u'
|
|
5
|
+
$KCODE = 'u' if RUBY_VERSION < "1.9"
|
|
6
6
|
|
|
7
7
|
require 'yaml'
|
|
8
8
|
|
|
@@ -20,7 +20,11 @@ Dir.glob(test_file) do |file|
|
|
|
20
20
|
require file
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
[nil
|
|
23
|
+
target_adapters = [nil]
|
|
24
|
+
# target_adapters << "ldap"
|
|
25
|
+
# target_adapters << "net-ldap"
|
|
26
|
+
# target_adapters << "jndi"
|
|
27
|
+
target_adapters.each do |adapter|
|
|
24
28
|
ENV["ACTIVE_LDAP_TEST_ADAPTER"] = adapter
|
|
25
29
|
puts "using adapter: #{adapter ? adapter : 'default'}"
|
|
26
30
|
args = [File.dirname($0), ARGV.dup]
|
data/test/test_associations.rb
CHANGED
|
@@ -225,12 +225,12 @@ class TestAssociations < Test::Unit::TestCase
|
|
|
225
225
|
mod = Module.new
|
|
226
226
|
mod.__send__(:mattr_accessor, :called)
|
|
227
227
|
mod.__send__(:define_method, :replace) do |entries|
|
|
228
|
-
super
|
|
228
|
+
super(entries)
|
|
229
229
|
mod.called = true
|
|
230
230
|
end
|
|
231
231
|
mod.called = false
|
|
232
232
|
|
|
233
|
-
@group_class.send(:undef_method, :members, :members
|
|
233
|
+
@group_class.send(:undef_method, :members, :members=, :__make_members)
|
|
234
234
|
@group_class.has_many :members, :wrap => "memberUid",
|
|
235
235
|
:extend => mod
|
|
236
236
|
@group_class.set_associated_class(:members, @user_class)
|
|
@@ -270,7 +270,7 @@ class TestAssociations < Test::Unit::TestCase
|
|
|
270
270
|
group.members = [user1]
|
|
271
271
|
assert_equal([user1.uid].sort,
|
|
272
272
|
group.members.collect {|x| x.uid}.sort)
|
|
273
|
-
assert_equal(
|
|
273
|
+
assert_equal(user1.uid, group.member_uid)
|
|
274
274
|
assert_equal(gid_number1, user1.gid_number.to_i)
|
|
275
275
|
end
|
|
276
276
|
end
|
|
@@ -452,7 +452,7 @@ class TestAssociations < Test::Unit::TestCase
|
|
|
452
452
|
group.members << user1
|
|
453
453
|
assert_equal([user1.uid].sort,
|
|
454
454
|
group.members.collect {|x| x.uid}.sort)
|
|
455
|
-
assert_equal(
|
|
455
|
+
assert_equal(user1.uid, group.member_uid)
|
|
456
456
|
assert_equal(gid_number1, user1.gid_number.to_i)
|
|
457
457
|
|
|
458
458
|
assert_equal(gid_number2, user2.gid_number.to_i)
|
data/test/test_attributes.rb
CHANGED
|
@@ -8,9 +8,11 @@ class TestAttributes < Test::Unit::TestCase
|
|
|
8
8
|
priority :normal
|
|
9
9
|
def test_to_real_attribute_name
|
|
10
10
|
user = @user_class.new("user")
|
|
11
|
-
|
|
11
|
+
assert_equal("objectClass",
|
|
12
|
+
user.__send__(:to_real_attribute_name, "objectclass"))
|
|
12
13
|
assert_equal("objectClass",
|
|
13
14
|
user.__send__(:to_real_attribute_name, "objectclass", true))
|
|
15
|
+
assert_nil(user.__send__(:to_real_attribute_name, "objectclass", false))
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
def test_protect_object_class_from_mass_assignment
|
data/test/test_base.rb
CHANGED
|
@@ -6,12 +6,54 @@ class TestBase < Test::Unit::TestCase
|
|
|
6
6
|
include AlTestUtils
|
|
7
7
|
|
|
8
8
|
priority :must
|
|
9
|
+
def test_first
|
|
10
|
+
make_temporary_user(:simple => true) do |user1,|
|
|
11
|
+
make_temporary_user(:simple => true) do |user2,|
|
|
12
|
+
assert_equal(user1, @user_class.find(:first))
|
|
13
|
+
assert_equal(user2, @user_class.find(:first, user2.cn))
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_last
|
|
19
|
+
make_temporary_user(:simple => true) do |user1,|
|
|
20
|
+
make_temporary_user(:simple => true) do |user2,|
|
|
21
|
+
assert_equal(user2, @user_class.find(:last))
|
|
22
|
+
assert_equal(user1, @user_class.find(:last, user1.cn))
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_convenient_operation_methods
|
|
28
|
+
make_temporary_user(:simple => true) do |user1,|
|
|
29
|
+
make_temporary_user(:simple => true) do |user2,|
|
|
30
|
+
assert_equal(user1, @user_class.first)
|
|
31
|
+
assert_equal(user2, @user_class.last)
|
|
32
|
+
assert_equal([user1, user2], @user_class.all)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
priority :normal
|
|
38
|
+
def test_set_attributes_with_a_blank_value_in_values
|
|
39
|
+
make_temporary_user(:simple => true) do |user,|
|
|
40
|
+
user.attributes = {"description" => ["a", "b", ""]}
|
|
41
|
+
assert(user.save)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_set_attributes_with_a_blank_value
|
|
46
|
+
make_temporary_user(:simple => true) do |user,|
|
|
47
|
+
user.attributes = {"description" => [""]}
|
|
48
|
+
assert(user.save)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
9
52
|
def test_create_invalid
|
|
10
53
|
user = @user_class.create
|
|
11
54
|
assert_not_predicate(user.errors, :empty?)
|
|
12
55
|
end
|
|
13
56
|
|
|
14
|
-
priority :normal
|
|
15
57
|
def test_id_with_invalid_dn_attribute_value
|
|
16
58
|
user = @user_class.new("#")
|
|
17
59
|
assert_equal("#", user.uid)
|
|
@@ -36,16 +78,18 @@ class TestBase < Test::Unit::TestCase
|
|
|
36
78
|
end
|
|
37
79
|
end
|
|
38
80
|
|
|
39
|
-
def
|
|
81
|
+
def test_destroy_with_empty_base_and_prefix_of_class
|
|
40
82
|
make_temporary_user do |user,|
|
|
41
83
|
base = user.class.base
|
|
84
|
+
prefix = user.class.prefix
|
|
42
85
|
begin
|
|
43
86
|
user.class.base = ""
|
|
44
|
-
user.prefix = ""
|
|
87
|
+
user.class.prefix = ""
|
|
45
88
|
user.base = base
|
|
46
89
|
user.destroy
|
|
47
90
|
ensure
|
|
48
91
|
user.class.base = base
|
|
92
|
+
user.class.prefix = prefix
|
|
49
93
|
end
|
|
50
94
|
end
|
|
51
95
|
end
|
|
@@ -76,13 +120,13 @@ class TestBase < Test::Unit::TestCase
|
|
|
76
120
|
end
|
|
77
121
|
|
|
78
122
|
def test_to_s
|
|
79
|
-
make_temporary_group do |group
|
|
123
|
+
make_temporary_group do |group|
|
|
80
124
|
assert_equal(group.to_s, group.to_ldif)
|
|
81
125
|
end
|
|
82
126
|
end
|
|
83
127
|
|
|
84
128
|
def test_to_ldif
|
|
85
|
-
make_temporary_group do |group
|
|
129
|
+
make_temporary_group do |group|
|
|
86
130
|
assert_to_ldif(group)
|
|
87
131
|
|
|
88
132
|
group.gidNumber += 1
|
|
@@ -626,7 +670,8 @@ EOX
|
|
|
626
670
|
EOX
|
|
627
671
|
|
|
628
672
|
make_temporary_user do |user, password|
|
|
629
|
-
|
|
673
|
+
xml = normalize_attributes_order(user.to_xml(:root => "user"))
|
|
674
|
+
assert_equal(<<-EOX, xml)
|
|
630
675
|
<user>
|
|
631
676
|
<dn>#{user.dn}</dn>
|
|
632
677
|
<cns type="array">
|
|
@@ -652,7 +697,7 @@ EOX
|
|
|
652
697
|
</uids>
|
|
653
698
|
<uidNumber>#{user.uid_number}</uidNumber>
|
|
654
699
|
<userCertificates type="array">
|
|
655
|
-
<userCertificate
|
|
700
|
+
<userCertificate base64="true" binary="true">#{base64(certificate)}</userCertificate>
|
|
656
701
|
</userCertificates>
|
|
657
702
|
<userPasswords type="array">
|
|
658
703
|
<userPassword>#{user.user_password}</userPassword>
|
|
@@ -761,13 +806,13 @@ EOX
|
|
|
761
806
|
|
|
762
807
|
def test_have_attribute?
|
|
763
808
|
make_temporary_user do |user, password|
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
809
|
+
assert_true(user.have_attribute?(:cn))
|
|
810
|
+
assert_true(user.have_attribute?(:commonName))
|
|
811
|
+
assert_true(user.have_attribute?(:common_name))
|
|
812
|
+
assert_true(user.have_attribute?(:commonname))
|
|
813
|
+
assert_true(user.have_attribute?(:COMMONNAME))
|
|
769
814
|
|
|
770
|
-
|
|
815
|
+
assert_false(user.have_attribute?(:unknown_attribute))
|
|
771
816
|
end
|
|
772
817
|
end
|
|
773
818
|
|
|
@@ -791,7 +836,7 @@ EOX
|
|
|
791
836
|
|
|
792
837
|
def test_update_all
|
|
793
838
|
make_temporary_user do |user, password|
|
|
794
|
-
make_temporary_user do |user2,
|
|
839
|
+
make_temporary_user do |user2, password2|
|
|
795
840
|
user2_cn = user2.cn
|
|
796
841
|
new_cn = "New #{user.cn}"
|
|
797
842
|
@user_class.update_all({:cn => new_cn}, user.uid)
|
|
@@ -817,7 +862,7 @@ EOX
|
|
|
817
862
|
new_user = @user_class.update(user.dn, {:cn => new_cn})
|
|
818
863
|
assert_equal(new_cn, new_user.cn)
|
|
819
864
|
|
|
820
|
-
make_temporary_user do |user2,
|
|
865
|
+
make_temporary_user do |user2, password2|
|
|
821
866
|
new_sns = ["New SN1", "New SN2"]
|
|
822
867
|
new_cn2 = "New #{user2.cn}"
|
|
823
868
|
new_user, new_user2 = @user_class.update([user.dn, user2.dn],
|
|
@@ -862,4 +907,19 @@ EOX
|
|
|
862
907
|
def base64(string)
|
|
863
908
|
[string].pack("m").gsub(/\n/u, "")
|
|
864
909
|
end
|
|
910
|
+
|
|
911
|
+
def normalize_attributes_order(xml)
|
|
912
|
+
xml.gsub(/<(\S+) (.+?)(\/?)>/) do |matched|
|
|
913
|
+
name = $1
|
|
914
|
+
attributes = $2
|
|
915
|
+
close_mark = $3
|
|
916
|
+
attributes = attributes.scan(/(\S+)="(.+?)"/)
|
|
917
|
+
normalized_attributes = attributes.sort_by do |key, value|
|
|
918
|
+
key
|
|
919
|
+
end.collect do |key, value|
|
|
920
|
+
"#{key}=\"#{value}\""
|
|
921
|
+
end.join(' ')
|
|
922
|
+
"<#{name} #{normalized_attributes}#{close_mark}>"
|
|
923
|
+
end
|
|
924
|
+
end
|
|
865
925
|
end
|
|
@@ -9,6 +9,13 @@ class TestBasePerInstance < Test::Unit::TestCase
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
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
|
|
12
19
|
def test_dn_is_base
|
|
13
20
|
entry_class = Class.new(ActiveLdap::Base)
|
|
14
21
|
entry_class.ldap_mapping :prefix => "",
|
|
@@ -21,7 +28,6 @@ class TestBasePerInstance < Test::Unit::TestCase
|
|
|
21
28
|
assert_equal(entry_class.base, entry.base)
|
|
22
29
|
end
|
|
23
30
|
|
|
24
|
-
priority :normal
|
|
25
31
|
def test_loose_dn
|
|
26
32
|
user = @user_class.new("test-user , ou = Sub")
|
|
27
33
|
assert_equal("uid=test-user,ou=Sub,#{@user_class.base}", user.dn)
|
data/test/test_bind.rb
CHANGED
|
@@ -29,9 +29,8 @@ class TestBind < Test::Unit::TestCase
|
|
|
29
29
|
assert(!ActiveLdap::Base.connected?)
|
|
30
30
|
config = ActiveLdap::Base.configurations[LDAP_ENV].symbolize_keys
|
|
31
31
|
config = ActiveLdap::Base.prepare_configuration(config)
|
|
32
|
-
if config[:bind_dn].nil?
|
|
33
|
-
|
|
34
|
-
return
|
|
32
|
+
if config[:bind_dn].nil? and !config[:try_sasl]
|
|
33
|
+
omit("need user configuration")
|
|
35
34
|
end
|
|
36
35
|
assert_nothing_raised do
|
|
37
36
|
config[:allow_anonymous] = false
|
|
@@ -48,6 +47,7 @@ class TestBind < Test::Unit::TestCase
|
|
|
48
47
|
config = ActiveLdap::Base.configurations[LDAP_ENV].symbolize_keys
|
|
49
48
|
config = ActiveLdap::Base.prepare_configuration(config)
|
|
50
49
|
config.delete(:bind_dn)
|
|
50
|
+
config[:try_sasl] = false
|
|
51
51
|
config[:allow_anonymous] = false
|
|
52
52
|
connect(config)
|
|
53
53
|
end
|
|
@@ -56,7 +56,7 @@ class TestBind < Test::Unit::TestCase
|
|
|
56
56
|
|
|
57
57
|
private
|
|
58
58
|
def connect(config)
|
|
59
|
-
ActiveLdap::Base.
|
|
59
|
+
ActiveLdap::Base.setup_connection(config)
|
|
60
60
|
ActiveLdap::Base.connection.connect
|
|
61
61
|
end
|
|
62
62
|
end
|
data/test/test_connection.rb
CHANGED
|
@@ -14,17 +14,33 @@ class TestConnection < Test::Unit::TestCase
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
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
|
|
17
34
|
|
|
18
|
-
priority :normal
|
|
19
35
|
def test_bind_format_check
|
|
20
36
|
connector = Class.new(ActiveLdap::Base)
|
|
21
37
|
assert(!connector.connected?)
|
|
22
38
|
exception = nil
|
|
23
39
|
assert_raises(ArgumentError) do
|
|
24
40
|
begin
|
|
25
|
-
connector.
|
|
26
|
-
|
|
27
|
-
|
|
41
|
+
connector.setup_connection(:adapter => adapter,
|
|
42
|
+
:bind_format => "uid=%s,dc=test",
|
|
43
|
+
:allow_anonymous => false)
|
|
28
44
|
connector.connection.connect
|
|
29
45
|
rescue Exception
|
|
30
46
|
exception = $!
|
|
@@ -38,23 +54,29 @@ class TestConnection < Test::Unit::TestCase
|
|
|
38
54
|
assert(!ActiveLdap::Base.connected?)
|
|
39
55
|
|
|
40
56
|
config = current_configuration.merge("retry_limit" => 10)
|
|
41
|
-
ActiveLdap::Base.
|
|
57
|
+
ActiveLdap::Base.setup_connection(config)
|
|
42
58
|
connection = ActiveLdap::Base.connection
|
|
43
|
-
assert(!connection.send(:can_reconnect?, :reconnect_attempts =>
|
|
59
|
+
assert(!connection.send(:can_reconnect?, :reconnect_attempts => 11))
|
|
44
60
|
|
|
45
61
|
config = current_configuration.merge("retry_limit" => 10)
|
|
46
|
-
ActiveLdap::Base.
|
|
62
|
+
ActiveLdap::Base.setup_connection(config)
|
|
47
63
|
connection = ActiveLdap::Base.connection
|
|
48
|
-
assert(
|
|
49
|
-
|
|
50
|
-
config = current_configuration.merge("retry_limit" => 10)
|
|
51
|
-
ActiveLdap::Base.establish_connection(config)
|
|
52
|
-
connection = ActiveLdap::Base.connection
|
|
53
|
-
assert(connection.send(:can_reconnect?, :reconnect_attempts => 8))
|
|
64
|
+
assert(connection.send(:can_reconnect?, :reconnect_attempts => 10))
|
|
54
65
|
|
|
55
66
|
config = current_configuration.merge("retry_limit" => -1)
|
|
56
|
-
ActiveLdap::Base.
|
|
67
|
+
ActiveLdap::Base.setup_connection(config)
|
|
57
68
|
connection = ActiveLdap::Base.connection
|
|
58
69
|
assert(connection.send(:can_reconnect?, :reconnect_attempts => -10))
|
|
59
70
|
end
|
|
71
|
+
|
|
72
|
+
priority :low
|
|
73
|
+
def test_retry_limit_0_with_nonexistent_host
|
|
74
|
+
config = current_configuration.merge("host" => "192.168.29.29",
|
|
75
|
+
"retry_limit" => 0)
|
|
76
|
+
ActiveLdap::Base.setup_connection(config)
|
|
77
|
+
notify("maybe take a long time")
|
|
78
|
+
assert_raise(ActiveLdap::ConnectionError) do
|
|
79
|
+
ActiveLdap::Base.find(:first)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
60
82
|
end
|
|
@@ -4,7 +4,7 @@ class TestConnectionPerClass < Test::Unit::TestCase
|
|
|
4
4
|
include AlTestUtils
|
|
5
5
|
|
|
6
6
|
priority :must
|
|
7
|
-
def
|
|
7
|
+
def test_multi_setup_connections_with_association
|
|
8
8
|
make_ou("Sub,ou=Users")
|
|
9
9
|
make_ou("Sub2,ou=Users")
|
|
10
10
|
|
|
@@ -30,7 +30,7 @@ class TestConnectionPerClass < Test::Unit::TestCase
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
priority :normal
|
|
33
|
-
def
|
|
33
|
+
def test_multi_setup_connections
|
|
34
34
|
make_ou("Sub")
|
|
35
35
|
make_ou("Sub2")
|
|
36
36
|
sub_class = ou_class("ou=Sub")
|
|
@@ -46,9 +46,9 @@ class TestConnectionPerClass < Test::Unit::TestCase
|
|
|
46
46
|
sub2_base = "ou=Sub2,#{current_base}"
|
|
47
47
|
sub2_configuration[:base] = sub2_base
|
|
48
48
|
|
|
49
|
-
sub_class.
|
|
49
|
+
sub_class.setup_connection(sub_configuration)
|
|
50
50
|
sub_class.prefix = nil
|
|
51
|
-
sub2_class.
|
|
51
|
+
sub2_class.setup_connection(sub2_configuration)
|
|
52
52
|
sub2_class.prefix = nil
|
|
53
53
|
|
|
54
54
|
assert_equal([sub_base], sub_class.find(:all).collect(&:dn))
|
|
@@ -106,7 +106,7 @@ class TestConnectionPerClass < Test::Unit::TestCase
|
|
|
106
106
|
|
|
107
107
|
private
|
|
108
108
|
def connect(klass, config)
|
|
109
|
-
klass.
|
|
109
|
+
klass.setup_connection({:adapter => adapter}.merge(config))
|
|
110
110
|
klass.connection.connect
|
|
111
111
|
end
|
|
112
112
|
end
|
|
@@ -8,12 +8,12 @@ class TestConnectionPerDN < Test::Unit::TestCase
|
|
|
8
8
|
make_temporary_user do |user, password|
|
|
9
9
|
assert_equal(user.class.connection, user.connection)
|
|
10
10
|
assert_raises(ActiveLdap::AuthenticationError) do
|
|
11
|
-
user.bind("")
|
|
11
|
+
user.bind("", :try_sasl => false)
|
|
12
12
|
end
|
|
13
13
|
assert_equal(user.class.connection, user.connection)
|
|
14
14
|
|
|
15
15
|
assert_nothing_raised do
|
|
16
|
-
user.bind("", :allow_anonymous => true)
|
|
16
|
+
user.bind("", :try_sasl => false, :allow_anonymous => true)
|
|
17
17
|
end
|
|
18
18
|
assert_not_equal(user.class.connection, user.connection)
|
|
19
19
|
end
|
|
@@ -29,7 +29,7 @@ class TestConnectionPerDN < Test::Unit::TestCase
|
|
|
29
29
|
assert_not_equal(user.class.connection, user.connection)
|
|
30
30
|
|
|
31
31
|
assert_raises(ActiveLdap::AuthenticationError) do
|
|
32
|
-
user.bind(password + "-WRONG")
|
|
32
|
+
user.bind(password + "-WRONG", :try_sasl => false)
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
end
|
|
@@ -39,6 +39,7 @@ class TestConnectionPerDN < Test::Unit::TestCase
|
|
|
39
39
|
assert_equal(user.class.connection, user.connection)
|
|
40
40
|
assert_raises(ActiveLdap::AuthenticationError) do
|
|
41
41
|
user.bind(:bind_dn => nil,
|
|
42
|
+
:try_sasl => false,
|
|
42
43
|
:allow_anonymous => false,
|
|
43
44
|
:retry_limit => 0)
|
|
44
45
|
end
|
|
@@ -46,12 +47,17 @@ class TestConnectionPerDN < Test::Unit::TestCase
|
|
|
46
47
|
|
|
47
48
|
assert_nothing_raised do
|
|
48
49
|
user.bind(:bind_dn => nil,
|
|
50
|
+
:try_sasl => false,
|
|
49
51
|
:allow_anonymous => true)
|
|
50
52
|
end
|
|
51
53
|
assert_not_equal(user.class.connection, user.connection)
|
|
52
54
|
|
|
53
55
|
assert_equal(user.connection, user.class.find(user.dn).connection)
|
|
54
|
-
|
|
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
|
|
55
61
|
end
|
|
56
62
|
end
|
|
57
63
|
|
|
@@ -82,7 +88,7 @@ class TestConnectionPerDN < Test::Unit::TestCase
|
|
|
82
88
|
user.groups = [group1]
|
|
83
89
|
assert_equal(group1.connection, user.connection)
|
|
84
90
|
|
|
85
|
-
user.bind(password)
|
|
91
|
+
user.bind(password, :try_sasl => false)
|
|
86
92
|
assert_not_equal(user.class.connection, user.connection)
|
|
87
93
|
assert_not_equal(group1.connection, user.connection)
|
|
88
94
|
assert_equal(user.groups[0].connection, user.connection)
|
data/test/test_groupadd.rb
CHANGED
|
@@ -12,7 +12,7 @@ class TestGroupadd < Test::Unit::TestCase
|
|
|
12
12
|
|
|
13
13
|
priority :normal
|
|
14
14
|
def test_exist_group
|
|
15
|
-
make_temporary_group do |group
|
|
15
|
+
make_temporary_group do |group|
|
|
16
16
|
assert(@group_class.exists?(group.id))
|
|
17
17
|
assert_equal([false, "Group #{group.id} already exists.\n"],
|
|
18
18
|
run_command(group.id))
|
|
@@ -21,7 +21,7 @@ class TestGroupadd < Test::Unit::TestCase
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def test_add_group
|
|
24
|
-
ensure_delete_group("test-group") do |gid
|
|
24
|
+
ensure_delete_group("test-group") do |gid|
|
|
25
25
|
assert_groupadd_successfully(gid)
|
|
26
26
|
end
|
|
27
27
|
end
|
data/test/test_groupdel.rb
CHANGED
|
@@ -12,7 +12,7 @@ class TestGroupdel < Test::Unit::TestCase
|
|
|
12
12
|
|
|
13
13
|
priority :normal
|
|
14
14
|
def test_non_exist_group
|
|
15
|
-
ensure_delete_group("test-group") do |name
|
|
15
|
+
ensure_delete_group("test-group") do |name|
|
|
16
16
|
assert(!@group_class.exists?(name))
|
|
17
17
|
assert_equal([false, "Group #{name} doesn't exist.\n"], run_command(name))
|
|
18
18
|
assert(!@group_class.exists?(name))
|
|
@@ -20,7 +20,7 @@ class TestGroupdel < Test::Unit::TestCase
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def test_delete_group
|
|
23
|
-
make_temporary_group do |group
|
|
23
|
+
make_temporary_group do |group|
|
|
24
24
|
assert_groupdel_successfully(group.id)
|
|
25
25
|
end
|
|
26
26
|
end
|
data/test/test_groupls.rb
CHANGED
|
@@ -14,7 +14,7 @@ class TestGroupls < Test::Unit::TestCase
|
|
|
14
14
|
|
|
15
15
|
priority :normal
|
|
16
16
|
def test_non_exist_group
|
|
17
|
-
ensure_delete_group("test-group") do |name
|
|
17
|
+
ensure_delete_group("test-group") do |name|
|
|
18
18
|
assert(!@group_class.exists?(name))
|
|
19
19
|
assert_equal([false, "Group #{name} doesn't exist.\n"], run_command(name))
|
|
20
20
|
assert(!@group_class.exists?(name))
|
data/test/test_groupmod.rb
CHANGED
|
@@ -12,7 +12,7 @@ class TestGroupmod < Test::Unit::TestCase
|
|
|
12
12
|
|
|
13
13
|
priority :normal
|
|
14
14
|
def test_non_exist_group
|
|
15
|
-
ensure_delete_group("test-group") do |name
|
|
15
|
+
ensure_delete_group("test-group") do |name|
|
|
16
16
|
assert(!@group_class.exists?(name))
|
|
17
17
|
assert_equal([false, "Group #{name} doesn't exist.\n"],
|
|
18
18
|
run_command(name, 111111))
|
|
@@ -21,7 +21,7 @@ class TestGroupmod < Test::Unit::TestCase
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def test_modify_group
|
|
24
|
-
make_temporary_group do |group
|
|
24
|
+
make_temporary_group do |group|
|
|
25
25
|
assert_groupmod_successfully(group.cn, group.gid_number.succ)
|
|
26
26
|
end
|
|
27
27
|
end
|
data/test/test_ldif.rb
CHANGED
|
@@ -1212,6 +1212,7 @@ uid: hjensen
|
|
|
1212
1212
|
telephonenumber: +1 408 555 1212
|
|
1213
1213
|
jpegphoto:< file://#{jpeg_photo_path}
|
|
1214
1214
|
EOL
|
|
1215
|
+
set_encoding(ldif_source, "utf-8")
|
|
1215
1216
|
|
|
1216
1217
|
jpeg_photo_attribute = "jpegphoto:: "
|
|
1217
1218
|
value = [jpeg_photo].pack("m").gsub(/\n/, '')
|
|
@@ -1295,6 +1296,7 @@ sn;lang-en: Ogasawara
|
|
|
1295
1296
|
cn;lang-en: Rodney Ogasawara
|
|
1296
1297
|
title;lang-en: Sales, Director
|
|
1297
1298
|
EOL
|
|
1299
|
+
set_encoding(ldif_source, "utf-8")
|
|
1298
1300
|
|
|
1299
1301
|
record1 = {
|
|
1300
1302
|
"dn" => "ou=営業部,o=Airius",
|
|
@@ -1422,6 +1424,7 @@ sn;lang-en: Ogasawara
|
|
|
1422
1424
|
cn;lang-en: Rodney Ogasawara
|
|
1423
1425
|
title;lang-en: Sales, Director
|
|
1424
1426
|
EOL
|
|
1427
|
+
set_encoding(ldif_source, "utf-8")
|
|
1425
1428
|
|
|
1426
1429
|
assert_ldif_to_s(<<-EOL, ldif_source)
|
|
1427
1430
|
version: 1
|
|
@@ -1833,12 +1836,15 @@ EOL
|
|
|
1833
1836
|
|
|
1834
1837
|
private
|
|
1835
1838
|
def assert_ldif(version, records, ldif_source)
|
|
1839
|
+
encoding = ldif_source.encoding if ldif_source.respond_to?(:encoding)
|
|
1836
1840
|
ldif = ActiveLdap::Ldif.parse(ldif_source)
|
|
1837
1841
|
assert_equal(version, ldif.version)
|
|
1838
1842
|
assert_equal(records,
|
|
1839
1843
|
ldif.records.collect {|record| record.to_hash})
|
|
1840
1844
|
|
|
1841
|
-
|
|
1845
|
+
regenerated_ldif = ldif.to_s
|
|
1846
|
+
set_encoding(regenerated_ldif, encoding)
|
|
1847
|
+
reparsed_ldif = ActiveLdap::Ldif.parse(regenerated_ldif)
|
|
1842
1848
|
assert_equal(ldif, reparsed_ldif)
|
|
1843
1849
|
|
|
1844
1850
|
ldif
|
|
@@ -1869,4 +1875,8 @@ EOL
|
|
|
1869
1875
|
ldif = ActiveLdap::Ldif.parse(original_ldif_source)
|
|
1870
1876
|
assert_equal(expected_ldif_source, ldif.to_s)
|
|
1871
1877
|
end
|
|
1878
|
+
|
|
1879
|
+
def set_encoding(string, encoding)
|
|
1880
|
+
string.force_encoding("utf-8") if string.respond_to?(:force_encoding)
|
|
1881
|
+
end
|
|
1872
1882
|
end
|