activeldap 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. data/CHANGES +34 -0
  2. data/README +13 -0
  3. data/Rakefile +2 -1
  4. data/TODO +6 -0
  5. data/benchmark/bench-al.rb +68 -17
  6. data/examples/al-admin/app/helpers/application_helper.rb +3 -5
  7. data/examples/al-admin/app/views/layouts/_footer.html.erb +2 -0
  8. data/examples/al-admin/config/boot.rb +7 -7
  9. data/examples/al-admin/config/environment.rb +27 -12
  10. data/examples/al-admin/config/environments/development.rb +0 -1
  11. data/examples/al-admin/config/environments/production.rb +6 -1
  12. data/examples/al-admin/config/environments/test.rb +1 -1
  13. data/examples/al-admin/config/initializers/gettext.rb +15 -1
  14. data/examples/al-admin/po/en/al-admin.po +1 -1
  15. data/examples/al-admin/po/ja/al-admin.po +1 -1
  16. data/examples/al-admin/po/nl/al-admin.po +1 -1
  17. data/examples/al-admin/public/dispatch.cgi +0 -0
  18. data/examples/al-admin/public/dispatch.fcgi +0 -0
  19. data/examples/al-admin/public/dispatch.rb +0 -0
  20. data/examples/al-admin/public/javascripts/controls.js +73 -73
  21. data/examples/al-admin/public/javascripts/dragdrop.js +166 -165
  22. data/examples/al-admin/public/javascripts/effects.js +174 -166
  23. data/examples/al-admin/public/javascripts/prototype.js +362 -267
  24. data/examples/al-admin/script/about +0 -0
  25. data/examples/al-admin/script/console +0 -0
  26. data/examples/al-admin/script/dbconsole +3 -0
  27. data/examples/al-admin/script/destroy +0 -0
  28. data/examples/al-admin/script/generate +0 -0
  29. data/examples/al-admin/script/performance/benchmarker +0 -0
  30. data/examples/al-admin/script/performance/profiler +0 -0
  31. data/examples/al-admin/script/performance/request +0 -0
  32. data/examples/al-admin/script/plugin +0 -0
  33. data/examples/al-admin/script/process/inspector +0 -0
  34. data/examples/al-admin/script/process/reaper +0 -0
  35. data/examples/al-admin/script/process/spawner +0 -0
  36. data/examples/al-admin/script/runner +0 -0
  37. data/examples/al-admin/script/server +0 -0
  38. data/examples/al-admin/test/run-test.sh +0 -0
  39. data/examples/groupadd +0 -0
  40. data/examples/groupdel +0 -0
  41. data/examples/groupls +0 -0
  42. data/examples/groupmod +0 -0
  43. data/examples/lpasswd +0 -0
  44. data/examples/ouadd +0 -0
  45. data/examples/useradd +0 -0
  46. data/examples/useradd-binary +0 -0
  47. data/examples/userdel +0 -0
  48. data/examples/userls +0 -0
  49. data/examples/usermod +0 -0
  50. data/examples/usermod-binary-add +0 -0
  51. data/examples/usermod-binary-add-time +0 -0
  52. data/examples/usermod-binary-del +0 -0
  53. data/examples/usermod-lang-add +0 -0
  54. data/lib/active_ldap.rb +10 -4
  55. data/lib/active_ldap/action_controller/ldap_benchmarking.rb +28 -9
  56. data/lib/active_ldap/adapter/base.rb +30 -17
  57. data/lib/active_ldap/adapter/jndi.rb +5 -1
  58. data/lib/active_ldap/adapter/ldap.rb +5 -1
  59. data/lib/active_ldap/association/has_many_utils.rb +7 -1
  60. data/lib/active_ldap/associations.rb +10 -5
  61. data/lib/active_ldap/attributes.rb +6 -1
  62. data/lib/active_ldap/base.rb +154 -52
  63. data/lib/active_ldap/configuration.rb +1 -1
  64. data/lib/active_ldap/connection.rb +7 -4
  65. data/lib/active_ldap/get_text.rb +11 -3
  66. data/lib/active_ldap/ldif.rb +16 -4
  67. data/lib/active_ldap/operations.rb +13 -5
  68. data/lib/active_ldap/schema.rb +6 -2
  69. data/lib/active_ldap/schema/syntaxes.rb +15 -3
  70. data/lib/active_ldap/user_password.rb +4 -4
  71. data/lib/active_ldap/validations.rb +32 -44
  72. data/lib/active_ldap/xml.rb +125 -0
  73. data/po/en/active-ldap.po +740 -85
  74. data/po/ja/active-ldap.po +748 -547
  75. data/rails/README +54 -0
  76. data/rails/init.rb +33 -0
  77. data/rails/plugin/active_ldap/generators/README +2 -0
  78. data/rails/plugin/active_ldap/generators/model_active_ldap/model_active_ldap_generator.rb +1 -1
  79. data/rails/plugin/active_ldap/init.rb +3 -0
  80. data/rails_generators/model_active_ldap/USAGE +17 -0
  81. data/rails_generators/model_active_ldap/model_active_ldap_generator.rb +69 -0
  82. data/rails_generators/model_active_ldap/templates/model_active_ldap.rb +3 -0
  83. data/rails_generators/model_active_ldap/templates/unit_test.rb +8 -0
  84. data/rails_generators/scaffold_active_ldap/scaffold_active_ldap_generator.rb +7 -0
  85. data/rails_generators/scaffold_active_ldap/templates/ldap.yml +18 -0
  86. data/rails_generators/scaffold_al/scaffold_al_generator.rb +20 -0
  87. data/test-unit/History.txt +50 -1
  88. data/test-unit/Manifest.txt +22 -12
  89. data/test-unit/README.txt +31 -12
  90. data/test-unit/Rakefile +14 -1
  91. data/test-unit/TODO +5 -0
  92. data/test-unit/bin/testrb +0 -0
  93. data/test-unit/lib/test/unit.rb +62 -0
  94. data/test-unit/lib/test/unit/assertions.rb +419 -75
  95. data/test-unit/lib/test/unit/autorunner.rb +70 -13
  96. data/test-unit/lib/test/unit/collector.rb +1 -1
  97. data/test-unit/lib/test/unit/collector/load.rb +1 -1
  98. data/test-unit/lib/test/unit/color-scheme.rb +86 -0
  99. data/test-unit/lib/test/unit/color.rb +40 -5
  100. data/test-unit/lib/test/unit/diff.rb +14 -0
  101. data/test-unit/lib/test/unit/fixture.rb +7 -16
  102. data/test-unit/lib/test/unit/notification.rb +9 -0
  103. data/test-unit/lib/test/unit/omission.rb +14 -0
  104. data/test-unit/lib/test/unit/pending.rb +16 -0
  105. data/test-unit/lib/test/unit/priority.rb +17 -2
  106. data/test-unit/lib/test/unit/runner/console.rb +8 -2
  107. data/test-unit/lib/test/unit/testcase.rb +188 -2
  108. data/test-unit/lib/test/unit/ui/console/testrunner.rb +51 -26
  109. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  110. data/test-unit/lib/test/unit/version.rb +1 -1
  111. data/test-unit/sample/test_user.rb +22 -0
  112. data/test-unit/test/collector/{test_descendant.rb → test-descendant.rb} +0 -0
  113. data/test-unit/test/collector/{test_load.rb → test-load.rb} +1 -1
  114. data/test-unit/test/run-test.rb +0 -0
  115. data/test-unit/test/{test_attribute.rb → test-attribute.rb} +0 -0
  116. data/test-unit/test/test-color-scheme.rb +56 -0
  117. data/test-unit/test/{test_color.rb → test-color.rb} +10 -0
  118. data/test-unit/test/{test_diff.rb → test-diff.rb} +0 -0
  119. data/test-unit/test/{test_emacs_runner.rb → test-emacs-runner.rb} +0 -0
  120. data/test-unit/test/test-fixture.rb +287 -0
  121. data/test-unit/test/{test_notification.rb → test-notification.rb} +4 -4
  122. data/test-unit/test/{test_omission.rb → test-omission.rb} +6 -6
  123. data/test-unit/test/{test_pending.rb → test-pending.rb} +12 -6
  124. data/test-unit/test/{test_priority.rb → test-priority.rb} +30 -0
  125. data/test-unit/test/test_assertions.rb +411 -69
  126. data/test-unit/test/test_testcase.rb +70 -3
  127. data/test-unit/test/{testunit_test_util.rb → testunit-test-util.rb} +4 -2
  128. data/test-unit/test/ui/test_testrunmediator.rb +1 -1
  129. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  130. data/test/run-test.rb +0 -0
  131. data/test/test_adapter.rb +3 -0
  132. data/test/test_associations.rb +50 -7
  133. data/test/test_base.rb +193 -11
  134. data/test/test_connection_per_dn.rb +1 -1
  135. data/test/test_ldif.rb +86 -0
  136. data/test/test_load.rb +7 -0
  137. data/test/test_schema.rb +31 -1
  138. data/test/test_syntax.rb +20 -0
  139. data/test/test_user_password.rb +22 -14
  140. data/test/test_validation.rb +70 -29
  141. metadata +99 -77
  142. data/data/locale/en/LC_MESSAGES/active-ldap.mo +0 -0
  143. data/data/locale/ja/LC_MESSAGES/active-ldap.mo +0 -0
  144. data/examples/al-admin/config/initializers/ralative_url_support.rb +0 -1
  145. data/examples/al-admin/lib/accept_http_rails_relative_url_root.rb +0 -9
  146. data/test-unit-ext/misc/rd2html.rb +0 -42
  147. data/test-unit/test/test_fixture.rb +0 -275
