sys-admin 1.3.1-mswin32 → 1.4.0-mswin32

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,38 @@
1
+ require 'rubygems'
2
+
3
+ spec = Gem::Specification.new do |gem|
4
+ gem.name = 'sys-admin'
5
+ gem.version = '1.4.0'
6
+ gem.author = 'Daniel J. Berger'
7
+ gem.email = 'djberg96@gmail.com'
8
+ gem.homepage = 'http://www.rubyforge.org/projects/sysutils'
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'
13
+ gem.has_rdoc = true
14
+ gem.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
15
+ gem.rubyforge_project = 'sysutils'
16
+
17
+ files = Dir["doc/*"] + Dir["examples/*"]
18
+ files += Dir["test/*"] + Dir["[A-Z]*"]
19
+ files.delete_if{ |item| item.include?('CVS') }
20
+ gem.files = files
21
+ end
22
+
23
+ if $PROGRAM_NAME == __FILE__
24
+ if RUBY_PLATFORM.match('mswin')
25
+ spec.required_ruby_version = '>= 1.8.2'
26
+ spec.files += Dir["lib/sys/admin.rb"]
27
+ spec.platform = Gem::Platform::WIN32
28
+ else
29
+ spec.required_ruby_version = '>= 1.8.0'
30
+ spec.extensions = ['ext/extconf.rb']
31
+ spec.files += Dir["ext/*"]
32
+ spec.extra_rdoc_files << 'ext/admin.c'
33
+ spec.require_path = 'lib'
34
+ end
35
+
36
+ Gem.manage_gems
37
+ Gem::Builder.new(spec).build
38
+ end
@@ -1,14 +1,14 @@
1
- ###############################################################################
2
- # tc_admin.rb
3
- #
4
- # This exists mostly for the sake of the gemspec, so that it calls the right
5
- # test suite based on the platform.
6
- ###############################################################################
7
- $LOAD_PATH.unshift Dir.pwd
8
- $LOAD_PATH.unshift Dir.pwd + "/test"
9
-
10
- if File::ALT_SEPARATOR
11
- require "tc_win32"
12
- else
13
- require "tc_unix"
14
- end
1
+ ###############################################################################
2
+ # tc_admin.rb
3
+ #
4
+ # This exists mostly for the sake of the gemspec, so that it calls the right
5
+ # test suite based on the platform.
6
+ ###############################################################################
7
+ $LOAD_PATH.unshift Dir.pwd
8
+ $LOAD_PATH.unshift Dir.pwd + "/test"
9
+
10
+ if File::ALT_SEPARATOR
11
+ require "tc_windows"
12
+ else
13
+ require "tc_unix"
14
+ end
@@ -0,0 +1,78 @@
1
+ ###############################################################################
2
+ # tc_unix.rb
3
+ #
4
+ # Test suite for the Unix version of sys-admin.
5
+ ###############################################################################
6
+ base = File.basename(Dir.pwd)
7
+
8
+ if base == "test" || base =~ /sys-admin.*/
9
+ require "fileutils"
10
+ Dir.chdir("..") if base == "test"
11
+ Dir.mkdir("sys") unless File.exists?("sys")
12
+ FileUtils.cp("ext/admin.so", "sys") if File.exists?("ext/admin.so")
13
+ $LOAD_PATH.unshift(Dir.pwd)
14
+ end
15
+
16
+ require 'test/unit'
17
+ require 'sys/admin'
18
+ include Sys
19
+
20
+ class TC_Sys_Admin_Unix < Test::Unit::TestCase
21
+ def setup
22
+ @user = "nobody"
23
+ @userid = 0
24
+ @group = "sys"
25
+ @groupid = 3
26
+ end
27
+
28
+ def test_version
29
+ assert_equal("1.4.0", Admin::VERSION)
30
+ end
31
+
32
+ def test_get_login
33
+ assert_respond_to(Admin, :get_login)
34
+ assert_nothing_raised{ Admin.get_login }
35
+ assert_kind_of(String, Admin.get_login)
36
+ end
37
+
38
+ def test_get_user
39
+ assert_respond_to(Admin, :get_user)
40
+ assert_nothing_raised{ Admin.get_user(@user) }
41
+ assert_nothing_raised{ Admin.get_user(@userid) }
42
+ assert_kind_of(User, Admin.get_user(@user))
43
+ assert_kind_of(User, Admin.get_user(@userid))
44
+ assert_raises(AdminError){ Admin.get_user("foofoo") }
45
+ end
46
+
47
+ def test_users
48
+ assert_respond_to(Admin, :users)
49
+ assert_nothing_raised{ Admin.users }
50
+ assert_nothing_raised{ Admin.users{ |g| } }
51
+ assert_kind_of(Array, Admin.users)
52
+ assert_kind_of(User, Admin.users.first)
53
+ end
54
+
55
+ def test_get_group
56
+ assert_respond_to(Admin, :get_group)
57
+ assert_nothing_raised{ Admin.get_group(@group) }
58
+ assert_nothing_raised{ Admin.get_group(@groupid) }
59
+ assert_kind_of(Group, Admin.get_group(@group))
60
+ assert_kind_of(Group, Admin.get_group(@groupid))
61
+ assert_raises(AdminError){ Admin.get_group("foofoo") }
62
+ end
63
+
64
+ def test_groups
65
+ assert_respond_to(Admin, :groups)
66
+ assert_nothing_raised{ Admin.groups }
67
+ assert_nothing_raised{ Admin.groups{ |g| } }
68
+ assert_kind_of(Array, Admin.groups)
69
+ assert_kind_of(Group, Admin.groups.first)
70
+ end
71
+
72
+ def teardown
73
+ @user = nil
74
+ @userid = nil
75
+ @group = nil
76
+ @groupid = nil
77
+ end
78
+ end
@@ -0,0 +1,312 @@
1
+ ###############################################################################
2
+ # tc_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
+ base = File.basename(Dir.pwd)
9
+
10
+ if base == "test" || base =~ /sys-admin.*/
11
+ require "ftools"
12
+ Dir.chdir("..") if base == "test"
13
+ Dir.mkdir("sys") unless File.exists?("sys")
14
+ File.copy("lib/sys/admin.rb", "sys/admin.rb")
15
+ $LOAD_PATH.unshift(Dir.pwd)
16
+ Dir.chdir("test") rescue nil
17
+ end
18
+
19
+ require "test/unit"
20
+ require "sys/admin"
21
+ require "socket"
22
+ include Sys
23
+
24
+ class TC_Sys_Admin_Win32 < Test::Unit::TestCase
25
+ def setup
26
+ @host = Socket.gethostname
27
+ @user = User.new
28
+ @user_name = "guest"
29
+ @user_id = 501 # best guess, may fail
30
+ @group = Group.new
31
+ @group_name = "guests"
32
+ @group_id = 546 # best guess, may fail
33
+ end
34
+
35
+ def test_version
36
+ assert_equal("1.4.0", Admin::VERSION)
37
+ end
38
+
39
+ def test_01_add_local_user
40
+ assert_respond_to(Admin, :add_local_user)
41
+ assert_nothing_raised{ Admin.add_local_user("foo") }
42
+ end
43
+
44
+ def test_add_global_user
45
+ assert_respond_to(Admin, :add_global_user)
46
+ end
47
+
48
+ def test_02_config_local_user
49
+ assert_respond_to(Admin, :config_local_user)
50
+ assert_nothing_raised{
51
+ Admin.config_local_user("foo",{
52
+ :description => "delete me",
53
+ :fullname => "fubar"
54
+ })
55
+ }
56
+ end
57
+
58
+ def test_config_global_user
59
+ assert_respond_to(Admin, :config_global_user)
60
+ end
61
+
62
+ def test_03_delete_local_user
63
+ assert_respond_to(Admin, :delete_local_user)
64
+ assert_nothing_raised{ Admin.delete_local_user("foo") }
65
+ end
66
+
67
+ def test_delete_global_user
68
+ assert_respond_to(Admin, :delete_global_user)
69
+ end
70
+
71
+ def test_01_add_local_group
72
+ assert_respond_to(Admin, :add_local_group)
73
+ assert_nothing_raised{ Admin.add_local_group("bar") }
74
+ end
75
+
76
+ def test_add_global_group
77
+ assert_respond_to(Admin, :add_global_group)
78
+ end
79
+
80
+ def test_02_config_local_group
81
+ assert_respond_to(Admin, :config_local_group)
82
+ assert_nothing_raised{
83
+ Admin.config_local_group("bar",{:description=>"delete me"})
84
+ }
85
+ end
86
+
87
+ def test_config_global_group
88
+ assert_respond_to(Admin, :config_global_group)
89
+ end
90
+
91
+ def test_03_delete_local_group
92
+ assert_respond_to(Admin, :delete_local_group)
93
+ assert_nothing_raised{ Admin.delete_local_group("bar") }
94
+ end
95
+
96
+ def test_delete_global_group
97
+ assert_respond_to(Admin, :delete_global_group)
98
+ end
99
+
100
+ def test_get_login
101
+ assert_respond_to(Admin, :get_login)
102
+ assert_nothing_raised{ Admin.get_login }
103
+ assert_kind_of(String, Admin.get_login)
104
+ end
105
+
106
+ def test_get_user
107
+ assert_respond_to(Admin, :get_user)
108
+ assert_raises(ArgumentError){ Admin.get_user }
109
+ end
110
+
111
+ def test_get_user_local
112
+ assert_nothing_raised{ Admin.get_user(@user_name) }
113
+ assert_nothing_raised{ Admin.get_user(@user_id) }
114
+ assert_kind_of(User, Admin.get_user(@user_name))
115
+ assert_kind_of(User, Admin.get_user(@user_id))
116
+ end
117
+
118
+ def test_get_user_remote
119
+ assert_nothing_raised{ Admin.get_user(@user_name, @host) }
120
+ assert_nothing_raised{ Admin.get_user(@user_id, @host) }
121
+ assert_kind_of(User, Admin.get_user(@user_name, @host))
122
+ assert_kind_of(User, Admin.get_user(@user_id, @host))
123
+ end
124
+
125
+ def test_users
126
+ assert_respond_to(Admin, :users)
127
+ end
128
+
129
+ def test_users_local
130
+ assert_nothing_raised{ Admin.users }
131
+ assert_nothing_raised{ Admin.users{ |u| } }
132
+ assert_nothing_raised{ Admin.users(nil) }
133
+ assert_nothing_raised{ Admin.users(nil){ |u| } }
134
+ assert_kind_of(Array, Admin.users)
135
+ assert_kind_of(User, Admin.users.first)
136
+ end
137
+
138
+ def test_users_remote
139
+ assert_nothing_raised{ Admin.users(@host) }
140
+ assert_nothing_raised{ Admin.users(@host){ |u| } }
141
+ end
142
+
143
+ def test_user_instance_caption
144
+ assert_respond_to(@user, :caption)
145
+ assert_respond_to(@user, :caption=)
146
+ end
147
+
148
+ def test_user_instance_description
149
+ assert_respond_to(@user, :description)
150
+ assert_respond_to(@user, :description=)
151
+ end
152
+
153
+ def test_user_instance_domain
154
+ assert_respond_to(@user, :domain)
155
+ assert_respond_to(@user, :domain=)
156
+ end
157
+
158
+ def test_user_instance_password
159
+ assert_respond_to(@user, :password)
160
+ assert_respond_to(@user, :password=)
161
+ end
162
+
163
+ def test_user_instance_full_name
164
+ assert_respond_to(@user, :full_name)
165
+ assert_respond_to(@user, :full_name=)
166
+ end
167
+
168
+ def test_user_instance_name
169
+ assert_respond_to(@user, :name)
170
+ assert_respond_to(@user, :name=)
171
+ end
172
+
173
+ def test_user_instance_sid
174
+ assert_respond_to(@user, :sid)
175
+ assert_respond_to(@user, :sid=)
176
+ end
177
+
178
+ def test_user_instance_status
179
+ assert_respond_to(@user, :status)
180
+ assert_respond_to(@user, :status=)
181
+ end
182
+
183
+ def test_user_instance_disabled
184
+ assert_respond_to(@user, :disabled?)
185
+ assert_respond_to(@user, :disabled=)
186
+ end
187
+
188
+ def test_user_instance_local
189
+ assert_respond_to(@user, :local?)
190
+ assert_respond_to(@user, :local=)
191
+ end
192
+
193
+ def test_user_instance_lockout
194
+ assert_respond_to(@user, :lockout?)
195
+ assert_respond_to(@user, :lockout=)
196
+ end
197
+
198
+ def test_user_instance_password_changeable
199
+ assert_respond_to(@user, :password_changeable?)
200
+ assert_respond_to(@user, :password_changeable=)
201
+ end
202
+
203
+ def test_user_instance_password_expires
204
+ assert_respond_to(@user, :password_expires?)
205
+ assert_respond_to(@user, :password_expires=)
206
+ end
207
+
208
+ def test_user_instance_password_required
209
+ assert_respond_to(@user, :password_required?)
210
+ assert_respond_to(@user, :password_required=)
211
+ end
212
+
213
+ def test_user_instance_account_type
214
+ assert_respond_to(@user, :account_type)
215
+ assert_respond_to(@user, :account_type=)
216
+ end
217
+
218
+ def test_get_group
219
+ assert_respond_to(Admin, :get_group)
220
+ assert_raises(ArgumentError){ Admin.get_group }
221
+ end
222
+
223
+ def test_get_group_local
224
+ assert_nothing_raised{ Admin.get_group(@group_name) }
225
+ assert_kind_of(Group, Admin.get_group(@group_name))
226
+ assert_nothing_raised{ Admin.get_group(@group_id) }
227
+ assert_kind_of(Group, Admin.get_group(@group_id))
228
+ end
229
+
230
+ def test_get_group_remote
231
+ assert_nothing_raised{ Admin.get_group(@group_name, @host) }
232
+ assert_kind_of(Group, Admin.get_group(@group_name, @host))
233
+ end
234
+
235
+ def test_groups
236
+ assert_respond_to(Admin, :groups)
237
+ end
238
+
239
+ def test_groups_local
240
+ assert_nothing_raised{ Admin.groups }
241
+ assert_nothing_raised{ Admin.groups{ |g| } }
242
+ assert_kind_of(Array, Admin.groups)
243
+ assert_kind_of(Group, Admin.groups.first)
244
+ end
245
+
246
+ def test_groups_remote
247
+ assert_nothing_raised{ Admin.groups(@host) }
248
+ assert_nothing_raised{ Admin.groups(@host){ |g| } }
249
+ assert_kind_of(Array, Admin.groups(@host))
250
+ assert_kind_of(Group, Admin.groups(@host).first)
251
+ end
252
+
253
+ def test_group_instance_caption
254
+ assert_respond_to(@group, :caption)
255
+ assert_respond_to(@group, :caption=)
256
+ end
257
+
258
+ def test_group_instance_description
259
+ assert_respond_to(@group, :description)
260
+ assert_respond_to(@group, :description=)
261
+ end
262
+
263
+ def test_group_instance_domain
264
+ assert_respond_to(@group, :domain)
265
+ assert_respond_to(@group, :domain=)
266
+ end
267
+
268
+ def test_group_instance_install_date
269
+ assert_respond_to(@group, :install_date)
270
+ assert_respond_to(@group, :install_date=)
271
+ end
272
+
273
+ def test_group_instance_name
274
+ assert_respond_to(@group, :name)
275
+ assert_respond_to(@group, :name)
276
+ end
277
+
278
+ def test_group_instance_gid
279
+ assert_respond_to(@group, :gid)
280
+ assert_respond_to(@group, :gid=)
281
+ end
282
+
283
+ def test_group_instance_status
284
+ assert_respond_to(@group, :status)
285
+ assert_respond_to(@group, :status=)
286
+ end
287
+
288
+ def test_group_instance_sid
289
+ assert_respond_to(@group, :sid)
290
+ assert_respond_to(@group, :sid=)
291
+ end
292
+
293
+ def test_group_instance_sid_type
294
+ assert_respond_to(@group, :sid_type)
295
+ assert_respond_to(@group, :sid_type=)
296
+ end
297
+
298
+ def test_group_instance_local
299
+ assert_respond_to(@group, :local?)
300
+ assert_respond_to(@group, :local=)
301
+ end
302
+
303
+ def teardown
304
+ @host = nil
305
+ @user = nil
306
+ @user_name = nil
307
+ @user_id = nil
308
+ @group = nil
309
+ @group_name = nil
310
+ @group_id = nil
311
+ end
312
+ end