File: test_object_class.rb

package info (click to toggle)
ruby-activeldap 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,588 kB
  • sloc: ruby: 18,143; sh: 12; makefile: 5
file content (93 lines) | stat: -rw-r--r-- 2,635 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
require 'al-test-utils'

class TestObjectClass < Test::Unit::TestCase
  include AlTestUtils

  priority :must
  def test_pass_nil_to_set_classes
    make_temporary_group do |group|
      assert_raises(ActiveLdap::RequiredObjectClassMissed) do
        group.classes = nil
      end
    end
  end

  priority :normal
  def test_pass_nil_to_replace_class
    make_temporary_group do |group|
      assert_raises(ActiveLdap::RequiredObjectClassMissed) do
        group.replace_class(nil)
      end
    end
  end

  def test_case_insensitive_match
    assert_nothing_raised do
      @group_class.send(:instantiate,
                        [
                         "cn=test-group,#{@group_class.base}",
                         {
                           :cn => "test-group",
                           :objectClass => ["TOP", "posixgroup"],
                         }
                        ])
    end
  end

  def test_ensure_recommended_classes
    make_temporary_group do |group|
      added_class = "labeledURIObject"

      assert_equal([], group.class.recommended_classes)
      group.class.recommended_classes += [added_class]
      assert_equal([added_class], group.class.recommended_classes)

      assert_equal([added_class],
                   group.class.recommended_classes - group.classes)
      group.ensure_recommended_classes
      assert_equal([],
                   group.class.recommended_classes - group.classes)
    end
  end

  def test_unknown_object_class
    make_temporary_group do |group|
      assert_raises(ActiveLdap::ObjectClassError) do
        group.add_class("unknownObjectClass")
      end
    end
  end

  def test_remove_required_class
    make_temporary_group do |group|
      assert_raises(ActiveLdap::RequiredObjectClassMissed) do
        group.remove_class("posixGroup")
      end
    end
  end

  def test_invalid_object_class_value
    make_temporary_group do |group|
      assert_raises(TypeError) {group.add_class(:posixAccount)}
    end
  end

  class TestRemoveClass < self
    def test_clear_existing_attributes
      make_temporary_user(:simple => true) do |user, password|
        user.add_class("inetOrgPerson")
        user.given_name = "new given name"

        original_attributes = user.attributes
        user.remove_class("inetOrgPerson")
        new_attributes = user.attributes
        original_attributes.delete("objectClass")
        removed_attributes = original_attributes.reject do |key, value|
          value == new_attributes[key]
        end
        assert_equal({"givenName" => "new given name"},
                     removed_attributes)
      end
    end
  end
end