@@ -267,7 +267,7 @@ module Test
267
267
  def test_re_raise_exception
268
268
  test_case = Class.new(TestCase) do
269
269
  def test_raise_interrupt
270
- raise Interrupt
270
+ raise Interrupt, "from test"
271
271
  end
272
272
  end
273
273
 
@@ -342,7 +342,7 @@ module Test
342
342
  test_case = Class.new(TestCase) do
343
343
  class << self
344
344
  def startup
345
- raise Interrupt
345
+ raise Interrupt, "from startup"
346
346
  end
347
347
  end
348
348
 
@@ -383,7 +383,7 @@ module Test
383
383
  test_case = Class.new(TestCase) do
384
384
  class << self
385
385
  def shutdown
386
- raise Interrupt
386
+ raise Interrupt, "from shutdown"
387
387
  end
388
388
  end
389
389
 
@@ -401,6 +401,73 @@ module Test
401
401
  end
402
402
  end
403
403
 
404
+ def test_interrupted
405
+ test_case = Class.new(TestCase) do
406
+ def test_fail
407
+ flunk
408
+ end
409
+
410
+ def test_nothing
411
+ end
412
+ end
413
+
414
+ failed_test = test_case.new(:test_fail)
415
+ failed_test.run(TestResult.new) {}
416
+ check("Should be interrupted", failed_test.interrupted?)
417
+
418
+ success_test = test_case.new(:test_nothing)
419
+ success_test.run(TestResult.new) {}
420
+ check("Should not be interrupted", !success_test.interrupted?)
421
+ end
422
+
423
+ def test_inherited_test_should_be_ignored
424
+ test_case = Class.new(TestCase) do
425
+ def test_nothing
426
+ end
427
+ end
428
+
429
+ sub_test_case = Class.new(test_case) do
430
+ def test_fail
431
+ flunk
432
+ end
433
+ end
434
+
435
+ assert_nothing_thrown do
436
+ test_case.new("test_nothing")
437
+ end
438
+
439
+ assert_nothing_thrown do
440
+ sub_test_case.new("test_fail")
441
+ end
442
+
443
+ assert_throw(:invalid_test) do
444
+ sub_test_case.new("test_nothing")
445
+ end
446
+ end
447
+
448
+ def test_mixin_test_should_not_be_ignored
449
+ test_module = Module.new do
450
+ def test_nothing
451
+ end
452
+ end
453
+
454
+ test_case = Class.new(Test::Unit::TestCase) do
455
+ include test_module
456
+
457
+ def test_fail
458
+ flunk
459
+ end
460
+ end
461
+
462
+ assert_nothing_thrown do
463
+ test_case.new("test_nothing")
464
+ end
465
+
466
+ assert_nothing_thrown do
467
+ test_case.new("test_fail")
468
+ end
469
+ end
470
+
404
471
  private
