activeldap 0.9.0 → 0.10.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 (120) hide show
  1. data/CHANGES +61 -0
  2. data/README +8 -1
  3. data/Rakefile +4 -1
  4. data/benchmark/bench-al.rb +12 -2
  5. data/examples/al-admin/app/controllers/account_controller.rb +4 -3
  6. data/examples/al-admin/app/controllers/application.rb +5 -2
  7. data/examples/al-admin/app/controllers/directory_controller.rb +3 -1
  8. data/examples/al-admin/app/controllers/users_controller.rb +19 -4
  9. data/examples/al-admin/app/controllers/welcome_controller.rb +4 -2
  10. data/examples/al-admin/app/helpers/application_helper.rb +7 -1
  11. data/examples/al-admin/app/helpers/url_helper.rb +4 -0
  12. data/examples/al-admin/app/models/ldap_user.rb +4 -0
  13. data/examples/al-admin/app/views/_entry/{_attributes_information.rhtml → _attributes_information.html.erb} +0 -0
  14. data/examples/al-admin/app/views/_entry/{_entry.rhtml → _entry.html.erb} +0 -0
  15. data/examples/al-admin/app/views/_schema/{_aliases.rhtml → _aliases.html.erb} +0 -0
  16. data/examples/al-admin/app/views/_switcher/{_after.rhtml → _after.html.erb} +0 -0
  17. data/examples/al-admin/app/views/_switcher/{_before.rhtml → _before.html.erb} +0 -0
  18. data/examples/al-admin/app/views/account/{login.rhtml → login.html.erb} +0 -0
  19. data/examples/al-admin/app/views/account/{sign_up.rhtml → sign_up.html.erb} +0 -0
  20. data/examples/al-admin/app/views/attributes/{_attributes.rhtml → _attributes.html.erb} +0 -0
  21. data/examples/al-admin/app/views/attributes/{_detail.rhtml → _detail.html.erb} +0 -0
  22. data/examples/al-admin/app/views/attributes/{index.rhtml → index.html.erb} +0 -0
  23. data/examples/al-admin/app/views/attributes/{show.rhtml → show.html.erb} +0 -0
  24. data/examples/al-admin/app/views/directory/{_tree.rhtml → _tree.html.erb} +0 -0
  25. data/examples/al-admin/app/views/directory/{_tree_view_js.rhtml → _tree_view_js.html.erb} +4 -5
  26. data/examples/al-admin/app/views/directory/{index.rhtml → index.html.erb} +0 -0
  27. data/examples/al-admin/app/views/directory/{populate.rhtml → populate.html.erb} +0 -0
  28. data/examples/al-admin/app/views/layouts/{_footer.rhtml → _footer.html.erb} +0 -0
  29. data/examples/al-admin/app/views/layouts/{_header_menu.rhtml → _header_menu.html.erb} +0 -0
  30. data/examples/al-admin/app/views/layouts/{_main_menu.rhtml → _main_menu.html.erb} +0 -0
  31. data/examples/al-admin/app/views/layouts/{application.rhtml → application.html.erb} +3 -2
  32. data/examples/al-admin/app/views/object_classes/{_attributes.rhtml → _attributes.html.erb} +0 -0
  33. data/examples/al-admin/app/views/object_classes/{_object_classes.rhtml → _object_classes.html.erb} +0 -0
  34. data/examples/al-admin/app/views/object_classes/{index.rhtml → index.html.erb} +0 -0
  35. data/examples/al-admin/app/views/object_classes/{show.rhtml → show.html.erb} +0 -0
  36. data/examples/al-admin/app/views/syntaxes/{_detail.rhtml → _detail.html.erb} +0 -0
  37. data/examples/al-admin/app/views/syntaxes/{_syntaxes.rhtml → _syntaxes.html.erb} +0 -0
  38. data/examples/al-admin/app/views/syntaxes/{index.rhtml → index.html.erb} +0 -0
  39. data/examples/al-admin/app/views/syntaxes/{show.rhtml → show.html.erb} +0 -0
  40. data/examples/al-admin/app/views/users/{_attributes_update_form.rhtml → _attributes_update_form.html.erb} +0 -0
  41. data/examples/al-admin/app/views/users/{_form.rhtml → _form.html.erb} +0 -0
  42. data/examples/al-admin/app/views/users/{_object_classes_update_form.rhtml → _object_classes_update_form.html.erb} +7 -1
  43. data/examples/al-admin/app/views/users/{_password_change_form.rhtml → _password_change_form.html.erb} +0 -0
  44. data/examples/al-admin/app/views/users/{edit.rhtml → edit.html.erb} +0 -0
  45. data/examples/al-admin/app/views/users/{index.rhtml → index.html.erb} +0 -0
  46. data/examples/al-admin/app/views/users/{show.rhtml → show.html.erb} +0 -0
  47. data/examples/al-admin/app/views/welcome/{index.rhtml → index.html.erb} +0 -0
  48. data/examples/al-admin/config/boot.rb +96 -32
  49. data/examples/al-admin/config/environment.rb +30 -36
  50. data/examples/al-admin/config/environments/development.rb +2 -5
  51. data/examples/al-admin/config/environments/production.rb +1 -0
  52. data/examples/al-admin/config/environments/test.rb +4 -1
  53. data/examples/al-admin/config/initializers/exception_notifier.rb +2 -0
  54. data/examples/al-admin/config/initializers/gettext.rb +1 -0
  55. data/examples/al-admin/config/initializers/inflections.rb +10 -0
  56. data/examples/al-admin/config/initializers/mime_types.rb +5 -0
  57. data/examples/al-admin/config/initializers/ralative_url_support.rb +1 -0
  58. data/examples/al-admin/config/routes.rb +24 -12
  59. data/examples/al-admin/lib/authenticated_system.rb +1 -1
  60. data/examples/al-admin/lib/tasks/gettext.rake +1 -1
  61. data/examples/al-admin/po/en/al-admin.po +102 -100
  62. data/examples/al-admin/po/ja/al-admin.po +112 -110
  63. data/examples/al-admin/po/nl/al-admin.po +117 -110
  64. data/examples/al-admin/public/javascripts/controls.js +484 -354
  65. data/examples/al-admin/public/javascripts/dragdrop.js +88 -58
  66. data/examples/al-admin/public/javascripts/effects.js +396 -364
  67. data/examples/al-admin/public/javascripts/prototype.js +2817 -1107
  68. data/examples/al-admin/public/stylesheets/base.css +5 -0
  69. data/examples/al-admin/script/performance/request +3 -0
  70. data/lib/active_ldap.rb +13 -10
  71. data/lib/active_ldap/adapter/base.rb +159 -43
  72. data/lib/active_ldap/adapter/jndi.rb +175 -0
  73. data/lib/active_ldap/adapter/jndi_connection.rb +180 -0
  74. data/lib/active_ldap/adapter/ldap.rb +91 -46
  75. data/lib/active_ldap/adapter/ldap_ext.rb +19 -5
  76. data/lib/active_ldap/adapter/net_ldap.rb +52 -44
  77. data/lib/active_ldap/association/has_many_wrap.rb +1 -1
  78. data/lib/active_ldap/attributes.rb +20 -95
  79. data/lib/active_ldap/base.rb +195 -186
  80. data/lib/active_ldap/callbacks.rb +33 -0
  81. data/lib/active_ldap/command.rb +3 -3
  82. data/lib/active_ldap/connection.rb +21 -3
  83. data/lib/active_ldap/distinguished_name.rb +18 -11
  84. data/lib/active_ldap/entry_attribute.rb +78 -0
  85. data/lib/active_ldap/human_readable.rb +20 -0
  86. data/lib/active_ldap/ldif.rb +860 -10
  87. data/lib/active_ldap/object_class.rb +6 -4
  88. data/lib/active_ldap/operations.rb +129 -22
  89. data/lib/active_ldap/schema.rb +118 -9
  90. data/lib/active_ldap/schema/syntaxes.rb +33 -16
  91. data/lib/active_ldap/validations.rb +74 -65
  92. data/po/en/active-ldap.po +378 -768
  93. data/po/ja/active-ldap.po +935 -868
  94. data/rails/plugin/active_ldap/init.rb +40 -2
  95. data/test/al-test-utils.rb +78 -58
  96. data/test/command.rb +51 -1
  97. data/test/test-unit-ext/priority.rb +29 -6
  98. data/test/test_adapter.rb +21 -2
  99. data/test/test_attributes.rb +13 -0
  100. data/test/test_base.rb +51 -1
  101. data/test/test_connection.rb +2 -1
  102. data/test/test_connection_per_class.rb +55 -1
  103. data/test/test_connection_per_dn.rb +29 -1
  104. data/test/test_find.rb +73 -0
  105. data/test/test_ldif.rb +1829 -15
  106. data/test/test_load.rb +126 -0
  107. data/test/test_object_class.rb +23 -5
  108. data/test/test_schema.rb +28 -0
  109. data/test/test_syntax.rb +22 -11
  110. data/test/test_user.rb +16 -25
  111. data/test/test_useradd-binary.rb +1 -1
  112. data/test/test_usermod-binary-add-time.rb +1 -1
  113. data/test/test_usermod-binary-add.rb +1 -1
  114. data/test/test_validation.rb +100 -22
  115. metadata +77 -71
  116. data/data/locale/en/LC_MESSAGES/active-ldap.mo +0 -0
  117. data/data/locale/ja/LC_MESSAGES/active-ldap.mo +0 -0
  118. data/examples/al-admin/app/views/layouts/_flash_box.rhtml +0 -4
  119. data/examples/al-admin/public/stylesheets/common.css +0 -2
  120. data/examples/al-admin/script/breakpointer +0 -3
