sys-admin 1.4.4-x86-mswin32-60 → 1.5.0-x86-mswin32-60

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.
data/sys-admin.gemspec CHANGED
@@ -2,14 +2,14 @@ require 'rubygems'
2
2
 
3
3
  spec = Gem::Specification.new do |gem|
4
4
  gem.name = 'sys-admin'
5
- gem.version = '1.4.4'
5
+ gem.version = '1.5.0'
6
6
  gem.author = 'Daniel J. Berger'
7
7
  gem.email = 'djberg96@gmail.com'
8
8
  gem.homepage = 'http://www.rubyforge.org/projects/sysutils'
9
9
  gem.platform = Gem::Platform::RUBY
10
- gem.summary = 'A unified, cross platform replacement for the "etc" package.'
11
- gem.description = 'A unified, cross platform replacement for the "etc" package.'
12
- gem.test_file = 'test/tc_admin.rb'
10
+ gem.summary = 'A unified, cross platform replacement for the "etc" library.'
11
+ gem.description = 'A unified, cross platform replacement for the "etc" library.'
12
+ gem.test_file = 'test/test_sys_admin.rb'
13
13
  gem.has_rdoc = true
14
14
  gem.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
15
15
  gem.rubyforge_project = 'sysutils'
@@ -1,14 +1,21 @@
1
1
  ###############################################################################
2
- # tc_admin.rb
2
+ # test_sys_admin.rb
3
3
  #
4
4
  # This exists mostly for the sake of the gemspec, so that it calls the right
5
5
  # test suite based on the platform.
6
6
  ###############################################################################
7
- $LOAD_PATH.unshift Dir.pwd
8
- $LOAD_PATH.unshift File.join(Dir.pwd, 'test')
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+ require 'test/unit'
9
10
 
10
11
  if File::ALT_SEPARATOR
11
- require 'tc_windows'
12
+ require 'test_sys_admin_windows'
12
13
  else
13
- require 'tc_unix'
14
+ require 'test_sys_admin_unix'
15
+ end
16
+
17
+ class TC_Sys_Admin_All < Test::Unit::TestCase
18
+ def test_version
19
+ assert_equal('1.5.0', Sys::Admin::VERSION)
20
+ end
14
21
  end