405
472
  def check(message, passed)
406
473
  add_assertion
@@ -4,9 +4,11 @@ module TestUnitTestUtil
4
4
  assert_equal(expected, faults.collect {|fault| fault.message})
5
5
  end
6
6
 
7
- def run_test(test_case, name)
7
+ def _run_test(test_case, name)
8
8
  result = Test::Unit::TestResult.new
9
- test_case.new(name).run(result) {}
9
+ test = test_case.new(name)
10
+ yield(test) if block_given?
11
+ test.run(result) {}
10
12
  result
11
13
  end
12
14
  end
@@ -4,7 +4,7 @@ class TestUnitUIMediator < Test::Unit::TestCase
4
4
  def test_run_suite_with_interrupt_exception
5
5
  test_case = Class.new(Test::Unit::TestCase) do
6
6
  def test_raise_interrupt
7
- raise Interrupt
7
+ raise Interrupt, "from test"
8
8
  end
9
9
  end
10
10
  mediator = Test::Unit::UI::TestRunnerMediator.new(test_case.suite)
@@ -0,0 +1,38 @@
1
+ require 'test/unit'
2
+
3
+ require 'test/unit/util/method-owner-finder'
4
+
5
+ class TestUnitMethodOwnerFinder < Test::Unit::TestCase
6
+ def test_find
7
+ assert_equal(Exception, find(RuntimeError.new, :inspect))
8
+ assert_equal(Exception, find(Exception.new, :inspect))
9
+
10
+ anonymous_class = Class.new do
11
+ end
12
+ assert_equal(Kernel, find(anonymous_class.new, :inspect))
13
+
14
+ anonymous_parent_class = Class.new do
15
+ def inspect
16
+ super + " by anonymous parent class"
17
+ end
18
+ end
19
+ anonymous_sub_class = Class.new(anonymous_parent_class) do
20
+ end
21
+ assert_equal(anonymous_parent_class, find(anonymous_sub_class.new, :inspect))
22
+
23
+ anonymous_module = Module.new do
24
+ def inspect
25
+ super + " by anonymous module"
26
+ end
27
+ end
28
+ anonymous_include_class = Class.new do
29
+ include anonymous_module
30
+ end
31
+ assert_equal(anonymous_module, find(anonymous_include_class.new, :inspect))
32
+ end
33
+
34
+ private
35
+ def find(object, method_name)
36
+ Test::Unit::Util::MethodOwnerFinder.find(object, method_name)
37
+ end
38
+ end
File without changes
@@ -11,7 +11,10 @@ class TestAdapter < Test::Unit::TestCase
11
11
 
