sys-admin 1.7.0 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,337 +1,337 @@
1
- ###############################################################################
2
- # test_sys_admin_windows.rb
3
- #
4
- # Test suite for the Win32 version of sys-admin. Note that some of the tests
5
- # are numbered to ensure a certain order. That way I can add test users
6
- # before configuring or deleting them.
7
- #
8
- # It is assumed that this test will be run via the 'rake test' task.
9
- ###############################################################################
10
- require 'test-unit'
11
- require 'sys/admin'
12
- require 'win32/security'
13
- require 'socket'
14
- include Sys
15
-
16
- class TC_Sys_Admin_Win32 < Test::Unit::TestCase
17
- def self.startup
18
- @@host = Socket.gethostname
19
- @@elevated = Win32::Security.elevated_security?
20
- end
21
-
22
- def setup
23
- @user = User.new
24
- @user_name = 'Guest'
25
- @user_id = 501 # best guess, may fail
26
- @group = Group.new
27
- @group_name = 'Guests'
28
- @group_id = 546 # best guess, may fail
29
- end
30
-
31
- # Admin singleton methods
32
-
33
- def test_01_add_user
34
- omit_unless(@@elevated)
35
- assert_respond_to(Admin, :add_user)
36
- assert_nothing_raised{
37
- Admin.add_user(:name => 'foo', :password => 'a1b2c3D4')
38
- }
39
- end
40
-
41
- def test_02_config_user
42
- omit_unless(@@elevated)
43
- assert_respond_to(Admin, :configure_user)
44
- assert_nothing_raised{
45
- Admin.configure_user(
46
- :name => 'foo',
47
- :description => 'delete me',
48
- :fullname => 'fubar',
49
- :password => 'd1c2b3A4'
50
- )
51
- }
52
- end
53
-
54
- def test_06_delete_user
55
- omit_unless(@@elevated)
56
- assert_respond_to(Admin, :delete_user)
57
- assert_nothing_raised{ Admin.delete_user('foo') }
58
- end
59
-
60
- def test_01_add_group
61
- omit_unless(@@elevated)
62
- assert_respond_to(Admin, :add_group)
63
- assert_nothing_raised{ Admin.add_group(:name => 'bar') }
64
- end
65
-
66
- def test_02_configure_group
67
- omit_unless(@@elevated)
68
- assert_respond_to(Admin, :configure_group)
69
- assert_nothing_raised{
70
- Admin.configure_group(:name => 'bar', :description => 'delete me')
71
- }
72
- end
73
-
74
- def test_03_add_group_member
75
- omit_unless(@@elevated)
76
- assert_respond_to(Admin, :add_group_member)
77
- assert_nothing_raised{ Admin.add_group_member('foo', 'bar') }
78
- end
79
-
80
- def test_04_remove_group_member
81
- omit_unless(@@elevated)
82
- assert_respond_to(Admin, :remove_group_member)
83
- assert_nothing_raised{ Admin.remove_group_member('foo', 'bar') }
84
- end
85
-
86
- def test_05_delete_group
87
- omit_unless(@@elevated)
88
- assert_respond_to(Admin, :delete_group)
89
- assert_nothing_raised{ Admin.delete_group('bar') }
90
- end
91
-
92
- test "get_login basic functionality" do
93
- assert_respond_to(Admin, :get_login)
94
- assert_nothing_raised{ Admin.get_login }
95
- end
96
-
97
- test "get_login returns a string" do
98
- assert_kind_of(String, Admin.get_login)
99
- assert_true(Admin.get_login.size > 0)
100
- end
101
-
102
- test "get_login does not accept any arguments" do
103
- assert_raise(ArgumentError){ Admin.get_login('foo') }
104
- end
105
-
106
- test "get_user basic functionality" do
107
- assert_respond_to(Admin, :get_user)
108
- end
109
-
110
- test "get_user with string argument works as expected" do
111
- assert_nothing_raised{ Admin.get_user(@user_name, :localaccount => true) }
112
- assert_kind_of(User, Admin.get_user(@user_name, :localaccount => true))
113
- end
114
-
115
- test "get user with integer argument works as expected" do
116
- assert_nothing_raised{ Admin.get_user(@user_id, :localaccount => true) }
117
- assert_kind_of(User, Admin.get_user(@user_id, :localaccount => true))
118
- end
119
-
120
- test "get_user method by string accepts a hash of options" do
121
- options = {:host => @@host, :localaccount => true}
122
- assert_nothing_raised{ Admin.get_user(@user_name, options) }
123
- assert_kind_of(User, Admin.get_user(@user_name, options))
124
- end
125
-
126
- test "get_user method by uid accepts a hash of options" do
127
- options = {:host => @@host, :localaccount => true}
128
- assert_nothing_raised{ Admin.get_user(@user_id, options) }
129
- assert_kind_of(User, Admin.get_user(@user_id, options))
130
- end
131
-
132
- test "get_user method requires an argument" do
133
- assert_raises(ArgumentError){ Admin.get_user }
134
- end
135
-
136
- test "users method basic functionality" do
137
- assert_respond_to(Admin, :users)
138
- assert_nothing_raised{ Admin.users(:localaccount => true) }
139
- end
140
-
141
- test "users method returns an array of User objects" do
142
- assert_kind_of(Array, Admin.users(:localaccount => true))
143
- assert_kind_of(User, Admin.users(:localaccount => true).first)
144
- end
145
-
146
- test "get_group basic functionality" do
147
- assert_respond_to(Admin, :get_group)
148
- end
149
-
150
- test "get_group method returns expected results with a string argument" do
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
- test "get_group method returns expected results with an integer argument" do
156
- assert_nothing_raised{ Admin.get_group(@group_id, :localaccount => true) }
157
- assert_kind_of(Group, Admin.get_group(@group_id, :localaccount => true))
158
- end
159
-
160
- # TODO: Update
161
- test "get_group method accepts a hash of options" do
162
- assert_nothing_raised{ Admin.get_group(@group_name, :localaccount => true) }
163
- assert_kind_of(Group, Admin.get_group(@group_name, :localaccount => true))
164
- end
165
-
166
- test "get_group method requires an argument" do
167
- assert_raise(ArgumentError){ Admin.get_group }
168
- end
169
-
170
- test "get_groups method basic functionality" do
171
- assert_respond_to(Admin, :groups)
172
- assert_nothing_raised{ Admin.groups(:localaccount => true) }
173
- end
174
-
175
- test "get_groups method returns an array of Group objects" do
176
- assert_kind_of(Array, Admin.groups(:localaccount => true))
177
- assert_kind_of(Group, Admin.groups(:localaccount => true).first)
178
- end
179
-
180
- # User class
181
-
182
- test "caption accessor for User class" do
183
- assert_respond_to(@user, :caption)
184
- assert_respond_to(@user, :caption=)
185
- end
186
-
187
- test "description accessor for User class" do
188
- assert_respond_to(@user, :description)
189
- assert_respond_to(@user, :description=)
190
- end
191
-
192
- test "domain accessor for User class" do
193
- assert_respond_to(@user, :domain)
194
- assert_respond_to(@user, :domain=)
195
- end
196
-
197
- test "password accessor for User class" do
198
- assert_respond_to(@user, :password)
199
- assert_respond_to(@user, :password=)
200
- end
201
-
202
- test "full_name accessor for User class" do
203
- assert_respond_to(@user, :full_name)
204
- assert_respond_to(@user, :full_name=)
205
- end
206
-
207
- test "name accessor for User class" do
208
- assert_respond_to(@user, :name)
209
- assert_respond_to(@user, :name=)
210
- end
211
-
212
- test "sid accessor for User class" do
213
- assert_respond_to(@user, :sid)
214
- assert_respond_to(@user, :sid=)
215
- end
216
-
217
- test "status accessor for User class" do
218
- assert_respond_to(@user, :status)
219
- assert_respond_to(@user, :status=)
220
- end
221
-
222
- test "disabled accessor for User class" do
223
- assert_respond_to(@user, :disabled?)
224
- assert_respond_to(@user, :disabled=)
225
- end
226
-
227
- test "local accessor for User class" do
228
- assert_respond_to(@user, :local?)
229
- assert_respond_to(@user, :local=)
230
- end
231
-
232
- test "lockout accessor for User class" do
233
- assert_respond_to(@user, :lockout?)
234
- assert_respond_to(@user, :lockout=)
235
- end
236
-
237
- test "password_changeable accessor for User class" do
238
- assert_respond_to(@user, :password_changeable?)
239
- assert_respond_to(@user, :password_changeable=)
240
- end
241
-
242
- test "password_expires accessor for User class" do
243
- assert_respond_to(@user, :password_expires?)
244
- assert_respond_to(@user, :password_expires=)
245
- end
246
-
247
- test "password_required accessor for User class" do
248
- assert_respond_to(@user, :password_required?)
249
- assert_respond_to(@user, :password_required=)
250
- end
251
-
252
- test "account_type accessor for User class" do
253
- assert_respond_to(@user, :account_type)
254
- assert_respond_to(@user, :account_type=)
255
- end
256
-
257
- test "uid accessor for User class" do
258
- assert_respond_to(@user, :uid)
259
- assert_respond_to(@user, :uid=)
260
- end
261
-
262
- test "dir accessor for User class" do
263
- assert_respond_to(@user, :dir)
264
- assert_respond_to(@user, :dir=)
265
- end
266
-
267
- test "dir method returns either a string or nil" do
268
- assert_nothing_raised{ @user = Admin.get_user(@user_name, :localaccount => true) }
269
- assert_kind_of([String, NilClass], @user.dir)
270
- end
271
-
272
- # Group class
273
-
274
- test "caption accessor for Group class" do
275
- assert_respond_to(@group, :caption)
276
- assert_respond_to(@group, :caption=)
277
- end
278
-
279
- test "description accessor for Group class" do
280
- assert_respond_to(@group, :description)
281
- assert_respond_to(@group, :description=)
282
- end
283
-
284
- test "domain accessor for Group class" do
285
- assert_respond_to(@group, :domain)
286
- assert_respond_to(@group, :domain=)
287
- end
288
-
289
- test "install_date accessor for Group class" do
290
- assert_respond_to(@group, :install_date)
291
- assert_respond_to(@group, :install_date=)
292
- end
293
-
294
- test "name accessor for Group class" do
295
- assert_respond_to(@group, :name)
296
- assert_respond_to(@group, :name)
297
- end
298
-
299
- test "gid accessor for Group class" do
300
- assert_respond_to(@group, :gid)
301
- assert_respond_to(@group, :gid=)
302
- end
303
-
304
- test "status accessor for Group class" do
305
- assert_respond_to(@group, :status)
306
- assert_respond_to(@group, :status=)
307
- end
308
-
309
- test "sid accessor for Group class" do
310
- assert_respond_to(@group, :sid)
311
- assert_respond_to(@group, :sid=)
312
- end
313
-
314
- test "sid_type accessor for Group class" do
315
- assert_respond_to(@group, :sid_type)
316
- assert_respond_to(@group, :sid_type=)
317
- end
318
-
319
- test "local accessor for Group class" do
320
- assert_respond_to(@group, :local?)
321
- assert_respond_to(@group, :local=)
322
- end
323
-
324
- def teardown
325
- @user = nil
326
- @user_name = nil
327
- @user_id = nil
328
- @group = nil
329
- @group_name = nil
330
- @group_id = nil
331
- end
332
-
333
- def self.shutdown
334
- @@host = nil
335
- @@elevated = nil
336
- end
337
- end
1
+ ###############################################################################
2
+ # test_sys_admin_windows.rb
3
+ #
4
+ # Test suite for the Win32 version of sys-admin. Note that some of the tests
5
+ # are numbered to ensure a certain order. That way I can add test users
6
+ # before configuring or deleting them.
7
+ #
8
+ # It is assumed that this test will be run via the 'rake test' task.
9
+ ###############################################################################
10
+ require 'test-unit'
11
+ require 'sys/admin'
12
+ require 'win32/security'
13
+ require 'socket'
14
+ include Sys
15
+
16
+ class TC_Sys_Admin_Win32 < Test::Unit::TestCase
17
+ def self.startup
18
+ @@host = Socket.gethostname
19
+ @@elevated = Win32::Security.elevated_security?
20
+ end
21
+
22
+ def setup
23
+ @user = User.new
24
+ @user_name = 'Guest'
25
+ @user_id = 501 # best guess, may fail
26
+ @group = Group.new
27
+ @group_name = 'Guests'
28
+ @group_id = 546 # best guess, may fail
29
+ end
30
+
31
+ # Admin singleton methods
32
+
33
+ def test_01_add_user
34
+ omit_unless(@@elevated)
35
+ assert_respond_to(Admin, :add_user)
36
+ assert_nothing_raised{
37
+ Admin.add_user(:name => 'foo', :password => 'a1b2c3D4')
38
+ }
39
+ end
40
+
41
+ def test_02_config_user
42
+ omit_unless(@@elevated)
43
+ assert_respond_to(Admin, :configure_user)
44
+ assert_nothing_raised{
45
+ Admin.configure_user(
46
+ :name => 'foo',
47
+ :description => 'delete me',
48
+ :fullname => 'fubar',
49
+ :password => 'd1c2b3A4'
50
+ )
51
+ }
52
+ end
53
+
54
+ def test_06_delete_user
55
+ omit_unless(@@elevated)
56
+ assert_respond_to(Admin, :delete_user)
57
+ assert_nothing_raised{ Admin.delete_user('foo') }
58
+ end
59
+
60
+ def test_01_add_group
61
+ omit_unless(@@elevated)
62
+ assert_respond_to(Admin, :add_group)
63
+ assert_nothing_raised{ Admin.add_group(:name => 'bar') }
64
+ end
65
+
66
+ def test_02_configure_group
67
+ omit_unless(@@elevated)
68
+ assert_respond_to(Admin, :configure_group)
69
+ assert_nothing_raised{
70
+ Admin.configure_group(:name => 'bar', :description => 'delete me')
71
+ }
72
+ end
73
+
74
+ def test_03_add_group_member
75
+ omit_unless(@@elevated)
76
+ assert_respond_to(Admin, :add_group_member)
77
+ assert_nothing_raised{ Admin.add_group_member('foo', 'bar') }
78
+ end
79
+
80
+ def test_04_remove_group_member
81
+ omit_unless(@@elevated)
82
+ assert_respond_to(Admin, :remove_group_member)
83
+ assert_nothing_raised{ Admin.remove_group_member('foo', 'bar') }
84
+ end
85
+
86
+ def test_05_delete_group
87
+ omit_unless(@@elevated)
88
+ assert_respond_to(Admin, :delete_group)
89
+ assert_nothing_raised{ Admin.delete_group('bar') }
90
+ end
91
+
92
+ test "get_login basic functionality" do
93
+ assert_respond_to(Admin, :get_login)
94
+ assert_nothing_raised{ Admin.get_login }
95
+ end
96
+
97
+ test "get_login returns a string" do
98
+ assert_kind_of(String, Admin.get_login)
99
+ assert_true(Admin.get_login.size > 0)
100
+ end
101
+
102
+ test "get_login does not accept any arguments" do
103
+ assert_raise(ArgumentError){ Admin.get_login('foo') }
104
+ end
105
+
106
+ test "get_user basic functionality" do
107
+ assert_respond_to(Admin, :get_user)
108
+ end
109
+
110
+ test "get_user with string argument works as expected" do
111
+ assert_nothing_raised{ Admin.get_user(@user_name, :localaccount => true) }
112
+ assert_kind_of(User, Admin.get_user(@user_name, :localaccount => true))
113
+ end
114
+
115
+ test "get user with integer argument works as expected" do
116
+ assert_nothing_raised{ Admin.get_user(@user_id, :localaccount => true) }
117
+ assert_kind_of(User, Admin.get_user(@user_id, :localaccount => true))
118
+ end
119
+
120
+ test "get_user method by string accepts a hash of options" do
121
+ options = {:host => @@host, :localaccount => true}
122
+ assert_nothing_raised{ Admin.get_user(@user_name, options) }
123
+ assert_kind_of(User, Admin.get_user(@user_name, options))
124
+ end
125
+
126
+ test "get_user method by uid accepts a hash of options" do
127
+ options = {:host => @@host, :localaccount => true}
128
+ assert_nothing_raised{ Admin.get_user(@user_id, options) }
129
+ assert_kind_of(User, Admin.get_user(@user_id, options))
130
+ end
131
+
132
+ test "get_user method requires an argument" do
133
+ assert_raises(ArgumentError){ Admin.get_user }
134
+ end
135
+
136
+ test "users method basic functionality" do
137
+ assert_respond_to(Admin, :users)
138
+ assert_nothing_raised{ Admin.users(:localaccount => true) }
139
+ end
140
+
141
+ test "users method returns an array of User objects" do
142
+ assert_kind_of(Array, Admin.users(:localaccount => true))
143
+ assert_kind_of(User, Admin.users(:localaccount => true).first)
144
+ end
145
+
146
+ test "get_group basic functionality" do
147
+ assert_respond_to(Admin, :get_group)
148
+ end
149
+
150
+ test "get_group method returns expected results with a string argument" do
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
+ test "get_group method returns expected results with an integer argument" do
156
+ assert_nothing_raised{ Admin.get_group(@group_id, :localaccount => true) }
157
+ assert_kind_of(Group, Admin.get_group(@group_id, :localaccount => true))
158
+ end
159
+
160
+ # TODO: Update
161
+ test "get_group method accepts a hash of options" do
162
+ assert_nothing_raised{ Admin.get_group(@group_name, :localaccount => true) }
163
+ assert_kind_of(Group, Admin.get_group(@group_name, :localaccount => true))
164
+ end
165
+
166
+ test "get_group method requires an argument" do
167
+ assert_raise(ArgumentError){ Admin.get_group }
168
+ end
169
+
170
+ test "get_groups method basic functionality" do
171
+ assert_respond_to(Admin, :groups)
172
+ assert_nothing_raised{ Admin.groups(:localaccount => true) }
173
+ end
174
+
175
+ test "get_groups method returns an array of Group objects" do
176
+ assert_kind_of(Array, Admin.groups(:localaccount => true))
177
+ assert_kind_of(Group, Admin.groups(:localaccount => true).first)
178
+ end
179
+
180
+ # User class
181
+
182
+ test "caption accessor for User class" do
183
+ assert_respond_to(@user, :caption)
184
+ assert_respond_to(@user, :caption=)
185
+ end
186
+
187
+ test "description accessor for User class" do
188
+ assert_respond_to(@user, :description)
189
+ assert_respond_to(@user, :description=)
190
+ end
191
+
192
+ test "domain accessor for User class" do
193
+ assert_respond_to(@user, :domain)
194
+ assert_respond_to(@user, :domain=)
195
+ end
196
+
197
+ test "password accessor for User class" do
198
+ assert_respond_to(@user, :password)
199
+ assert_respond_to(@user, :password=)
200
+ end
201
+
202
+ test "full_name accessor for User class" do
203
+ assert_respond_to(@user, :full_name)
204
+ assert_respond_to(@user, :full_name=)
205
+ end
206
+
207
+ test "name accessor for User class" do
208
+ assert_respond_to(@user, :name)
209
+ assert_respond_to(@user, :name=)
210
+ end
211
+
212
+ test "sid accessor for User class" do
213
+ assert_respond_to(@user, :sid)
214
+ assert_respond_to(@user, :sid=)
215
+ end
216
+
217
+ test "status accessor for User class" do
218
+ assert_respond_to(@user, :status)
219
+ assert_respond_to(@user, :status=)
220
+ end
221
+
222
+ test "disabled accessor for User class" do
223
+ assert_respond_to(@user, :disabled?)
224
+ assert_respond_to(@user, :disabled=)
225
+ end
226
+
227
+ test "local accessor for User class" do
228
+ assert_respond_to(@user, :local?)
229
+ assert_respond_to(@user, :local=)
230
+ end
231
+
232
+ test "lockout accessor for User class" do
233
+ assert_respond_to(@user, :lockout?)
234
+ assert_respond_to(@user, :lockout=)
235
+ end
236
+
237
+ test "password_changeable accessor for User class" do
238
+ assert_respond_to(@user, :password_changeable?)
239
+ assert_respond_to(@user, :password_changeable=)
240
+ end
241
+
242
+ test "password_expires accessor for User class" do
243
+ assert_respond_to(@user, :password_expires?)
244
+ assert_respond_to(@user, :password_expires=)
245
+ end
246
+
247
+ test "password_required accessor for User class" do
248
+ assert_respond_to(@user, :password_required?)
249
+ assert_respond_to(@user, :password_required=)
250
+ end
251
+
252
+ test "account_type accessor for User class" do
253
+ assert_respond_to(@user, :account_type)
254
+ assert_respond_to(@user, :account_type=)
255
+ end
256
+
257
+ test "uid accessor for User class" do
258
+ assert_respond_to(@user, :uid)
259
+ assert_respond_to(@user, :uid=)
260
+ end
261
+
262
+ test "dir accessor for User class" do
263
+ assert_respond_to(@user, :dir)
264
+ assert_respond_to(@user, :dir=)
265
+ end
266
+
267
+ test "dir method returns either a string or nil" do
268
+ assert_nothing_raised{ @user = Admin.get_user(@user_name, :localaccount => true) }
269
+ assert_kind_of([String, NilClass], @user.dir)
270
+ end
271
+
272
+ # Group class
273
+
274
+ test "caption accessor for Group class" do
275
+ assert_respond_to(@group, :caption)
276
+ assert_respond_to(@group, :caption=)
277
+ end
278
+
279
+ test "description accessor for Group class" do
280
+ assert_respond_to(@group, :description)
281
+ assert_respond_to(@group, :description=)
282
+ end
283
+
284
+ test "domain accessor for Group class" do
285
+ assert_respond_to(@group, :domain)
286
+ assert_respond_to(@group, :domain=)
287
+ end
288
+
289
+ test "install_date accessor for Group class" do
290
+ assert_respond_to(@group, :install_date)
291
+ assert_respond_to(@group, :install_date=)
292
+ end
293
+
294
+ test "name accessor for Group class" do
295
+ assert_respond_to(@group, :name)
296
+ assert_respond_to(@group, :name)
297
+ end
298
+
299
+ test "gid accessor for Group class" do
300
+ assert_respond_to(@group, :gid)
301
+ assert_respond_to(@group, :gid=)
302
+ end
303
+
304
+ test "status accessor for Group class" do
305
+ assert_respond_to(@group, :status)
306
+ assert_respond_to(@group, :status=)
307
+ end
308
+
309
+ test "sid accessor for Group class" do
310
+ assert_respond_to(@group, :sid)
311
+ assert_respond_to(@group, :sid=)
312
+ end
313
+
314
+ test "sid_type accessor for Group class" do
315
+ assert_respond_to(@group, :sid_type)
316
+ assert_respond_to(@group, :sid_type=)
317
+ end
318
+
319
+ test "local accessor for Group class" do
320
+ assert_respond_to(@group, :local?)
321
+ assert_respond_to(@group, :local=)
322
+ end
323
+
324
+ def teardown
325
+ @user = nil
326
+ @user_name = nil
327
+ @user_id = nil
328
+ @group = nil
329
+ @group_name = nil
330
+ @group_id = nil
331
+ end
332
+
333
+ def self.shutdown
334
+ @@host = nil
335
+ @@elevated = nil
336
+ end
337
+ end