@@ -0,0 +1,246 @@
1
+ ###############################################################################
2
+ # test_sys_admin_unix.rb
3
+ #
4
+ # Test suite for the Unix version of sys-admin. This test should be run
5
+ # via the 'rake test' task.
6
+ ###############################################################################
7
+ require 'test/unit'
8
+ require 'sys/admin'
9
+ include Sys
10
+
11
+ class TC_Sys_Admin_Unix < Test::Unit::TestCase
12
+ def setup
13
+ @user = 'nobody'
14
+ @user_id = 0
15
+
16
+ @group = 'sys'
17
+ @group_id = 3
18
+ end
19
+
20
+ ## Admin singleton methods
21
+
22
+ def test_get_login
23
+ assert_respond_to(Admin, :get_login)
24
+ assert_nothing_raised{ Admin.get_login }
25
+ assert_kind_of(String, Admin.get_login)
26
+ end
27
+
28
+ def test_get_user_basic
29
+ assert_respond_to(Admin, :get_user)
30
+ assert_nothing_raised{ Admin.get_user(@user) }
31
+ assert_nothing_raised{ Admin.get_user(@user_id) }
32
+ end
33
+
34
+ def test_get_user_by_name
35
+ assert_kind_of(User, Admin.get_user(@user))
36
+ end
37
+
38
+ def test_get_user_by_id
39
+ assert_kind_of(User, Admin.get_user(@user_id))
40
+ end
41
+
42
+ def test_get_user_expected_errors
43
+ assert_raise(ArgumentError){ Admin.get_user }
44
+ assert_raise(TypeError){ Admin.get_user([]) }
45
+ assert_raise(Admin::Error){ Admin.get_user('foofoofoo') }
46
+ end
47
+
48
+ def test_users_basic
49
+ assert_respond_to(Admin, :users)
50
+ assert_nothing_raised{ Admin.users }
51
+ end
52
+
53
+ def test_users
54
+ assert_kind_of(Array, Admin.users)
55
+ assert_kind_of(User, Admin.users.first)
56
+ end
57
+
58
+ def test_users_block_form
59
+ array = []
60
+ assert_nothing_raised{ Admin.users{ |g| array << g } }
61
+ assert_equal(true, Admin.users.length == array.length)
62
+ assert_nothing_raised{ Admin.users{ |g| break } }
63
+ end
64
+
65
+ def test_users_expected_errors
66
+ assert_raise(ArgumentError){ Admin.users(@user_id) }
67
+ end
68
+
69
+ def test_get_group_basic
70
+ assert_respond_to(Admin, :get_group)
71
+ assert_nothing_raised{ Admin.get_group(@group) }
72
+ assert_nothing_raised{ Admin.get_group(@group_id) }
73
+ end
74
+
75
+ def test_get_group_by_name
76
+ assert_kind_of(Group, Admin.get_group(@group))
77
+ end
78
+
79
+ def test_get_group_by_id
80
+ assert_kind_of(Group, Admin.get_group(@group_id))
81
+ end
82
+
83
+ def test_get_group_expected_errors
84
+ assert_raise(ArgumentError){ Admin.get_group }
85
+ assert_raise(TypeError){ Admin.get_group([]) }
86
+ assert_raise(Admin::Error){ Admin.get_group('foofoofoo') }
87
+ end
88
+
89
+ def test_groups_basic
90
+ assert_respond_to(Admin, :groups)
91
+ assert_nothing_raised{ Admin.groups }
92
+ end
93
+
94
+ def test_groups
95
+ assert_kind_of(Array, Admin.groups)
96
+ assert_kind_of(Group, Admin.groups.first)
97
+ end
98
+
99
+ def test_groups_expected_errors
100
+ assert_raise(ArgumentError){ Admin.groups(@group_id) }
101
+ end
102
+
103
+ def test_groups_block_form
104
+ array = []
105
+ assert_nothing_raised{ Admin.groups{ |g| array << g } }
106
+ assert_equal(true, Admin.groups.length == array.length)
107
+ assert_nothing_raised{ Admin.groups{ |g| break } }
108
+ end
109
+
110
+ ## User Tests
111
+
112
+ def test_user_name
113
+ @user = Admin.users.first
114
+ assert_respond_to(@user, :name)
115
+ assert_kind_of(String, @user.name)
116
+ end
117
+
118
+ def test_user_passwd
119
+ @user = Admin.users.first
120
+ assert_respond_to(@user, :passwd)
121
+ assert_kind_of(String, @user.passwd)
122
+ end
123
+
124
+ def test_user_uid
125
+ @user = Admin.users.first
126
+ assert_respond_to(@user, :uid)
127
+ assert_kind_of(Fixnum, @user.uid)
128
+ end
129
+
130
+ def test_user_gid
131
+ @user = Admin.users.first
132
+ assert_respond_to(@user, :gid)
133
+ assert_kind_of(Fixnum, @user.gid)
134
+ end
135
+
136
+ def test_user_dir
137
+ @user = Admin.users.first
138
+ assert_respond_to(@user, :dir)
139
+ assert_kind_of(String, @user.dir)
140
+ end
141
+
142
+ def test_user_shell
143
+ @user = Admin.users.first
144
+ assert_respond_to(@user, :shell)
145
+ assert_kind_of(String, @user.shell)
146
+ end
147
+
148
+ def test_user_gecos
149
+ @user = Admin.users.first
150
+ assert_respond_to(@user, :gecos)
151
+ assert_kind_of(String, @user.gecos)
152
+ end
153
+
154
+ def test_user_quota
155
+ @user = Admin.users.first
156
+ assert_respond_to(@user, :quota)
157
+ assert_true([Fixnum, NilClass].include?(@user.quota.class))
158
+ end
159
+
160
+ def test_user_age
161
+ @user = Admin.users.first
162
+ assert_respond_to(@user, :age)
163
+ assert_true([Fixnum, NilClass].include?(@user.age.class))
164
+ end
165
+
166
+ def test_user_access_class
167
+ @user = Admin.users.first
168
+ assert_respond_to(@user, :access_class)
169
+ assert_true([String, NilClass].include?(@user.access_class.class))
170
+ end
171
+
172
+ def test_user_comment
173
+ @user = Admin.users.first
174
+ assert_respond_to(@user, :comment)
175
+ assert_true([String, NilClass].include?(@user.comment.class))
176
+ end
177
+
178
+ def test_user_expire
179
+ @user = Admin.users.first
180
+ assert_respond_to(@user, :expire)
181
+ assert_true([Time, NilClass].include?(@user.expire.class))
182
+ end
183
+
184
+ def test_user_change
185
+ @user = Admin.users.first
186
+ assert_respond_to(@user, :change)
187
+ assert_true([Time, NilClass].include?(@user.change.class))
188
+ end
189
+
190
+ def test_user_login_time
191
+ @user = Admin.users.first
192
+ assert_respond_to(@user, :login_time)
193
+ assert_true([Time, NilClass].include?(@user.login_time.class))
194
+ end
195
+
196
+ def test_user_login_device
197
+ @user = Admin.users.first
198
+ assert_respond_to(@user, :login_device)
199
+ assert_true([String, NilClass].include?(@user.login_device.class))
200
+ end
201
+
202
+ def test_user_login_host
203
+ @user = Admin.users.first
204
+ assert_respond_to(@user, :login_host)
205
+ assert_true([String, NilClass].include?(@user.login_host.class))
206
+ end
207
+
208
+ def test_user_groups
209
+ @user = Admin.users.first
210
+ assert_respond_to(@user, :groups)
211
+ assert_kind_of(Array, @user.groups)
212
+ end
213
+
214
+ ## Group Tests
215
+
216
+ def test_group_name
217
+ @group = Admin.groups.first
218
+ assert_respond_to(@group, :name)
219
+ assert_kind_of(String, @group.name)
220
+ end
221
+
222
+ def test_group_gid
223
+ @group = Admin.groups.first
224
+ assert_respond_to(@group, :gid)
225
+ assert_kind_of(Fixnum, @group.gid)
226
+ end
227
+
228
+ def test_group_members
229
+ @group = Admin.groups.first
230
+ assert_respond_to(@group, :members)
231
+ assert_kind_of(Array, @group.members)
232
+ end
233
+
234
+ def test_group_passwd
235
+ @group = Admin.groups.first
236
+ assert_respond_to(@group, :passwd)
237
+ assert_kind_of(String, @group.passwd)
238
+ end
239
+
240
+ def teardown
241
+ @user = nil
242
+ @user_id = nil
243
+ @group = nil
244
+ @group_id = nil
245
+ end
246
+ end
@@ -1,5 +1,5 @@
1
1
  ###############################################################################