12
12
  priority :must
13
13
  def test_operator
14
+ assert_parse_filter("(uid=Alice)", ["uid", "=", "Alice"])
14
15
  assert_parse_filter("(uid~=Alice)", ["uid", "~=", "Alice"])
16
+ assert_parse_filter("(uidNumber>=1000)", ["uidNumber", ">=", "1000"])
17
+ assert_parse_filter("(uidNumber<=1000)", ["uidNumber", "<=", "1000"])
15
18
  assert_parse_filter("(&(uid~=Alice)(uid~=Bob))",
16
19
  ["uid", "~=", "Alice", "Bob"])
17
20
  assert_parse_filter("(uid~=Alice)", [["uid", "~=", "Alice"]])
@@ -4,6 +4,47 @@ class TestAssociations < Test::Unit::TestCase
4
4
  include AlTestUtils
5
5
 
6
6
  priority :must
7
+ def test_belongs_to_with_invalid_dn_attribute_value
8
+ make_temporary_user do |user,|
9
+ make_temporary_group do |group|
10
+ user.primary_group = group
11
+ user.uid = "#"
12
+ assert_nothing_raised do
13
+ user.primary_group.reload
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ priority :normal
20
+ def test_has_many_wrap_with_nonexistent_entry
21
+ @user_class.has_many :references, :wrap => "seeAlso", :primary_key => "dn"
22
+ @user_class.set_associated_class(:references, @group_class)
23
+ @group_class.belongs_to :related_users, :many => "seeAlso",
24
+ :foreign_key => "dn"
25
+ @group_class.set_associated_class(:related_users, @user_class)
26
+ make_temporary_user do |user,|
27
+ make_temporary_group do |group1|
28
+ make_temporary_group do |group2|
29
+ user.references = [group1, group2]
30
+ group3_dn = group2.dn.sub(/cn=(.*?),/, "cn=\\1-nonexistent,")
31
+ user.see_also += [group3_dn]
32
+ user.save!
33
+
34
+ user = @user_class.find(user.dn)
35
+ assert_equal([group1.dn, group2.dn, group3_dn],
36
+ user.see_also.collect(&:to_s))
37
+ assert_equal([group1.dn, group2.dn, group3_dn],
38
+ user.references.collect(&:dn))
39
+ assert_equal([group1.gid_number, group2.gid_number, nil],
40
+ user.references.collect(&:gid_number))
41
+ assert_equal([false, false, true],
42
+ user.references.collect(&:new_entry?))
43
+ end
44
+ end
45
+ end
46
+ end
47
+
7
48
  def test_has_many_wrap_with_dn_value
