radum 0.0.1

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.
@@ -0,0 +1,98 @@
1
+ require 'test/unit'
2
+ require 'radum'
3
+
4
+ # This tests the UNIXUser class.
5
+ class TC_UNIXUser < Test::Unit::TestCase
6
+ def setup
7
+ @ad1 = RADUM::AD.new :root => "dc=vmware,dc=local", :password => "test1"
8
+ @ad2 = RADUM::AD.new :root => "dc=vmware,dc=com", :password => "test2"
9
+ @c1_ad1 = RADUM::Container.new :name => "ou=People", :directory => @ad1
10
+ @c2_ad2 = RADUM::Container.new :name => "ou=Staff,ou=People",
11
+ :directory => @ad2
12
+ @ug1_c1_ad1 = RADUM::UNIXGroup.new :name => "staff", :container => @c1_ad1,
13
+ :gid => 1001
14
+ @ug2_c1_ad1 = RADUM::UNIXGroup.new :name => "enable", :container => @c1_ad1,
15
+ :gid => 1002
16
+ @ug3_c2_ad2 = RADUM::UNIXGroup.new :name => "enable", :container => @c2_ad2,
17
+ :gid => 1003
18
+ @g4_c1_ad1 = RADUM::Group.new :name => "class", :container => @c1_ad1
19
+ @uu1a_c1_ad1 = RADUM::UNIXUser.new :username => "user",
20
+ :container => @c1_ad1,
21
+ :primary_group => @g4_c1_ad1,
22
+ :uid => 1000,
23
+ :unix_main_group => @ug1_c1_ad1,
24
+ :shell => "/bin/bash",
25
+ :home_directory => "/home/user"
26
+ end
27
+
28
+ def test_removed_flag_false
29
+ assert(@uu1a_c1_ad1.removed? == false, "Removed flag should be false")
30
+ end
31
+
32
+ def test_duplicate_uid_exception
33
+ assert_raise RuntimeError do
34
+ RADUM::UNIXUser.new :username => "test", :container => @c1_ad1,
35
+ :primary_group => @g4_c1_ad1, :uid => 1000,
36
+ :unix_main_group => @ug1_c1_ad1,
37
+ :shell => "/bin/bash",
38
+ :home_directory => "/home/user"
39
+ end
40
+ end
41
+
42
+ def test_unix_main_group_different_directory_exception
43
+ assert_raise RuntimeError do
44
+ RADUM::UNIXUser.new :username => "test", :container => @c1_ad1,
45
+ :primary_group => @g4_c1_ad1, :uid => 1000,
46
+ :unix_main_group => @ug3_c2_ad2,
47
+ :shell => "/bin/bash",
48
+ :home_directory => "/home/test"
49
+ end
50
+ end
51
+
52
+ def test_unix_main_group_non_unix_exception
53
+ assert_raise RuntimeError do
54
+ RADUM::UNIXUser.new :username => "test", :container => @c1_ad1,
55
+ :primary_group => @g4_c1_ad1, :uid => 1000,
56
+ :unix_main_group => @g4_c1_ad1,
57
+ :shell => "/bin/bash",
58
+ :home_directory => "/home/test"
59
+ end
60
+ end
61
+
62
+ def test_removed_unix_main_group_exception
63
+ assert_raise RuntimeError do
64
+ @ug2_c1_ad1.set_removed
65
+ @uu1a_c1_ad1.unix_main_group = @ug2_c1_ad1
66
+ end
67
+ end
68
+
69
+ def test_add_unix_group_different_directory_exception
70
+ assert_raise RuntimeError do
71
+ @uu1a_c1_ad1.add_group @ug3_c2_ad2
72
+ end
73
+ end
74
+
75
+ def test_add_unix_group_no_exception
76
+ assert_nothing_raised do
77
+ @uu1a_c1_ad1.add_group @ug2_c1_ad1
78
+ end
79
+ end
80
+
81
+ def test_add_group
82
+ assert_block("Should have added exactly one group") do
83
+ # Note that the UNIXUser already added its unix_main_group, so the count
84
+ # should be two (so it should have really added a total of two groups
85
+ # only).
86
+ @uu1a_c1_ad1.add_group @ug2_c1_ad1
87
+ @uu1a_c1_ad1.add_group @ug2_c1_ad1
88
+ @uu1a_c1_ad1.groups.length == 2 &&
89
+ @uu1a_c1_ad1.groups.find { |group| group == @ug2_c1_ad1 }
90
+ end
91
+ end
92
+
93
+ def test_remove_unix_main_group_exception
94
+ assert_raise RuntimeError do
95
+ @uu1a_c1_ad1.remove_group @ug1_c1_ad1
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,175 @@
1
+ require 'test/unit'
2
+ require 'radum'
3
+
4
+ # This tests the User class.
5
+ class TC_User < Test::Unit::TestCase
6
+ def setup
7
+ @type = RADUM::GROUP_DOMAIN_LOCAL_DISTRIBUTION
8
+ @ad1 = RADUM::AD.new :root => "dc=vmware,dc=local", :password => "test1"
9
+ @ad2 = RADUM::AD.new :root => "dc=vmware,dc=com", :password => "test2"
10
+ @c1_ad1 = RADUM::Container.new :name => "ou=People", :directory => @ad1
11
+ @c2_ad1 = RADUM::Container.new :name => "ou=Staff,ou=People",
12
+ :directory => @ad1
13
+ @c3_ad2 = RADUM::Container.new :name => "ou=People", :directory => @ad2
14
+ @g1_c1_ad1 = RADUM::Group.new :name => "staff", :container => @c1_ad1
15
+ @g2_c2_ad1 = RADUM::Group.new :name => "enable", :container => @c2_ad1
16
+ @g3_c3_ad2 = RADUM::Group.new :name => "staff", :container => @c3_ad2
17
+ @g4_c1_ad1 = RADUM::Group.new :name => "primary", :container => @c1_ad1
18
+ @g5_c3_ad2 = RADUM::Group.new :name => "primary", :container => @c3_ad2
19
+ @ug1_c1_ad1 = RADUM::UNIXGroup.new :name => "class", :container => @c1_ad1,
20
+ :gid => 1001
21
+ @ug2_c3_ad2 = RADUM::UNIXGroup.new :name => "class", :container => @c3_ad2,
22
+ :gid => 1001
23
+ @u1_c1_ad1 = RADUM::User.new :username => "user", :container => @c1_ad1,
24
+ :primary_group => @g4_c1_ad1,
25
+ :disabled => false, :rid => 1834
26
+ @u2_c3_ad2 = RADUM::User.new :username => "user", :container => @c3_ad2,
27
+ :primary_group => @g5_c3_ad2,
28
+ :disabled => false, :rid => 1834
29
+ end
30
+
31
+ def test_removed_flag_false
32
+ assert(@u1_c1_ad1.removed? == false, "Removed flag should be false")
33
+ end
34
+
35
+ def test_duplicate_rid_exception
36
+ assert_raise RuntimeError do
37
+ RADUM::User.new :username => "test", :container => @c1_ad1,
38
+ :primary_group => @g4_c1_ad1, :disabled => false,
39
+ :rid => 1834
40
+ end
41
+ end
42
+
43
+ def test_primary_group_type_exception
44
+ assert_raise RuntimeError do
45
+ @u1_c1_ad1.primary_group = RADUM::Group.new :name => "broken",
46
+ :container => @c1_ad1,
47
+ :type => @type
48
+ end
49
+ end
50
+
51
+ def test_removed_primary_group_exception
52
+ assert_raise RuntimeError do
53
+ @g1_c1_ad1.set_removed
54
+ @u1_c1_ad1.primary_group = @g1_c1_ad1
55
+ end
56
+ end
57
+
58
+ def test_equal_exception
59
+ assert_raise RuntimeError do
60
+ RADUM::User.new :username => "user", :container => @c1_ad1,
61
+ :primary_group => @g4_c1_ad1
62
+ end
63
+ end
64
+
65
+ def test_equal_container_difference_exception
66
+ assert_raise RuntimeError do
67
+ RADUM::User.new :username => "user", :container => @c2_ad1,
68
+ :primary_group => @g4_c1_ad1
69
+ end
70
+ end
71
+
72
+ def test_equal_name_case_exception
73
+ assert_raise RuntimeError do
74
+ RADUM::User.new :username => "User", :container => @c1_ad1,
75
+ :primary_group => @g4_c1_ad1
76
+ end
77
+ end
78
+
79
+ def test_not_equal_ad
80
+ assert(@u1_c1_ad1 != @u2_c3_ad2, "Should not be equal")
81
+ end
82
+
83
+ def test_add_unix_group_no_exception
84
+ assert_nothing_raised do
85
+ @u1_c1_ad1.add_group @ug1_c1_ad1
86
+ end
87
+ end
88
+
89
+ def test_add_unix_group_different_directory_exception
90
+ assert_raise RuntimeError do
91
+ @u1_c1_ad1.add_group @ug2_c3_ad2
92
+ end
93
+ end
94
+
95
+ def test_group_add_different_directory_exception
96
+ assert_raise RuntimeError do
97
+ @u1_c1_ad1.add_group @g3_c3_ad2
98
+ end
99
+ end
100
+
101
+ def test_add_group_no_exception
102
+ assert_nothing_raised do
103
+ @u1_c1_ad1.add_group @g1_c1_ad1
104
+ end
105
+ end
106
+
107
+ def test_add_primary_group_exception
108
+ assert_raise RuntimeError do
109
+ @u1_c1_ad1.add_group @g4_c1_ad1
110
+ end
111
+ end
112
+
113
+ def test_modify_distiguished_name_loaded_exception
114
+ assert_raise RuntimeError do
115
+ @u1_c1_ad1.set_loaded
116
+ @u1_c1_ad1.distinguished_name = "cn=error,ou=crazy,dc=fool,dc=com"
117
+ end
118
+ end
119
+
120
+ def test_change_primary_group_add_old_group
121
+ assert_block("Should have added user to old primary group on change") do
122
+ # The primary group is currently @g4_c1_ad1. Changing it below should
123
+ # automatically add the user to the @g4_c1_ad1 group (which the user is
124
+ # not a member of currently).
125
+ @u1_c1_ad1.primary_group = @g1_c1_ad1
126
+ @u1_c1_ad1.groups.find { |group| group == @g4_c1_ad1 }
127
+ end
128
+ end
129
+
130
+ def test_add_group
131
+ assert_block("Should have added exactly two groups") do
132
+ @u1_c1_ad1.add_group @g1_c1_ad1
133
+ @u1_c1_ad1.add_group @g2_c2_ad1
134
+ @u1_c1_ad1.add_group @g2_c2_ad1
135
+ @u1_c1_ad1.groups.length == 2 &&
136
+ @u1_c1_ad1.groups.find { |group| group == @g1_c1_ad1 } &&
137
+ @u1_c1_ad1.groups.find { |group| group == @g2_c2_ad1 }
138
+ end
139
+ end
140
+
141
+ def test_user_added_to_container
142
+ assert_block("User should have been automatically added to container") do
143
+ @c1_ad1.users.find do |user|
144
+ user == @u1_c1_ad1
145
+ end
146
+ end
147
+ end
148
+
149
+ def test_add_group_user_added_to_group
150
+ assert_block("Group should have user when added to user") do
151
+ @u1_c1_ad1.add_group @g1_c1_ad1
152
+ @g1_c1_ad1.users.find do |user|
153
+ user == @u1_c1_ad1
154
+ end
155
+ end
156
+ end
157
+
158
+ def test_remove_group_user_removed_from_group
159
+ assert_block("Group should have removed user when removed from user") do
160
+ @u1_c1_ad1.add_group @g1_c1_ad1
161
+ @u1_c1_ad1.remove_group @g1_c1_ad1
162
+ ! @g1_c1_ad1.users.find do |user|
163
+ user == @u1_c1_ad1
164
+ end
165
+ end
166
+ end
167
+
168
+ def test_member_of
169
+ assert_block("User should be member of the single group") do
170
+ @u1_c1_ad1.add_group @g1_c1_ad1
171
+ (@u1_c1_ad1.member_of? @g1_c1_ad1) &&
172
+ ! (@u1_c1_ad1.member_of? @g2_c2_ad1)
173
+ end
174
+ end
175
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radum
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Shaun Rowland
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-02 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ruby-net-ldap
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.4
24
+ version:
25
+ description: " RADUM is a module to manage users and groups in Active Directory uisng pure\n Ruby on any supported platform.\n"
26
+ email:
27
+ - rowland@shaunrowland.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - LICENSE
34
+ files:
35
+ - lib/radum/ad.rb
36
+ - lib/radum/container.rb
37
+ - lib/radum/group.rb
38
+ - lib/radum/logger.rb
39
+ - lib/radum/user.rb
40
+ - lib/radum.rb
41
+ - LICENSE
42
+ has_rdoc: true
43
+ homepage: http://www.shaunrowland.com/wiki/RADUM
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --exclude
49
+ - test
50
+ - --exclude
51
+ - demo*
52
+ - --exclude
53
+ - radum-gemspec.rb
54
+ - --exclude
55
+ - lib/radum.rb
56
+ - --main
57
+ - RADUM
58
+ - --accessor
59
+ - directory
60
+ - --title
61
+ - RADUM -- Ruby Active Directory User Management
62
+ - --line-numbers
63
+ - --inline-source
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ requirements: []
80
+
81
+ rubyforge_project: radum
82
+ rubygems_version: 1.3.5
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Manage users and groups in Active Directory.
86
+ test_files:
87
+ - test/tc_ad.rb
88
+ - test/tc_container.rb
89
+ - test/tc_group.rb
90
+ - test/tc_unix_user.rb
91
+ - test/tc_user.rb