@@ -0,0 +1,126 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestLoad < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ priority :must
7
+ def test_load_modify_record
8
+ ldif = ActiveLdap::LDIF.new
9
+ make_temporary_user do |user, password|
10
+ user.display_name = "Display Name"
11
+ assert(user.save)
12
+
13
+ user = @user_class.find(user.dn)
14
+ assert_equal("Display Name", user.display_name)
15
+
16
+ record = ActiveLdap::LDIF::ModifyRecord.new(user.dn)
17
+ ldif << record
18
+
19
+ original_descriptions = user.description(true)
20
+ new_description = "new description"
21
+ record.add_operation(:add, "description", [],
22
+ {"description" => [new_description]})
23
+
24
+ record.add_operation(:delete, "DisplayName", [], {})
25
+
26
+ original_sn = user.sn
27
+ new_sn = ["New SN1", "New SN2"]
28
+ record.add_operation(:replace, "sn", [], {"sn" => new_sn})
29
+
30
+ ActiveLdap::Base.load(ldif.to_s)
31
+
32
+ user = @user_class.find(user.dn)
33
+ assert_equal(original_descriptions + [new_description],
34
+ user.description(true))
35
+ assert_nil(user.display_name)
36
+ assert_equal(new_sn, user.sn)
37
+ end
38
+ end
39
+
40
+ def test_load_move_dn_record
41
+ assert_load_move_dn_record(ActiveLdap::LDIF::ModifyDNRecord)
42
+ assert_load_move_dn_record(ActiveLdap::LDIF::ModifyRDNRecord)
43
+ end
44
+
45
+ def test_load_copy_dn_record
46
+ assert_load_copy_dn_record(ActiveLdap::LDIF::ModifyDNRecord)
47
+ assert_load_copy_dn_record(ActiveLdap::LDIF::ModifyRDNRecord)
48
+ end
49
+
50
+ def test_load_delete_record
51
+ ldif = ActiveLdap::LDIF.new
52
+ make_temporary_user do |user, password|
53
+ record = ActiveLdap::LDIF::DeleteRecord.new(user.dn)
54
+ ldif << record
55
+ assert_true(@user_class.exists?(user.dn))
56
+ ActiveLdap::Base.load(ldif.to_s)
57
+ assert_false(@user_class.exists?(user.dn))
58
+ end
59
+ end
60
+
61
+ def test_load_add_record
62
+ ldif = ActiveLdap::LDIF.new
63
+ make_temporary_user do |user, password|
64
+ new_description = "new description"
65
+ attributes = {
66
+ "description" => [new_description]
67
+ }
68
+ original_descriptions = user.description(true)
69
+ record = ActiveLdap::LDIF::AddRecord.new(user.dn, [], attributes)
70
+ ldif << record
71
+ ActiveLdap::Base.load(ldif.to_s)
72
+ user.reload
73
+ assert(original_descriptions + [new_description], user.description(true))
74
+ end
75
+ end
76
+
77
+ def test_load_content_records
78
+ ldif = ActiveLdap::LDIF.new
79
+ 2.times do
80
+ make_temporary_user do |user, password|
81
+ ldif << ActiveLdap::LDIF.parse(user.to_ldif).records[0]
82
+ end
83
+ end
84
+
85
+ original_n_users = @user_class.count
86
+ ActiveLdap::Base.load(ldif.to_s)
87
+ assert_equal(2, @user_class.count - original_n_users)
88
+ end
89
+
90
+ priority :normal
91
+
92
+ private
93
+ def assert_load_copy_dn_record(record_class)
94
+ ldif = ActiveLdap::LDIF.new
95
+ make_temporary_user do |user, password|
96
+ new_rdn = "uid=XXX"
97
+ ensure_delete_user(new_rdn) do
98
+ record = record_class.new(user.dn, [], new_rdn, false)
99
+ ldif << record
100
+ assert_true(@user_class.exists?(user.dn))
101
+ assert_false(@user_class.exists?(new_rdn))
102
+ ActiveLdap::Base.load(ldif.to_s)
103
+ assert_true(@user_class.exists?(user.dn))
104
+ assert_true(@user_class.exists?(new_rdn))
105
+ assert_equal(user.cn, @user_class.find(new_rdn).cn)
106
+ end
107
+ end
108
+ end
109
+
110
+ def assert_load_move_dn_record(record_class)
111
+ ldif = ActiveLdap::LDIF.new
112
+ make_temporary_user do |user, password|
113
+ new_rdn = "uid=XXX"
114
+ ensure_delete_user(new_rdn) do
115
+ record = record_class.new(user.dn, [], new_rdn, true)
116
+ ldif << record
117
+ assert_true(@user_class.exists?(user.dn))
118
+ assert_false(@user_class.exists?(new_rdn))
119
+ ActiveLdap::Base.load(ldif.to_s)
120
+ assert_false(@user_class.exists?(user.dn))
121
+ assert_true(@user_class.exists?(new_rdn))
122
+ assert_equal(user.cn, @user_class.find(new_rdn).cn)
123
+ end
124
+ end
125
+ end
126
+ end
@@ -4,15 +4,33 @@ class TestObjectClass < Test::Unit::TestCase
4
4
  include AlTestUtils