8
49
  @user_class.has_many :references, :wrap => "seeAlso", :primary_key => "dn"
9
50
  @user_class.set_associated_class(:references, @group_class)
@@ -42,7 +83,6 @@ class TestAssociations < Test::Unit::TestCase
42
83
  end
43
84
  end
44
85
 
45
- priority :normal
46
86
  def test_belongs_to_many_with_dn_value
47
87
  @user_class.has_many :references, :wrap => "seeAlso", :primary_key => "dn"
48
88
  @user_class.set_associated_class(:references, @group_class)
@@ -243,14 +283,15 @@ class TestAssociations < Test::Unit::TestCase
243
283
  :scope => :sub,
244
284
  :classes => ["posixGroup"]
245
285
  assert_raises(ArgumentError) do
246
- group_class.has_many :members, :class_name => "User"
286
+ group_class.has_many :users, :unknown_name => "value"
247
287
  end
248
288
 
249
289
  mod = Module.new
250
290
  assert_nothing_raised do
251
- group_class.has_many :members, :class => "User", :wrap => "memberUid",
291
+ group_class.has_many :users, :class_name => "User"
292
+ group_class.has_many :members, :class => @user_class, :wrap => "memberUid",
252
293
  :extend => mod
253
- group_class.has_many :primary_members, :class => "User",
294
+ group_class.has_many :primary_members, :class => @user_class,
254
295
  :foreign_key => "gidNumber",
255
296
  :primary_key => "gidNumber",
256
297
  :extend => mod
@@ -264,14 +305,16 @@ class TestAssociations < Test::Unit::TestCase
264
305
  :scope => :sub,
265
306
  :classes => ["posixAccount", "person"]
266
307
  assert_raises(ArgumentError) do
267
- user_class.belongs_to :groups, :class_name => "Group"
308
+ user_class.belongs_to :groups, :unknown_name => "value"
268
309
  end
269
310
 
270
311
  mod = Module.new
271
312
  assert_nothing_raised do
272
- user_class.belongs_to :groups, :class => "Group", :many => "memberUid",
313
+ user_class.belongs_to :string_groups, :class_name => "Group"
314
+ user_class.belongs_to :groups, :class => @group_class,
315
+ :many => "memberUid",
273
316
  :extend => mod
274
- user_class.belongs_to :primary_group, :class => "Group",
317
+ user_class.belongs_to :primary_group, :class => @group_class,
275
318
  :foreign_key => "gidNumber",
276
319
  :primary_key => "gidNumber",
277
320
  :extend => mod
@@ -6,6 +6,81 @@ class TestBase < Test::Unit::TestCase
6
6
  include AlTestUtils
7
7
 
8
8
  priority :must