2
- # tc_windows.rb
2
+ # test_sys_admin_windows.rb
3
3
  #
4
4
  # Test suite for the Win32 version of sys-admin. Note that some of the tests
5
5
  # are numbered to ensure a certain order. That way I can add test users
@@ -22,120 +22,159 @@ class TC_Sys_Admin_Win32 < Test::Unit::TestCase
22
22
 
23
23
  def setup
24
24
  @user = User.new
25
- @user_name = 'guest'
25
+ @user_name = 'Guest'
26
26
  @user_id = 501 # best guess, may fail
27
27
  @group = Group.new
28
- @group_name = 'guests'
28
+ @group_name = 'Guests'
29
29
  @group_id = 546 # best guess, may fail
30
30
  end
31
31
 
32
- def test_version
33
- assert_equal('1.4.4', Admin::VERSION)
34
- end
35
-
36
- def test_01_add_local_user
37
- assert_respond_to(Admin, :add_local_user)
38
- assert_nothing_raised{ Admin.add_local_user('foo') }
39
- end
40
-
41
- def test_add_global_user
42
- assert_respond_to(Admin, :add_global_user)
43
- end
44
-
45
- def test_02_config_local_user
46
- assert_respond_to(Admin, :config_local_user)
32
+ # Admin singleton methods
33
+
34
+ def test_01_add_user
35
+ assert_respond_to(Admin, :add_user)
47
36
  assert_nothing_raised{
48
- Admin.config_local_user("foo", {
49
- :description => "delete me",
50
- :fullname => "fubar"
51
- })
37
+ Admin.add_user(:name => 'foo', :password => 'a1b2c3D4')
52
38
  }
53
39
  end
54
-
55
- def test_config_global_user
56
- assert_respond_to(Admin, :config_global_user)
57
- end
58
-
59
- def test_03_delete_local_user
60
- assert_respond_to(Admin, :delete_local_user)
61
- assert_nothing_raised{ Admin.delete_local_user("foo") }
62
- end
63
-
64
- def test_delete_global_user
65
- assert_respond_to(Admin, :delete_global_user)
40
+
41
+ def test_02_config_user
42
+ assert_respond_to(Admin, :configure_user)
43
+ assert_nothing_raised{
44
+ Admin.configure_user(
45
+ :name => 'foo',
46
+ :description => 'delete me',
47
+ :fullname => 'fubar',
48
+ :password => ['a1b2c3D4', 'd1c2b3A4']
49
+ )
50
+ }
66
51
  end
67
52
 