5
5
 
6
6
  priority :must
7
+ def test_pass_nil_to_set_classes
8
+ make_temporary_group do |group|
9
+ assert_raises(ActiveLdap::RequiredObjectClassMissed) do
10
+ group.classes = nil
11
+ end
12
+ end
13
+ end
7
14
 
8
15
  priority :normal
16
+ def test_pass_nil_to_replace_class
17
+ make_temporary_group do |group|
18
+ assert_raises(ActiveLdap::RequiredObjectClassMissed) do
19
+ group.replace_class(nil)
20
+ end
21
+ end
22
+ end
23
+
9
24
  def test_case_insensitive_match
10
25
  assert_nothing_raised do
11
- @group_class.instantiate(["cn=test-group,#{@group_class.base}",
12
- {
13
- :cn => "test-group",
14
- :objectClass => ["TOP", "posixgroup"],
15
- }])
26
+ @group_class.send(:instantiate,
27
+ [
28
+ "cn=test-group,#{@group_class.base}",
29
+ {
30
+ :cn => "test-group",
31
+ :objectClass => ["TOP", "posixgroup"],
32
+ }
33
+ ])
16
34
  end
17
35
  end
18
36
 
@@ -2,6 +2,34 @@ require 'al-test-utils'
2
2
 
3
3
  class TestSchema < Test::Unit::TestCase