9
+ def test_create_invalid
10
+ user = @user_class.create
11
+ assert_not_predicate(user.errors, :empty?)
12
+ end
13
+
14
+ priority :normal
15
+ def test_id_with_invalid_dn_attribute_value
16
+ user = @user_class.new("#")
17
+ assert_equal("#", user.uid)
18
+ assert_equal("#", user.id)
19
+ end
20
+
21
+ def test_non_string_dn_attribute_value
22
+ user = @user_class.new("uidNumber=10110")
23
+ user.uid = user.cn = user.sn = "test-user"
24
+ user.gid_number = 10000
25
+ user.home_directory = "/home/test-user"
26
+ assert_nothing_raised do
27
+ user.save!
28
+ end
29
+ end
30
+
31
+ def test_set_dn_with_unnormalized_dn_attribute
32
+ make_temporary_user do |user,|
33
+ assert_not_equal("ZZZ", user.cn)
34
+ user.dn = "CN=ZZZ"
35
+ assert_equal("ZZZ", user.cn)
36
+ end
37
+ end
38
+
39
+ def test_destroy_with_empty_base_of_class
40
+ make_temporary_user do |user,|
41
+ base = user.class.base
42
+ begin
43
+ user.class.base = ""
44
+ user.prefix = ""
45
+ user.base = base
46
+ user.destroy
47
+ ensure
48
+ user.class.base = base
49
+ end
50
+ end
51
+ end
52
+
53
+ def test_empty_base_of_class
54
+ make_temporary_user do |user,|
55
+ user.class.prefix = ""
56
+ user.class.base = ""
57
+ user.base = "dc=net"
58
+ assert_equal("dc=net", user.base)
59
+ end
60
+ end
61
+
62
+ def test_search_value_with_no_dn_attribute
63
+ make_temporary_user do |user1,|
64
+ make_temporary_user do |user2,|
65
+ options = {:attribute => "seeAlso", :value => user2.dn}
66
+ assert_equal([],
67
+ user1.class.find(:all, options).collect(&:dn))
68
+
69
+ user1.see_also = user2.dn
70
+ user1.save!
71
+
72
+ assert_equal([user1.dn],
73
+ user1.class.find(:all, options).collect(&:dn))
74
+ end
75
+ end
76
+ end
77
+
78
+ def test_to_s
79
+ make_temporary_group do |group,|
80
+ assert_equal(group.to_s, group.to_ldif)
81
+ end
82
+ end
83
+
9
84
  def test_to_ldif
10
85
  make_temporary_group do |group,|
11
86
  assert_to_ldif(group)
@@ -16,7 +91,6 @@ class TestBase < Test::Unit::TestCase
16
91
  end
17
92
  end
18
93
 
19
- priority :normal
20
94
  def test_save_with_changes
21
95
  make_temporary_user do |user, password|
22
96
  user.cn += "!!!"
@@ -528,38 +602,142 @@ class TestBase < Test::Unit::TestCase
528
602
  assert_equal(<<-EOX, ou.to_xml(:root => "ou"))
529
603
  <ou>
530
604
  <dn>#{ou.dn}</dn>
531
- <objectClass>organizationalUnit</objectClass>
532
- <objectClass>top</objectClass>
533
- <ou>Sample</ou>
605
+ <objectClasses type="array">
606
+ <objectClass>organizationalUnit</objectClass>
607
+ <objectClass>top</objectClass>
608
+ </objectClasses>
609
+ <ous type="array">
610
+ <ou>Sample</ou>
611
+ </ous>
534
612
  </ou>
535
613
  EOX
536
614
 
537
615
  assert_equal(<<-EOX, ou.to_xml)
538
616
  <>
539
617
  <dn>#{ou.dn}</dn>
540
- <objectClass>organizationalUnit</objectClass>
541
- <objectClass>top</objectClass>
542
- <ou>Sample</ou>
618
+ <objectClasses type="array">
619
+ <objectClass>organizationalUnit</objectClass>
620
+ <objectClass>top</objectClass>
621
+ </objectClasses>
622
+ <ous type="array">
623
+ <ou>Sample</ou>
624
+ </ous>
543
625
  </>
544
626
  EOX
545
627
 
546
628
  make_temporary_user do |user, password|
