sys-admin 1.5.4-x86-mingw32 → 1.5.5-x86-mingw32
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/CHANGES +8 -0
- data/Rakefile +12 -13
- data/lib/sys/admin.rb +944 -936
- data/sys-admin.gemspec +1 -1
- data/test/test_sys_admin.rb +1 -1
- data/test/test_sys_admin_windows.rb +306 -295
- metadata +6 -8
data/sys-admin.gemspec
CHANGED
data/test/test_sys_admin.rb
CHANGED
@@ -13,321 +13,332 @@ gem 'test-unit'
|
|
13
13
|
require 'test/unit'
|
14
14
|
require 'sys/admin'
|
15
15
|
require 'socket'
|
16
|
+
require 'etc'
|
16
17
|
include Sys
|
17
18
|
|
18
19
|
class TC_Sys_Admin_Win32 < Test::Unit::TestCase
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
def self.startup
|
21
|
+
@@host = Socket.gethostname
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
def setup
|
25
|
+
@user = User.new
|
26
|
+
@user_name = 'Guest'
|
27
|
+
@user_id = 501 # best guess, may fail
|
28
|
+
@group = Group.new
|
29
|
+
@group_name = 'Guests'
|
30
|
+
@group_id = 546 # best guess, may fail
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
+
# Admin singleton methods
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
def test_01_add_user
|
36
|
+
assert_respond_to(Admin, :add_user)
|
37
|
+
assert_nothing_raised{
|
38
|
+
Admin.add_user(:name => 'foo', :password => 'a1b2c3D4')
|
39
|
+
}
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
def test_01_add_group
|
59
|
-
assert_respond_to(Admin, :add_group)
|
60
|
-
assert_nothing_raised{ Admin.add_group(:name => 'bar') }
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_02_configure_group
|
64
|
-
assert_respond_to(Admin, :configure_group)
|
65
|
-
assert_nothing_raised{
|
66
|
-
Admin.configure_group(:name => 'bar', :description => 'delete me')
|
67
|
-
}
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_03_delete_group
|
71
|
-
assert_respond_to(Admin, :delete_group)
|
72
|
-
assert_nothing_raised{ Admin.delete_group('bar') }
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_get_login_basic
|
76
|
-
assert_respond_to(Admin, :get_login)
|
77
|
-
assert_nothing_raised{ Admin.get_login }
|
78
|
-
end
|
42
|
+
def test_02_config_user
|
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 => ['a1b2c3D4', 'd1c2b3A4']
|
50
|
+
)
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_03_delete_user
|
55
|
+
assert_respond_to(Admin, :delete_user)
|
56
|
+
assert_nothing_raised{ Admin.delete_user('foo') }
|
57
|
+
end
|
79
58
|
|
80
|
-
|
81
|
-
|
82
|
-
|
59
|
+
def test_01_add_group
|
60
|
+
assert_respond_to(Admin, :add_group)
|
61
|
+
assert_nothing_raised{ Admin.add_group(:name => 'bar') }
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_02_configure_group
|
65
|
+
assert_respond_to(Admin, :configure_group)
|
66
|
+
assert_nothing_raised{
|
67
|
+
Admin.configure_group(:name => 'bar', :description => 'delete me')
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_03_delete_group
|
72
|
+
assert_respond_to(Admin, :delete_group)
|
73
|
+
assert_nothing_raised{ Admin.delete_group('bar') }
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_get_login_basic
|
77
|
+
assert_respond_to(Admin, :get_login)
|
78
|
+
assert_nothing_raised{ Admin.get_login }
|
79
|
+
end
|
83
80
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
def test_get_user_basic
|
89
|
-
assert_respond_to(Admin, :get_user)
|
90
|
-
end
|
91
|
-
|
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
|
81
|
+
def test_get_login
|
82
|
+
assert_kind_of(String, Admin.get_login)
|
83
|
+
end
|
96
84
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
assert_nothing_raised{ Admin.get_user(@user_name, options) }
|
105
|
-
assert_kind_of(User, Admin.get_user(@user_name, options))
|
106
|
-
end
|
85
|
+
def test_get_login_expected_errors
|
86
|
+
assert_raise(ArgumentError){ Admin.get_login('foo') }
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_get_user_basic
|
90
|
+
assert_respond_to(Admin, :get_user)
|
91
|
+
end
|
107
92
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
end
|
93
|
+
def test_get_user_by_string
|
94
|
+
assert_nothing_raised{ Admin.get_user(@user_name, :localaccount => true) }
|
95
|
+
assert_kind_of(User, Admin.get_user(@user_name, :localaccount => true))
|
96
|
+
end
|
113
97
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
98
|
+
def test_get_user_by_uid
|
99
|
+
assert_nothing_raised{ Admin.get_user(@user_id, :localaccount => true) }
|
100
|
+
assert_kind_of(User, Admin.get_user(@user_id, :localaccount => true))
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_get_user_by_string_with_options
|
104
|
+
options = {:host => @@host, :localaccount => true}
|
105
|
+
assert_nothing_raised{ Admin.get_user(@user_name, options) }
|
106
|
+
assert_kind_of(User, Admin.get_user(@user_name, options))
|
107
|
+
end
|
122
108
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
109
|
+
def test_get_user_by_uid_with_options
|
110
|
+
options = {:host => @@host, :localaccount => true}
|
111
|
+
assert_nothing_raised{ Admin.get_user(@user_id, options) }
|
112
|
+
assert_kind_of(User, Admin.get_user(@user_id, options))
|
113
|
+
end
|
127
114
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
}
|
133
|
-
assert_kind_of(User, array[0])
|
134
|
-
end
|
115
|
+
def test_get_user_with_no_options
|
116
|
+
assert_nothing_raised{ Admin.get_user(Etc.getlogin) }
|
117
|
+
assert_kind_of(User, Admin.get_user(Etc.getlogin))
|
118
|
+
end
|
135
119
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
120
|
+
def test_get_user_expected_errors
|
121
|
+
assert_raises(ArgumentError){ Admin.get_user }
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_users_basic
|
125
|
+
assert_respond_to(Admin, :users)
|
126
|
+
assert_nothing_raised{ Admin.users(:localaccount => true) }
|
127
|
+
end
|
144
128
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
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
|
129
|
+
def test_users
|
130
|
+
assert_kind_of(Array, Admin.users(:localaccount => true))
|
131
|
+
assert_kind_of(User, Admin.users(:localaccount => true).first)
|
132
|
+
end
|
154
133
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
end
|
134
|
+
def test_users_with_block
|
135
|
+
array = []
|
136
|
+
assert_nothing_raised{
|
137
|
+
Admin.users(:localaccount => true){ |u| array << u }
|
138
|
+
}
|
139
|
+
assert_kind_of(User, array[0])
|
140
|
+
end
|
163
141
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
Admin.groups(:localaccount => true){ |g| array << g }
|
173
|
-
}
|
174
|
-
assert_kind_of(Group, array[0])
|
175
|
-
end
|
142
|
+
def test_get_group_basic
|
143
|
+
assert_respond_to(Admin, :get_group)
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_get_group_by_name
|
147
|
+
assert_nothing_raised{ Admin.get_group(@group_name, :localaccount => true) }
|
148
|
+
assert_kind_of(Group, Admin.get_group(@group_name, :localaccount => true))
|
149
|
+
end
|
176
150
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
assert_respond_to(@user, :description=)
|
187
|
-
end
|
188
|
-
|
189
|
-
def test_user_instance_domain
|
190
|
-
assert_respond_to(@user, :domain)
|
191
|
-
assert_respond_to(@user, :domain=)
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_user_instance_password
|
195
|
-
assert_respond_to(@user, :password)
|
196
|
-
assert_respond_to(@user, :password=)
|
197
|
-
end
|
198
|
-
|
199
|
-
def test_user_instance_full_name
|
200
|
-
assert_respond_to(@user, :full_name)
|
201
|
-
assert_respond_to(@user, :full_name=)
|
202
|
-
end
|
203
|
-
|
204
|
-
def test_user_instance_name
|
205
|
-
assert_respond_to(@user, :name)
|
206
|
-
assert_respond_to(@user, :name=)
|
207
|
-
end
|
208
|
-
|
209
|
-
def test_user_instance_sid
|
210
|
-
assert_respond_to(@user, :sid)
|
211
|
-
assert_respond_to(@user, :sid=)
|
212
|
-
end
|
213
|
-
|
214
|
-
def test_user_instance_status
|
215
|
-
assert_respond_to(@user, :status)
|
216
|
-
assert_respond_to(@user, :status=)
|
217
|
-
end
|
218
|
-
|
219
|
-
def test_user_instance_disabled
|
220
|
-
assert_respond_to(@user, :disabled?)
|
221
|
-
assert_respond_to(@user, :disabled=)
|
222
|
-
end
|
223
|
-
|
224
|
-
def test_user_instance_local
|
225
|
-
assert_respond_to(@user, :local?)
|
226
|
-
assert_respond_to(@user, :local=)
|
227
|
-
end
|
228
|
-
|
229
|
-
def test_user_instance_lockout
|
230
|
-
assert_respond_to(@user, :lockout?)
|
231
|
-
assert_respond_to(@user, :lockout=)
|
232
|
-
end
|
233
|
-
|
234
|
-
def test_user_instance_password_changeable
|
235
|
-
assert_respond_to(@user, :password_changeable?)
|
236
|
-
assert_respond_to(@user, :password_changeable=)
|
237
|
-
end
|
238
|
-
|
239
|
-
def test_user_instance_password_expires
|
240
|
-
assert_respond_to(@user, :password_expires?)
|
241
|
-
assert_respond_to(@user, :password_expires=)
|
242
|
-
end
|
243
|
-
|
244
|
-
def test_user_instance_password_required
|
245
|
-
assert_respond_to(@user, :password_required?)
|
246
|
-
assert_respond_to(@user, :password_required=)
|
247
|
-
end
|
248
|
-
|
249
|
-
def test_user_instance_account_type
|
250
|
-
assert_respond_to(@user, :account_type)
|
251
|
-
assert_respond_to(@user, :account_type=)
|
252
|
-
end
|
151
|
+
def test_get_group_by_gid
|
152
|
+
assert_nothing_raised{ Admin.get_group(@group_id, :localaccount => true) }
|
153
|
+
assert_kind_of(Group, Admin.get_group(@group_id, :localaccount => true))
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_get_group_with_options
|
157
|
+
assert_nothing_raised{ Admin.get_group(@group_name, :localaccount => true) }
|
158
|
+
assert_kind_of(Group, Admin.get_group(@group_name, :localaccount => true))
|
159
|
+
end
|
253
160
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
161
|
+
def test_get_group_with_no_options
|
162
|
+
assert_nothing_raised{ Admin.get_group("Administrators") }
|
163
|
+
assert_kind_of(Group, Admin.get_group("Administrators"))
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_get_group_expected_errors
|
167
|
+
assert_raise(ArgumentError){ Admin.get_group }
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_groups_basic
|
171
|
+
assert_respond_to(Admin, :groups)
|
172
|
+
assert_nothing_raised{ Admin.groups(:localaccount => true) }
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_groups
|
176
|
+
assert_kind_of(Array, Admin.groups(:localaccount => true))
|
177
|
+
assert_kind_of(Group, Admin.groups(:localaccount => true).first)
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_groups_with_block
|
181
|
+
array = []
|
182
|
+
assert_nothing_raised{
|
183
|
+
Admin.groups(:localaccount => true){ |g| array << g }
|
184
|
+
}
|
185
|
+
assert_kind_of(Group, array[0])
|
186
|
+
end
|
187
|
+
|
188
|
+
# User class
|
189
|
+
|
190
|
+
def test_user_instance_caption
|
191
|
+
assert_respond_to(@user, :caption)
|
192
|
+
assert_respond_to(@user, :caption=)
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_user_instance_description
|
196
|
+
assert_respond_to(@user, :description)
|
197
|
+
assert_respond_to(@user, :description=)
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_user_instance_domain
|
201
|
+
assert_respond_to(@user, :domain)
|
202
|
+
assert_respond_to(@user, :domain=)
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_user_instance_password
|
206
|
+
assert_respond_to(@user, :password)
|
207
|
+
assert_respond_to(@user, :password=)
|
208
|
+
end
|
209
|
+
|
210
|
+
def test_user_instance_full_name
|
211
|
+
assert_respond_to(@user, :full_name)
|
212
|
+
assert_respond_to(@user, :full_name=)
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_user_instance_name
|
216
|
+
assert_respond_to(@user, :name)
|
217
|
+
assert_respond_to(@user, :name=)
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_user_instance_sid
|
221
|
+
assert_respond_to(@user, :sid)
|
222
|
+
assert_respond_to(@user, :sid=)
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_user_instance_status
|
226
|
+
assert_respond_to(@user, :status)
|
227
|
+
assert_respond_to(@user, :status=)
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_user_instance_disabled
|
231
|
+
assert_respond_to(@user, :disabled?)
|
232
|
+
assert_respond_to(@user, :disabled=)
|
233
|
+
end
|
234
|
+
|
235
|
+
def test_user_instance_local
|
236
|
+
assert_respond_to(@user, :local?)
|
237
|
+
assert_respond_to(@user, :local=)
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_user_instance_lockout
|
241
|
+
assert_respond_to(@user, :lockout?)
|
242
|
+
assert_respond_to(@user, :lockout=)
|
243
|
+
end
|
244
|
+
|
245
|
+
def test_user_instance_password_changeable
|
246
|
+
assert_respond_to(@user, :password_changeable?)
|
247
|
+
assert_respond_to(@user, :password_changeable=)
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_user_instance_password_expires
|
251
|
+
assert_respond_to(@user, :password_expires?)
|
252
|
+
assert_respond_to(@user, :password_expires=)
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_user_instance_password_required
|
256
|
+
assert_respond_to(@user, :password_required?)
|
257
|
+
assert_respond_to(@user, :password_required=)
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_user_instance_account_type
|
261
|
+
assert_respond_to(@user, :account_type)
|
262
|
+
assert_respond_to(@user, :account_type=)
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_user_instance_uid
|
266
|
+
assert_respond_to(@user, :uid)
|
267
|
+
assert_respond_to(@user, :uid=)
|
268
|
+
end
|
269
|
+
|
270
|
+
def test_user_dir_basic
|
271
|
+
assert_respond_to(@user, :dir)
|
272
|
+
assert_respond_to(@user, :dir=)
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_user_dir
|
276
|
+
assert_nothing_raised{ @user = Admin.get_user(@user_name, :localaccount => true) }
|
277
|
+
assert_kind_of([String, NilClass], @user.dir)
|
278
|
+
end
|
279
|
+
|
280
|
+
# Group class
|
281
|
+
|
282
|
+
def test_group_instance_caption
|
283
|
+
assert_respond_to(@group, :caption)
|
284
|
+
assert_respond_to(@group, :caption=)
|
285
|
+
end
|
286
|
+
|
287
|
+
def test_group_instance_description
|
288
|
+
assert_respond_to(@group, :description)
|
289
|
+
assert_respond_to(@group, :description=)
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_group_instance_domain
|
293
|
+
assert_respond_to(@group, :domain)
|
294
|
+
assert_respond_to(@group, :domain=)
|
295
|
+
end
|
296
|
+
|
297
|
+
def test_group_instance_install_date
|
298
|
+
assert_respond_to(@group, :install_date)
|
299
|
+
assert_respond_to(@group, :install_date=)
|
300
|
+
end
|
301
|
+
|
302
|
+
def test_group_instance_name
|
303
|
+
assert_respond_to(@group, :name)
|
304
|
+
assert_respond_to(@group, :name)
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_group_instance_gid
|
308
|
+
assert_respond_to(@group, :gid)
|
309
|
+
assert_respond_to(@group, :gid=)
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_group_instance_status
|
313
|
+
assert_respond_to(@group, :status)
|
314
|
+
assert_respond_to(@group, :status=)
|
315
|
+
end
|
316
|
+
|
317
|
+
def test_group_instance_sid
|
318
|
+
assert_respond_to(@group, :sid)
|
319
|
+
assert_respond_to(@group, :sid=)
|
320
|
+
end
|
321
|
+
|
322
|
+
def test_group_instance_sid_type
|
323
|
+
assert_respond_to(@group, :sid_type)
|
324
|
+
assert_respond_to(@group, :sid_type=)
|
325
|
+
end
|
326
|
+
|
327
|
+
def test_group_instance_local
|
328
|
+
assert_respond_to(@group, :local?)
|
329
|
+
assert_respond_to(@group, :local=)
|
330
|
+
end
|
320
331
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
332
|
+
def teardown
|
333
|
+
@user = nil
|
334
|
+
@user_name = nil
|
335
|
+
@user_id = nil
|
336
|
+
@group = nil
|
337
|
+
@group_name = nil
|
338
|
+
@group_id = nil
|
339
|
+
end
|
329
340
|
|
330
|
-
|
331
|
-
|
332
|
-
|
341
|
+
def self.shutdown
|
342
|
+
@@host = nil
|
343
|
+
end
|
333
344
|
end
|