68
- def test_01_add_local_group
69
- assert_respond_to(Admin, :add_local_group)
70
- assert_nothing_raised{ Admin.add_local_group("bar") }
53
+ def test_03_delete_user
54
+ assert_respond_to(Admin, :delete_user)
55
+ assert_nothing_raised{ Admin.delete_user('foo') }
71
56
  end
72
-
73
- def test_add_global_group
74
- assert_respond_to(Admin, :add_global_group)
57
+
58
+ def test_01_add_group
59
+ assert_respond_to(Admin, :add_group)
60
+ assert_nothing_raised{ Admin.add_group(:name => 'bar') }
75
61
  end
76
62
 
77
- def test_02_config_local_group
78
- assert_respond_to(Admin, :config_local_group)
63
+ def test_02_configure_group
64
+ assert_respond_to(Admin, :configure_group)
79
65
  assert_nothing_raised{
80
- Admin.config_local_group('bar', {:description => 'delete me'})
66
+ Admin.configure_group(:name => 'bar', :description => 'delete me')
81
67
  }
82
68
  end
83
69
 
84
- def test_config_global_group
85
- assert_respond_to(Admin, :config_global_group)
86
- end
87
-
88
- def test_03_delete_local_group
89
- assert_respond_to(Admin, :delete_local_group)
90
- assert_nothing_raised{ Admin.delete_local_group("bar") }
70
+ def test_03_delete_group
71
+ assert_respond_to(Admin, :delete_group)
72
+ assert_nothing_raised{ Admin.delete_group('bar') }
91
73
  end
92
74
 
93
- def test_delete_global_group
94
- assert_respond_to(Admin, :delete_global_group)
75
+ def test_get_login_basic
76
+ assert_respond_to(Admin, :get_login)
77
+ assert_nothing_raised{ Admin.get_login }
95
78
  end
96
79
 
97
80
  def test_get_login
98
- assert_respond_to(Admin, :get_login)
99
- assert_nothing_raised{ Admin.get_login }
100
81
  assert_kind_of(String, Admin.get_login)
101
82
  end
83
+
84
+ def test_get_login_expected_errors
85
+ assert_raise(ArgumentError){ Admin.get_login('foo') }
86
+ end
102
87
 
103
- def test_get_user
88
+ def test_get_user_basic
104
89
  assert_respond_to(Admin, :get_user)
105
- assert_raises(ArgumentError){ Admin.get_user }
106
90
  end
107
91
 
108
- def test_get_user_local
109
- assert_nothing_raised{ Admin.get_user(@user_name) }
110
- assert_nothing_raised{ Admin.get_user(@user_id) }
111
- assert_kind_of(User, Admin.get_user(@user_name))
112
- assert_kind_of(User, Admin.get_user(@user_id))
92
+ def test_get_user_by_string
93
+ assert_nothing_raised{ Admin.get_user(@user_name, :localaccount => true) }
94
+ assert_kind_of(User, Admin.get_user(@user_name, :localaccount => true))
95
+ end
96
+
97
+ def test_get_user_by_uid
98
+ assert_nothing_raised{ Admin.get_user(@user_id, :localaccount => true) }
99
+ assert_kind_of(User, Admin.get_user(@user_id, :localaccount => true))
113
100
  end
114
101
 
115
- def test_get_user_remote
116
- assert_nothing_raised{ Admin.get_user(@user_name, @@host) }
117
- assert_nothing_raised{ Admin.get_user(@user_id, @@host) }
118
- assert_kind_of(User, Admin.get_user(@user_name, @@host))
119
- assert_kind_of(User, Admin.get_user(@user_id, @@host))
102
+ def test_get_user_by_string_with_options
103
+ options = {:host => @@host, :localaccount => true}
104
+ assert_nothing_raised{ Admin.get_user(@user_name, options) }
105
+ assert_kind_of(User, Admin.get_user(@user_name, options))
106
+ end
107
+
108
+ def test_get_user_by_uid_with_options
109
+ options = {:host => @@host, :localaccount => true}
110
+ assert_nothing_raised{ Admin.get_user(@user_id, options) }
111
+ assert_kind_of(User, Admin.get_user(@user_id, options))
112
+ end
113
+
114
+ def test_get_user_expected_errors
115
+ assert_raises(ArgumentError){ Admin.get_user }
120
116
  end
121
117
 
122
- def test_users
118
+ def test_users_basic
123
119
  assert_respond_to(Admin, :users)
120
+ assert_nothing_raised{ Admin.users(:localaccount => true) }
124
121
  end
125
122
 