4
4
  priority :must
5
+ def test_normalize_attribute_value
6
+ entry = {
7
+ "attributeTypes" =>
8
+ [
9
+ "( 0.9.2342.19200300.100.1.25 NAME ( 'dc' 'domainComponent' ) DESC " +
10
+ "'RFC1274/2247: domain component' EQUALITY caseIgnoreIA5Match SUBSTR " +
11
+ "caseIgnoreIA5SubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 " +
12
+ "SINGLE-VALUE )",
13
+ ],
14
+ "ldapSyntaxes" =>
15
+ [
16
+ "( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' " +
17
+ "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
18
+ ],
19
+ }
20
+
21
+ schema = ActiveLdap::Schema.new(entry)
22
+ dc = schema.attribute("dc")
23
+ assert_equal(["com"], dc.normalize_value("com"))
24
+ assert_equal(["com"], dc.normalize_value(["com"]))
25
+ assert_raise(ActiveLdap::AttributeValueInvalid) do
26
+ dc.normalize_value(["com", "co.jp"])
27
+ end
28
+ assert_equal([{"lang-en" => ["com"]},
29
+ {"lang-ja" => ["co.jp"]}],
30
+ dc.normalize_value([{"lang-en" => "com"},
31
+ {"lang-ja" => "co.jp"}]))
32
+ end
5
33
 
