File: test_groupls.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 (107 lines) | stat: -rw-r--r-- 3,199 bytes parent folder | download | duplicates (6)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
require 'al-test-utils'

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

  def setup
    super
    @command = File.join(@examples_dir, "groupls")
    make_ou("People")
    @user_class.prefix = "ou=People"
  end

  priority :must

  priority :normal
  def test_non_exist_group
    ensure_delete_group("test-group") do |name|
      assert(!@group_class.exists?(name))
      assert_equal([false, "Group #{name} doesn't exist.\n"], run_command(name))
      assert(!@group_class.exists?(name))
    end
  end

  def test_list_group_no_group
    make_temporary_group do |group|
      assert_groupls_successfully(group.id, [])
    end
  end

  def test_list_group_have_primary_members
    make_temporary_group do |group|
      make_temporary_user(:gid_number => group.gid_number) do |user1,|
        make_temporary_user(:gid_number => group.gid_number) do |user2,|
          assert_groupls_successfully(group.id, [user1, user2])
        end
      end
    end
  end

  def test_list_group_have_members
    make_temporary_user do |user1,|
      make_temporary_user do |user2,|
        make_temporary_group do |group|
          group.members << user1
          group.members << user2
          assert_groupls_successfully(group.id, [user1, user2])
        end
      end
    end
  end

  def test_list_group_have_members_and_primary_members
    make_temporary_group do |group|
      options = {:gid_number => group.gid_number}
      make_temporary_user(options) do |primary_user1,|
        make_temporary_user(options) do |primary_user2,|
          options1 = {:gid_number => group.gid_number.succ}
          options2 = {:gid_number => group.gid_number.succ.succ}
          make_temporary_user(options1) do |user1,|
            make_temporary_user(options2) do |user2,|
              group.members << user1
              group.members << user2
              assert_groupls_successfully(group.id,
                                          [primary_user1, primary_user2,
                                           user1, user2])
            end
          end
        end
      end
    end
  end

  def test_list_group_have_non_exist_member
    make_temporary_group do |group|
      options = {:gid_number => group.gid_number.succ}
      make_temporary_user(options) do |user,|
        group.member_uid = [user.id]
        assert(group.save)
        assert_groupls_successfully(group.id, [user])
      end
    end
  end

  private
  def assert_groupls_successfully(name, members, *args, &block)
    _wrap_assertion do
      assert(@group_class.exists?(name))
      args.concat([name])
      group = @group_class.find(name)
      members = members.collect do |m|
        "#{m.uid}[#{m.new_entry? ? '????' : m.uid_number}]"
      end
      result = "#{group.cn}(#{group.gid_number}): #{members.join(', ')}\n"
      assert_equal([true, result], run_command(*args, &block))
      assert(@group_class.exists?(name))
    end
  end

  def assert_groupls_failed(name, message, *args, &block)
    _wrap_assertion do
      assert(@group_class.exists?(name))
      args.concat([name])
      assert_equal([false, message], run_command(*args, &block))
      assert(@group_class.exists?(name))
    end
  end
end