547
- assert_equal(<<-EOX, user.to_xml(:root => "user"))
629
+ assert_equal(<<-EOX, user.to_xml(:root => "user"))
630
+ <user>
631
+ <dn>#{user.dn}</dn>
632
+ <cns type="array">
633
+ <cn>#{user.cn}</cn>
634
+ </cns>
635
+ <gidNumber>#{user.gid_number}</gidNumber>
636
+ <homeDirectory>#{user.home_directory}</homeDirectory>
637
+ <jpegPhotos type="array">
638
+ <jpegPhoto base64="true">#{base64(jpeg_photo)}</jpegPhoto>
639
+ </jpegPhotos>
640
+ <objectClasses type="array">
641
+ <objectClass>inetOrgPerson</objectClass>
642
+ <objectClass>organizationalPerson</objectClass>
643
+ <objectClass>person</objectClass>
644
+ <objectClass>posixAccount</objectClass>
645
+ <objectClass>shadowAccount</objectClass>
646
+ </objectClasses>
647
+ <sns type="array">
648
+ <sn>#{user.sn}</sn>
649
+ </sns>
650
+ <uids type="array">
651
+ <uid>#{user.uid}</uid>
652
+ </uids>
653
+ <uidNumber>#{user.uid_number}</uidNumber>
654
+ <userCertificates type="array">
655
+ <userCertificate binary="true" base64="true">#{base64(certificate)}</userCertificate>
656
+ </userCertificates>
657
+ <userPasswords type="array">
658
+ <userPassword>#{user.user_password}</userPassword>
659
+ </userPasswords>
660
+ </user>
661
+ EOX
662
+ end
663
+ end
664
+
665
+ def test_to_xml_except
666
+ ou = ou_class.new("Sample")
667
+ assert_equal(<<-EOX, ou.to_xml(:root => "sample", :except => [:objectClass]))
668
+ <sample>
669
+ <dn>#{ou.dn}</dn>
670
+ <ous type="array">
671
+ <ou>Sample</ou>
672
+ </ous>
673
+ </sample>
674
+ EOX
675
+
676
+ except = [:dn, :object_class]
677
+ assert_equal(<<-EOX, ou.to_xml(:root => "sample", :except => except))
678
+ <sample>
679
+ <ous type="array">
680
+ <ou>Sample</ou>
681
+ </ous>
682
+ </sample>
683
+ EOX
684
+ end
685
+
686
+ def test_to_xml_escape
687
+ make_temporary_user do |user, password|
688
+ sn = user.sn
689
+ user.sn = "<#{sn}>"
690
+ except = [:jpeg_photo, :user_certificate]
691
+ assert_equal(<<-EOX, user.to_xml(:root => "user", :except => except))
692
+ <user>
693
+ <dn>#{user.dn}</dn>
694
+ <cns type="array">
695
+ <cn>#{user.cn}</cn>
696
+ </cns>
697
+ <gidNumber>#{user.gid_number}</gidNumber>
698
+ <homeDirectory>#{user.home_directory}</homeDirectory>
699
+ <objectClasses type="array">
700
+ <objectClass>inetOrgPerson</objectClass>
701
+ <objectClass>organizationalPerson</objectClass>
702
+ <objectClass>person</objectClass>
703
+ <objectClass>posixAccount</objectClass>
704
+ <objectClass>shadowAccount</objectClass>
705
+ </objectClasses>
706
+ <sns type="array">
707
+ <sn>&lt;#{sn}&gt;</sn>
708
+ </sns>
709
+ <uids type="array">
710
+ <uid>#{user.uid}</uid>
711
+ </uids>
712
+ <uidNumber>#{user.uid_number}</uidNumber>
713
+ <userPasswords type="array">
714
+ <userPassword>#{user.user_password}</userPassword>
715
+ </userPasswords>
716
+ </user>
717
+ EOX
718
+ end
719
+ end
720
+
721
+ def test_to_xml_type_ldif
722
+ make_temporary_user do |user, password|
723
+ sn = user.sn
724
+ user.sn = "<#{sn}>"
725
+ except = [:jpeg_photo, :user_certificate]
726
+ options = {:root => "user", :except => except, :type => :ldif}
727
+ assert_equal(<<-EOX, user.to_xml(options))
548
728
  <user>
549
729
  <dn>#{user.dn}</dn>
550
730
  <cn>#{user.cn}</cn>
551
731
  <gidNumber>#{user.gid_number}</gidNumber>
552
732
  <homeDirectory>#{user.home_directory}</homeDirectory>
553
- <jpegPhoto>#{jpeg_photo}</jpegPhoto>
554
733
  <objectClass>inetOrgPerson</objectClass>
555
734
  <objectClass>organizationalPerson</objectClass>
556
735
  <objectClass>person</objectClass>
557
736
  <objectClass>posixAccount</objectClass>
558
737
  <objectClass>shadowAccount</objectClass>
559
- <sn>#{user.sn}</sn>
738
+ <sn>&lt;#{sn}&gt;</sn>
560
739
  <uid>#{user.uid}</uid>
561
740
  <uidNumber>#{user.uid_number}</uidNumber>
562
- <userCertificate binary="true">#{certificate}</userCertificate>
563
741
  <userPassword>#{user.user_password}</userPassword>
564
742
  </user>
565
743
  EOX
@@ -680,4 +858,8 @@ EOX
680
858
  end
681
859
  assert_equal([entry], parsed_entries)
682
860
  end
861
+
862
+ def base64(string)
863
+ [string].pack("m").gsub(/\n/u, "")
864
+ end
683
865
  end