6
34
  priority :normal
7
35
  def test_syntax_validation
@@ -84,11 +84,12 @@ class TestSyntax < Test::Unit::TestCase
84
84
 
85
85
  def test_generalized_time_type_cast
86
86
  assert_type_cast_without_validation(nil, nil, "Generalized Time")
87
- assert_type_cast(Time.parse("1994/12/16 10:32"), "199412161032",
87
+ assert_type_cast(Time.parse("1994/12/16 10:32:12"), "19941216103212",
88
88
  "Generalized Time")
89
- assert_type_cast(Time.parse("1994/12/16 10:32Z"), "199412161032Z",
89
+ assert_type_cast(Time.parse("1994/12/16 10:32:12Z"), "19941216103212Z",
90
90
  "Generalized Time")
91
- assert_type_cast(Time.parse("1994/12/16 10:32 +09:00"), "199412161032+0900",
91
+ assert_type_cast(Time.parse("1994/12/16 10:32:12.345 +09:00"),
92
+ "19941216103212.345+0900",
92
93
  "Generalized Time")
93
94
  end
94
95
 
@@ -165,12 +166,18 @@ class TestSyntax < Test::Unit::TestCase
165
166
  end
166
167
 
167
168
  def test_generalized_time_validate
168
- assert_valid("199412161032", "Generalized Time")
169
- assert_valid("199412161032Z", "Generalized Time")
170
- assert_valid("199412161032+0900", "Generalized Time")
169
+ assert_valid("19941216103201", "Generalized Time")
170
+ assert_valid("19941216103212Z", "Generalized Time")
171
+ assert_valid("19941216103230+0900", "Generalized Time")
172
+ assert_valid("20080107034615.0Z", "Generalized Time")
173
+ assert_valid("20080107034615,123-0900", "Generalized Time")
171
174
 
172
175
  value = "1994"
173
- params = [value.inspect, %w(month day hour minute).join(", ")]
176
+ params = [value.inspect, %w(month day hour minute second).join(", ")]
177
+ assert_invalid(_("%s has missing components: %s") % params,
178
+ value, "Generalized Time")
179
+ value = "199412161032"
180
+ params = [value.inspect, %w(second).join(", ")]
174
181
  assert_invalid(_("%s has missing components: %s") % params,
175
182
  value, "Generalized Time")
176
183
  end
@@ -217,7 +224,7 @@ class TestSyntax < Test::Unit::TestCase
217
224
  assert_valid("1.2.3.4", "OID")
218
225
  assert_valid("cn", "OID")
219
226
 
220
- assert_invalid_oid("\#@!")
227
+ assert_invalid_oid("\#@!", "attribute type is missing")
221
228
  end
222
229
 
223
230
  def test_other_mailbox_validate
@@ -304,9 +311,13 @@ class TestSyntax < Test::Unit::TestCase
304
311
  value, "Numeric String")
305
312
  end
306
313
 
307
- def assert_invalid_oid(value)
308
- assert_invalid(_("%s is invalid OID format") % value.inspect,
309
- value, "OID")
314
+ def assert_invalid_oid(value, reason=nil)
315
+ if reason
316
+ message = _("%s is invalid OID format: %s") % [value.inspect, _(reason)]
317
+ else
318
+ message = _("%s is invalid OID format") % value.inspect
319
+ end
320
+ assert_invalid(message, value, "OID")
310
321
  end
311
322
 
312
323
  def assert_type_cast_without_validation(type_casted_value, original_value,
@@ -38,17 +38,15 @@ class TestUser < Test::Unit::TestCase
38
38
  'This should have returned an array of a ' +
39
39
  'normal cn and a lang-en-us cn.')
40
40
 
41
- uid_number = 9000
41
+ uid_number = "9000"
42
42
  user.uid_number = uid_number
43
- # Test to_s on Fixnums
44
- assert_equal(uid_number, user.uid_number)
45
- assert_equal(uid_number.to_s, user.uid_number_before_type_cast)
43
+ assert_equal(uid_number.to_i, user.uid_number)
44
+ assert_equal(uid_number, user.uid_number_before_type_cast)
46
45
 
47
46
  gid_number = 9000
48
47
  user.gid_number = gid_number
49
- # Test to_s on Fixnums
50
48
  assert_equal(gid_number, user.gid_number)
51
- assert_equal(gid_number.to_s, user.gid_number_before_type_cast)
49
+ assert_equal(gid_number, user.gid_number_before_type_cast)
52
50
 
53
51
  home_directory = '/home/foo'
54
52
  user.home_directory = home_directory
@@ -104,42 +102,35 @@ class TestUser < Test::Unit::TestCase
104
102
 
105
103
  # This tests the reload of a binary_required type
106
104
  def test_binary_required
105
+ require 'openssl'
107
106
  make_temporary_user do |user, password|
108
107
  # validate add
109
108
  user.user_certificate = nil
110
- assert_equal({'binary' => nil}, user.user_certificate)
109
+ assert_nil(user.user_certificate)
111
110
  assert_nothing_raised() { user.save! }
112
- assert_equal({'binary' => nil}, user.user_certificate)
111
+ assert_nil(user.user_certificate)
113
112
 
114
113
  user.user_certificate = {"binary" => [certificate]}
115
- assert_equal({'binary' => certificate},
116
- user.user_certificate,
117
- 'This should have been forced to be a binary subtype.')
114
+ assert_equal(certificate, user.user_certificate)
118
115
  assert_nothing_raised() { user.save! }
119
- assert_equal({'binary' => certificate},
120
- user.user_certificate,
121
- 'This should have been forced to be a binary subtype.')
116
+ assert_equal(certificate, user.user_certificate)
122
117
 
123
118
  # now test modify
124
119
  user.user_certificate = nil
125
- assert_equal({"binary" => nil}, user.user_certificate)
120
+ assert_nil(user.user_certificate)
126
121
  assert_nothing_raised() { user.save! }
127
- assert_equal({"binary" => nil}, user.user_certificate)
122
+ assert_nil(user.user_certificate)
128
123
 
129
124
  user.user_certificate = certificate
130
- assert_equal({'binary' => certificate},
131
- user.user_certificate,
132
- 'This should have been forced to be a binary subtype.')
125
+ assert_equal(certificate, user.user_certificate)
133
126
  assert_nothing_raised() { user.save! }
134
127
 
135
128
  # validate modify
136
129
  user = @user_class.find(user.uid)
137
- assert_equal({'binary' => certificate},
138
- user.user_certificate,
139
- 'This should have been forced to be a binary subtype.')
130
+ assert_equal(certificate, user.user_certificate)
140
131
 
141
132
  expected_cert = OpenSSL::X509::Certificate.new(certificate)
142
- actual_cert = user.user_certificate['binary']
133
+ actual_cert = user.user_certificate
143
134
  actual_cert = OpenSSL::X509::Certificate.new(actual_cert)
144
135
  assert_equal(expected_cert.subject.to_s,
145
136
  actual_cert.subject.to_s,
@@ -150,10 +141,10 @@ class TestUser < Test::Unit::TestCase
150
141
  def test_binary_required_nested
151
142
  make_temporary_user do |user, password|
152
143
  user.user_certificate = {"lang-en" => [certificate]}
153
- assert_equal({'lang-en' => {'binary' => certificate}},
144
+ assert_equal({'lang-en' => certificate},
154
145
  user.user_certificate)
155
146
  assert_nothing_raised() { user.save! }
156
- assert_equal({'lang-en' => {'binary' => certificate}},
147
+ assert_equal({'lang-en' => certificate},
157
148
  user.user_certificate)
158
149
  end
159
150
  end
@@ -46,7 +46,7 @@ class TestUseraddBinary < Test::Unit::TestCase
46
46
  assert_equal(['person', 'posixAccount', 'shadowAccount',
47
47
  'strongAuthenticationUser'].sort, user.classes.sort)
48
48
  cert = File.read(File.join(@examples_dir, 'example.der'))
49
- assert_equal({"binary" => cert}, user.user_certificate)
49
+ assert_equal(cert, user.user_certificate)
50
50
  end
51
51
  end
52
52
 
@@ -48,7 +48,7 @@ class TestUsermodBinaryAddTime < Test::Unit::TestCase
48
48
  assert_equal((previous_classes + ['strongAuthenticationUser']).sort,
49
49
  user.classes.sort)
50
50
  cert = File.read(File.join(@examples_dir, 'example.der'))
51
- assert_equal({"binary" => cert}, user.user_certificate)
51
+ assert_equal(cert, user.user_certificate)
52
52
  end
53
53
  end
54
54
 
@@ -48,7 +48,7 @@ class TestUsermodBinaryAdd < Test::Unit::TestCase
48
48
  assert_equal((previous_classes + ['strongAuthenticationUser']).sort,
49
49
  user.classes.sort)
50
50
  cert = File.read(File.join(@examples_dir, 'example.der'))
51
- assert_equal({"binary" => cert}, user.user_certificate)
51
+ assert_equal(cert, user.user_certificate)
52
52
  end
53
53
  end
54
54
 
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'al-test-utils'
2
3
 
3
4
  class TestValidation < Test::Unit::TestCase
@@ -5,6 +6,63 @@ class TestValidation < Test::Unit::TestCase
5
6
  include ActiveLdap::Helper
6
7
 
7
8
  priority :must
9
+ def test_validate_excluded_classes
10
+ make_temporary_user do |user,|
11
+ user.save
12
+ user.classes -= ['person']
13
+ assert(user.save)
14
+ user.class.excluded_classes = ['person']
15
+ assert(!user.save)
16
+ if ActiveLdap.get_text_supported?
17
+ format = n_("%{fn} has excluded value: %s",
18
+ "%{fn} has excluded values: %s",
19
+ 1) % {:fn => la_("objectClass")}
20
+ message = format % loc_("person")
21
+ else
22
+ message = "ObjectClass has excluded value: person"
23
+ end
24
+ assert_equal([message], user.errors.full_messages)
25
+ end
26
+ end
27
+
28
+ priority :normal
29
+ def test_valid_subtype_and_single_value
30
+ make_temporary_user do |user, password|
31
+ user.display_name = [{"lang-ja" => ["ユーザ"]},
32
+ {"lang-en" => "User"}]
33
+ assert(user.save)
34
+
35
+ user = user.class.find(user.dn)
36
+ assert_equal([{"lang-ja" => "ユーザ"}, {"lang-en" => "User"}],
37
+ user.display_name)
38
+ end
39
+ end
40
+
41
+ def test_invalid_subtype_and_single_value
42
+ assert_invalid_display_name_value(["User1", "User2"],
43
+ ["User1", "User2"])
44
+ assert_invalid_display_name_value(["User3", "User4"],
45
+ [{"lang-en" => ["User3", "User4"]}],
46
+ {"lang-en" => ["User3", "User4"]}.inspect)
47
+ assert_invalid_display_name_value(["U2", "U3"],
48
+ [{"lang-ja" => ["User1"]},
49
+ {"lang-en" => ["U2", "U3"]}],
50
+ [{"lang-ja" => "User1"},
51
+ {"lang-en" => ["U2", "U3"]}].inspect)
52
+ end
53
+
54
+ def test_validate_required_ldap_values
55
+ make_temporary_user(:simple => true) do |user, password|
56
+ assert(user.save)
57
+
58
+ user.add_class("strongAuthenticationUser")
59
+ user.user_certificate = nil
60
+ assert(!user.save)
61
+ assert(user.errors.invalid?(:userCertificate))
62
+ assert_equal(1, user.errors.size)
63
+ end
64
+ end
65
+
8
66
  def test_syntax_validation
9
67
  make_temporary_user do |user, password|
10
68
  assert(user.save)
@@ -26,7 +84,6 @@ class TestValidation < Test::Unit::TestCase
26
84
  "lang-ja-jp")
27
85
  end
28
86
 
29
- priority :normal
30
87
  def test_duplicated_dn_creation
31
88
  assert(ou_class.new("YYY").save)
32
89
  ou = ou_class.new("YYY")
@@ -70,6 +127,29 @@ class TestValidation < Test::Unit::TestCase
70
127
  end
71
128
 
72
129
  private
130
+ def assert_invalid_value(name, formatted_value, syntax, reason, model, option)
131
+ syntax_description = lsd_(syntax)
132
+ assert_not_nil(syntax_description)
133
+ params = [formatted_value, syntax_description, reason]
134
+ params.unshift(option) if option
135
+ if ActiveLdap.get_text_supported?
136
+ if option
137
+ format = _("%{fn} (%s) has invalid format: %s: required syntax: %s: %s")
138
+ else
139
+ format = _("%{fn} has invalid format: %s: required syntax: %s: %s")
140
+ end
141
+ format = format % {:fn => la_(name)}
142
+ assert_equal([format % params], model.errors.full_messages)
143
+ else
144
+ if option
145
+ format = _("(%s) has invalid format: %s: required syntax: %s: %s")
146
+ else
147
+ format = _("has invalid format: %s: required syntax: %s: %s")
148
+ end
149
+ assert_equal(["#{name} #{format % params}"], model.errors.full_messages)
150
+ end
151
+ end
152
+
73
153
  def assert_invalid_see_also_value(invalid_value, value, option=nil)
74
154
  make_temporary_user do |user, password|
75
155
  assert(user.save)
@@ -82,29 +162,27 @@ class TestValidation < Test::Unit::TestCase
82
162
  assert(user.errors.invalid?(:seeAlso))
83
163
  assert_equal(1, user.errors.size)
84
164
 
85
- syntax_description = lsd_("1.3.6.1.4.1.1466.115.121.1.12")
86
- assert_not_nil(syntax_description)
87
165
  reason_params = [invalid_value, _("attribute value is missing")]
88
166
  reason = _('%s is invalid distinguished name (DN): %s') % reason_params
89
- params = [invalid_value, syntax_description, reason]
90
- params.unshift(option) if option
91
- if ActiveLdap.get_text_supported?
92
- if option
93
- format =
94
- _("%{fn} (%s) has invalid format: %s: required syntax: %s: %s")
95
- else
96
- format = _("%{fn} has invalid format: %s: required syntax: %s: %s")
97
- end
98
- format = format % {:fn => la_("seeAlso")}
99
- assert_equal([format % params], user.errors.full_messages)
100
- else
101
- if option
102
- format = _("(%s) has invalid format: %s: required syntax: %s: %s")
103
- else
104
- format = _("has invalid format: %s: required syntax: %s: %s")
105
- end
106
- assert_equal(["seeAlso #{format % params}"], user.errors.full_messages)
107
- end
167
+ assert_invalid_value("seeAlso", value.inspect,
168
+ "1.3.6.1.4.1.1466.115.121.1.12",
169
+ reason, user, option)
170
+ end
171
+ end
172
+
173
+ def assert_invalid_display_name_value(invalid_value, value,
174
+ formatted_value=nil)
175
+ make_temporary_user do |user, password|
176
+ assert(user.save)
177
+
178
+ user.display_name = value
179
+ assert(!user.save)
180
+
181
+ reason_params = [la_("displayName"), invalid_value.inspect]
182
+ reason = _('Attribute %s can only have a single value: %s') % reason_params
183
+ assert_invalid_value("displayName", formatted_value || value.inspect,
184
+ "1.3.6.1.4.1.1466.115.121.1.15",
185
+ reason, user, nil)
108
186
  end
109
187
  end
110
188
  end