126
- def test_users_local
127
- assert_nothing_raised{ Admin.users }
128
- assert_nothing_raised{ Admin.users{ |u| } }
129
- assert_nothing_raised{ Admin.users(nil) }
130
- assert_nothing_raised{ Admin.users(nil){ |u| } }
131
- assert_kind_of(Array, Admin.users)
132
- assert_kind_of(User, Admin.users.first)
123
+ def test_users
124
+ assert_kind_of(Array, Admin.users(:localaccount => true))
125
+ assert_kind_of(User, Admin.users(:localaccount => true).first)
126
+ end
127
+
128
+ def test_users_with_block
129
+ array = []
130
+ assert_nothing_raised{
131
+ Admin.users(:localaccount => true){ |u| array << u }
132
+ }
133
+ assert_kind_of(User, array[0])
134
+ end
135
+
136
+ def test_get_group_basic
137
+ assert_respond_to(Admin, :get_group)
138
+ end
139
+
140
+ def test_get_group_by_name
141
+ assert_nothing_raised{ Admin.get_group(@group_name, :localaccount => true) }
142
+ assert_kind_of(Group, Admin.get_group(@group_name, :localaccount => true))
143
+ end
144
+
145
+ def test_get_group_by_gid
146
+ assert_nothing_raised{ Admin.get_group(@group_id, :localaccount => true) }
147
+ assert_kind_of(Group, Admin.get_group(@group_id, :localaccount => true))
133
148
  end
134
149
 
135
- def test_users_remote
136
- assert_nothing_raised{ Admin.users(@@host) }
137
- assert_nothing_raised{ Admin.users(@@host){ |u| } }
150
+ def test_get_group_with_options
151
+ assert_nothing_raised{ Admin.get_group(@group_name, :localaccount => true) }
152
+ assert_kind_of(Group, Admin.get_group(@group_name, :localaccount => true))
153
+ end
154
+
155
+ def test_get_group_expected_errors
156
+ assert_raise(ArgumentError){ Admin.get_group }
157
+ end
158
+
159
+ def test_groups_basic
160
+ assert_respond_to(Admin, :groups)
161
+ assert_nothing_raised{ Admin.groups(:localaccount => true) }
162
+ end
163
+
164
+ def test_groups
165
+ assert_kind_of(Array, Admin.groups(:localaccount => true))
166
+ assert_kind_of(Group, Admin.groups(:localaccount => true).first)
167
+ end
168
+
169
+ def test_groups_with_block
170
+ array = []
171
+ assert_nothing_raised{
172
+ Admin.groups(:localaccount => true){ |g| array << g }
173
+ }
174
+ assert_kind_of(Group, array[0])
138
175
  end
176
+
177
+ # User class
139
178
 
140
179
  def test_user_instance_caption
141
180
  assert_respond_to(@user, :caption)
@@ -217,40 +256,7 @@ class TC_Sys_Admin_Win32 < Test::Unit::TestCase
217
256
  assert_respond_to(@user, :uid=)
218
257
  end
219
258
 
220
- def test_get_group
221
- assert_respond_to(Admin, :get_group)
222
- assert_raises(ArgumentError){ Admin.get_group }
223
- end
224
-
225
- def test_get_group_local
226
- assert_nothing_raised{ Admin.get_group(@group_name) }
227
- assert_kind_of(Group, Admin.get_group(@group_name))
228
- assert_nothing_raised{ Admin.get_group(@group_id) }
229
- assert_kind_of(Group, Admin.get_group(@group_id))
230
- end
231
-
232
- def test_get_group_remote
233
- assert_nothing_raised{ Admin.get_group(@group_name, @@host) }
234
- assert_kind_of(Group, Admin.get_group(@group_name, @@host))
235
- end
236
-
237
- def test_groups
238
- assert_respond_to(Admin, :groups)
239
- end
240
-
241
- def test_groups_local
242
- assert_nothing_raised{ Admin.groups }
243
- assert_nothing_raised{ Admin.groups{ |g| } }
244
- assert_kind_of(Array, Admin.groups)
245
- assert_kind_of(Group, Admin.groups.first)
246
- end
247
-
248
- def test_groups_remote
249
- assert_nothing_raised{ Admin.groups(@@host) }
250
- assert_nothing_raised{ Admin.groups(@@host){ |g| } }
251
- assert_kind_of(Array, Admin.groups(@@host))
252
- assert_kind_of(Group, Admin.groups(@@host).first)
253
- end
259
+ # Group class
254
260
 
255
261
  def test_group_instance_caption
256
262
  assert_respond_to(@group, :caption)