sys-admin 1.6.4 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,31 +1,31 @@
1
- # Do not use this file directly. Build the gem via the Rake tasks.
2
- require 'rubygems'
3
-
4
- Gem::Specification.new do |spec|
5
- spec.name = 'sys-admin'
6
- spec.version = '1.6.4'
7
- spec.author = 'Daniel J. Berger'
8
- spec.license = 'Artistic 2.0'
9
- spec.email = 'djberg96@gmail.com'
10
- spec.homepage = 'http://www.github.com/djberg96/sysutils'
11
- spec.summary = 'A unified, cross platform replacement for the "etc" library.'
12
- spec.test_file = 'test/test_sys_admin.rb'
13
- spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
14
- spec.cert_chain = ['certs/djberg96_pub.pem']
15
-
16
- spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
17
- spec.rubyforge_project = 'sysutils'
18
-
19
- spec.add_dependency('ffi', '>= 1.1.0')
20
-
21
- spec.add_development_dependency('test-unit', '>= 2.5.0')
22
- spec.add_development_dependency('rake')
23
-
24
- spec.description = <<-EOF
25
- The sys-admin library is a unified, cross platform replacement for the
26
- 'etc' library that ships as part of the Ruby standard library. It
27
- provides a common interface for all platforms, including MS Windows. In
28
- addition, it provides an interface for adding, deleting and configuring
29
- users on MS Windows.
30
- EOF
31
- end
1
+ # Do not use this file directly. Build the gem via the Rake tasks.
2
+ require 'rubygems'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'sys-admin'
6
+ spec.version = '1.7.0'
7
+ spec.author = 'Daniel J. Berger'
8
+ spec.license = 'Apache 2.0'
9
+ spec.email = 'djberg96@gmail.com'
10
+ spec.homepage = 'http://www.github.com/djberg96/sysutils'
11
+ spec.summary = 'A unified, cross platform replacement for the "etc" library.'
12
+ spec.test_file = 'test/test_sys_admin.rb'
13
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
14
+ spec.cert_chain = ['certs/djberg96_pub.pem']
15
+
16
+ spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
17
+ spec.rubyforge_project = 'sysutils'
18
+
19
+ spec.add_dependency('ffi', '>= 1.1.0')
20
+
21
+ spec.add_development_dependency('test-unit', '>= 2.5.0')
22
+ spec.add_development_dependency('rake')
23
+
24
+ spec.description = <<-EOF
25
+ The sys-admin library is a unified, cross platform replacement for the
26
+ 'etc' library that ships as part of the Ruby standard library. It
27
+ provides a common interface for all platforms, including MS Windows. In
28
+ addition, it provides an interface for adding, deleting and configuring
29
+ users on MS Windows.
30
+ EOF
31
+ end
@@ -1,19 +1,19 @@
1
- ###############################################################################
2
- # test_sys_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
- require 'test-unit'
8
-
9
- if File::ALT_SEPARATOR
10
- require 'test_sys_admin_windows'
11
- else
12
- require 'test_sys_admin_unix'
13
- end
14
-
15
- class TC_Sys_Admin_All < Test::Unit::TestCase
16
- test "version is set to expected value" do
17
- assert_equal('1.6.4', Sys::Admin::VERSION)
18
- end
19
- end
1
+ ###############################################################################
2
+ # test_sys_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
+ require 'test-unit'
8
+
9
+ if File::ALT_SEPARATOR
10
+ require 'test_sys_admin_windows'
11
+ else
12
+ require 'test_sys_admin_unix'
13
+ end
14
+
15
+ class TC_Sys_Admin_All < Test::Unit::TestCase
16
+ test "version is set to expected value" do
17
+ assert_equal('1.7.0', Sys::Admin::VERSION)
18
+ end
19
+ end
@@ -1,260 +1,260 @@
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
- @group = 'sys'
16
- @group_id = 3
17
- end
18
-
19
- ## Admin singleton methods
20
-
21
- test "get_login basic functionality" do
22
- assert_respond_to(Admin, :get_login)
23
- assert_nothing_raised{ Admin.get_login }
24
- end
25
-
26
- test "get_login returns a string" do
27
- assert_kind_of(String, Admin.get_login)
28
- assert_true(Admin.get_login.length > 0)
29
- end
30
-
31
- test "get_user basic functionality" do
32
- assert_respond_to(Admin, :get_user)
33
- assert_nothing_raised{ Admin.get_user(@user) }
34
- assert_nothing_raised{ Admin.get_user(@user_id) }
35
- end
36
-
37
- test "get_user with a string argument works as expected" do
38
- assert_kind_of(Admin::User, Admin.get_user(@user))
39
- end
40
-
41
- test "get_user with an integer argument works as expected" do
42
- assert_kind_of(Admin::User, Admin.get_user(@user_id))
43
- end
44
-
45
- test "get_user requires one argument only" do
46
- assert_raise(ArgumentError){ Admin.get_user }
47
- assert_raise(ArgumentError){ Admin.get_user(@user, @user) }
48
- end
49
-
50
- test "get_user requires a string or integer argument" do
51
- assert_raise(TypeError){ Admin.get_user([]) }
52
- end
53
-
54
- test "get_user raises an Error if the user cannot be found" do
55
- assert_raise(Admin::Error){ Admin.get_user('foofoofoo') }
56
- end
57
-
58
- test "users basic functionality" do
59
- assert_respond_to(Admin, :users)
60
- assert_nothing_raised{ Admin.users }
61
- end
62
-
63
- test "users returns an array of User objects" do
64
- users = Admin.users
65
- assert_kind_of(Array, users)
66
- assert_kind_of(Admin::User, users.first)
67
- end
68
-
69
- test "users does not accept any arguments" do
70
- assert_raise(ArgumentError){ Admin.users(@user_id) }
71
- end
72
-
73
- test "get_group basic functionality" do
74
- assert_respond_to(Admin, :get_group)
75
- assert_nothing_raised{ Admin.get_group(@group) }
76
- assert_nothing_raised{ Admin.get_group(@group_id) }
77
- end
78
-
79
- test "get_group accepts a string argument" do
80
- assert_kind_of(Admin::Group, Admin.get_group(@group))
81
- end
82
-
83
- test "get_group accepts an integer argument" do
84
- assert_kind_of(Admin::Group, Admin.get_group(@group_id))
85
- end
86
-
87
- test "get_group requires one argument only" do
88
- assert_raise(ArgumentError){ Admin.get_group }
89
- assert_raise(ArgumentError){ Admin.get_group(@group_id, @group_id) }
90
- end
91
-
92
- test "get_group raises a TypeError if an invalid type is passed" do
93
- assert_raise(TypeError){ Admin.get_group([]) }
94
- end
95
-
96
- test "get_group raises an Error if the group cannot be found" do
97
- assert_raise(Admin::Error){ Admin.get_group('foofoofoo') }
98
- end
99
-
100
- test "groups basic functionality" do
101
- assert_respond_to(Admin, :groups)
102
- assert_nothing_raised{ Admin.groups }
103
- end
104
-
105
- test "groups returns an array of Group objects" do
106
- groups = Admin.groups
107
- assert_kind_of(Array, groups)
108
- assert_kind_of(Admin::Group, groups.first)
109
- end
110
-
111
- test "groups method does not accept any arguments" do
112
- assert_raise(ArgumentError){ Admin.groups(@group_id) }
113
- end
114
-
115
- ## User Tests
116
-
117
- test "user.name behaves as expected" do
118
- @user = Admin.get_user(@user_id)
119
- assert_respond_to(@user, :name)
120
- assert_kind_of(String, @user.name)
121
- end
122
-
123
- test "user.passwd behaves as expected" do
124
- @user = Admin.get_user(@user_id)
125
- assert_respond_to(@user, :passwd)
126
- assert_kind_of(String, @user.passwd)
127
- end
128
-
129
- test "user.uid behaves as expected" do
130
- @user = Admin.get_user(@user_id)
131
- assert_respond_to(@user, :uid)
132
- assert_kind_of(Fixnum, @user.uid)
133
- end
134
-
135
- test "user.gid behaves as expected" do
136
- @user = Admin.get_user(@user_id)
137
- assert_respond_to(@user, :gid)
138
- assert_kind_of(Fixnum, @user.gid)
139
- end
140
-
141
- test "user.dir behaves as expected" do
142
- @user = Admin.get_user(@user_id)
143
- assert_respond_to(@user, :dir)
144
- assert_kind_of(String, @user.dir)
145
- end
146
-
147
- test "user.shell behaves as expected" do
148
- @user = Admin.get_user(@user_id)
149
- assert_respond_to(@user, :shell)
150
- assert_kind_of(String, @user.shell)
151
- end
152
-
153
- test "user.gecos behaves as expected" do
154
- @user = Admin.get_user(@user_id)
155
- assert_respond_to(@user, :gecos)
156
- assert_kind_of([String, NilClass], @user.gecos)
157
- end
158
-
159
- test "user.quota behaves as expected" do
160
- @user = Admin.get_user(@user_id)
161
- assert_respond_to(@user, :quota)
162
- assert_true([Fixnum, NilClass].include?(@user.quota.class))
163
- end
164
-
165
- test "user.age behaves as expected" do
166
- @user = Admin.get_user(@user_id)
167
- assert_respond_to(@user, :age)
168
- assert_true([Fixnum, NilClass].include?(@user.age.class))
169
- end
170
-
171
- test "user.access behaves as expected" do
172
- @user = Admin.get_user(@user_id)
173
- assert_respond_to(@user, :access_class)
174
- assert_true([String, NilClass].include?(@user.access_class.class))
175
- end
176
-
177
- test "user.comment behaves as expected" do
178
- @user = Admin.get_user(@user_id)
179
- assert_respond_to(@user, :comment)
180
- assert_true([String, NilClass].include?(@user.comment.class))
181
- end
182
-
183
- test "user.expire behaves as expected" do
184
- @user = Admin.get_user(@user_id)
185
- assert_respond_to(@user, :expire)
186
- assert_true([Time, NilClass].include?(@user.expire.class))
187
- end
188
-
189
- test "user.change behaves as expected" do
190
- @user = Admin.get_user(@user_id)
191
- assert_respond_to(@user, :change)
192
- assert_true([Time, NilClass].include?(@user.change.class))
193
- end
194
-
195
- test "user.login_time behaves as expected" do
196
- @user = Admin.get_user(@user_id)
197
- assert_respond_to(@user, :login_time)
198
- assert_true([Time, NilClass].include?(@user.login_time.class))
199
- end
200
-
201
- test "user.login_device behaves as expected" do
202
- @user = Admin.get_user(@user_id)
203
- assert_respond_to(@user, :login_device)
204
- assert_true([String, NilClass].include?(@user.login_device.class))
205
- end
206
-
207
- test "user.login_host behaves as expected" do
208
- @user = Admin.get_user(@user_id)
209
- assert_respond_to(@user, :login_host)
210
- assert_true([String, NilClass].include?(@user.login_host.class))
211
- end
212
-
213
- test "user.groups behaves as expected" do
214
- @user = Admin.get_user(@user_id)
215
- assert_respond_to(@user, :groups)
216
- assert_kind_of(Array, @user.groups)
217
- end
218
-
219
- ## Group Tests
220
-
221
- test "group.name behaves as expected" do
222
- @group = Admin.get_group(@group_id)
223
- assert_respond_to(@group, :name)
224
- assert_kind_of(String, @group.name)
225
- end
226
-
227
- test "group.gid behaves as expected" do
228
- @group = Admin.get_group(@group_id)
229
- assert_respond_to(@group, :gid)
230
- assert_kind_of(Fixnum, @group.gid)
231
- end
232
-
233
- test "group.members behaves as expected" do
234
- @group = Admin.get_group(@group_id)
235
- assert_respond_to(@group, :members)
236
- assert_kind_of(Array, @group.members)
237
- end
238
-
239
- test "group.passwd behaves as expected" do
240
- @group = Admin.get_group(@group_id)
241
- assert_respond_to(@group, :passwd)
242
- assert_kind_of(String, @group.passwd)
243
- end
244
-
245
- ## FFI
246
-
247
- test "ffi functions are private" do
248
- methods = Admin.methods(false).map{ |e| e.to_s }
249
- assert_false(methods.include?('getlogin'))
250
- assert_false(methods.include?('getlogin_r'))
251
- assert_false(methods.include?('strerror'))
252
- end
253
-
254
- def teardown
255
- @user = nil
256
- @user_id = nil
257
- @group = nil
258
- @group_id = nil
259
- end
260
- end
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
+ @group = 'sys'
16
+ @group_id = 3
17
+ end
18
+
19
+ ## Admin singleton methods
20
+
21
+ test "get_login basic functionality" do
22
+ assert_respond_to(Admin, :get_login)
23
+ assert_nothing_raised{ Admin.get_login }
24
+ end
25
+
26
+ test "get_login returns a string" do
27
+ assert_kind_of(String, Admin.get_login)
28
+ assert_true(Admin.get_login.length > 0)
29
+ end
30
+
31
+ test "get_user basic functionality" do
32
+ assert_respond_to(Admin, :get_user)
33
+ assert_nothing_raised{ Admin.get_user(@user) }
34
+ assert_nothing_raised{ Admin.get_user(@user_id) }
35
+ end
36
+
37
+ test "get_user with a string argument works as expected" do
38
+ assert_kind_of(Admin::User, Admin.get_user(@user))
39
+ end
40
+
41
+ test "get_user with an integer argument works as expected" do
42
+ assert_kind_of(Admin::User, Admin.get_user(@user_id))
43
+ end
44
+
45
+ test "get_user requires one argument only" do
46
+ assert_raise(ArgumentError){ Admin.get_user }
47
+ assert_raise(ArgumentError){ Admin.get_user(@user, @user) }
48
+ end
49
+
50
+ test "get_user requires a string or integer argument" do
51
+ assert_raise(TypeError){ Admin.get_user([]) }
52
+ end
53
+
54
+ test "get_user raises an Error if the user cannot be found" do
55
+ assert_raise(Admin::Error){ Admin.get_user('foofoofoo') }
56
+ end
57
+
58
+ test "users basic functionality" do
59
+ assert_respond_to(Admin, :users)
60
+ assert_nothing_raised{ Admin.users }
61
+ end
62
+
63
+ test "users returns an array of User objects" do
64
+ users = Admin.users
65
+ assert_kind_of(Array, users)
66
+ assert_kind_of(Admin::User, users.first)
67
+ end
68
+
69
+ test "users does not accept any arguments" do
70
+ assert_raise(ArgumentError){ Admin.users(@user_id) }
71
+ end
72
+
73
+ test "get_group basic functionality" do
74
+ assert_respond_to(Admin, :get_group)
75
+ assert_nothing_raised{ Admin.get_group(@group) }
76
+ assert_nothing_raised{ Admin.get_group(@group_id) }
77
+ end
78
+
79
+ test "get_group accepts a string argument" do
80
+ assert_kind_of(Admin::Group, Admin.get_group(@group))
81
+ end
82
+
83
+ test "get_group accepts an integer argument" do
84
+ assert_kind_of(Admin::Group, Admin.get_group(@group_id))
85
+ end
86
+
87
+ test "get_group requires one argument only" do
88
+ assert_raise(ArgumentError){ Admin.get_group }
89
+ assert_raise(ArgumentError){ Admin.get_group(@group_id, @group_id) }
90
+ end
91
+
92
+ test "get_group raises a TypeError if an invalid type is passed" do
93
+ assert_raise(TypeError){ Admin.get_group([]) }
94
+ end
95
+
96
+ test "get_group raises an Error if the group cannot be found" do
97
+ assert_raise(Admin::Error){ Admin.get_group('foofoofoo') }
98
+ end
99
+
100
+ test "groups basic functionality" do
101
+ assert_respond_to(Admin, :groups)
102
+ assert_nothing_raised{ Admin.groups }
103
+ end
104
+
105
+ test "groups returns an array of Group objects" do
106
+ groups = Admin.groups
107
+ assert_kind_of(Array, groups)
108
+ assert_kind_of(Admin::Group, groups.first)
109
+ end
110
+
111
+ test "groups method does not accept any arguments" do
112
+ assert_raise(ArgumentError){ Admin.groups(@group_id) }
113
+ end
114
+
115
+ ## User Tests
116
+
117
+ test "user.name behaves as expected" do
118
+ @user = Admin.get_user(@user_id)
119
+ assert_respond_to(@user, :name)
120
+ assert_kind_of(String, @user.name)
121
+ end
122
+
123
+ test "user.passwd behaves as expected" do
124
+ @user = Admin.get_user(@user_id)
125
+ assert_respond_to(@user, :passwd)
126
+ assert_kind_of(String, @user.passwd)
127
+ end
128
+
129
+ test "user.uid behaves as expected" do
130
+ @user = Admin.get_user(@user_id)
131
+ assert_respond_to(@user, :uid)
132
+ assert_kind_of(Fixnum, @user.uid)
133
+ end
134
+
135
+ test "user.gid behaves as expected" do
136
+ @user = Admin.get_user(@user_id)
137
+ assert_respond_to(@user, :gid)
138
+ assert_kind_of(Fixnum, @user.gid)
139
+ end
140
+
141
+ test "user.dir behaves as expected" do
142
+ @user = Admin.get_user(@user_id)
143
+ assert_respond_to(@user, :dir)
144
+ assert_kind_of(String, @user.dir)
145
+ end
146
+
147
+ test "user.shell behaves as expected" do
148
+ @user = Admin.get_user(@user_id)
149
+ assert_respond_to(@user, :shell)
150
+ assert_kind_of(String, @user.shell)
151
+ end
152
+
153
+ test "user.gecos behaves as expected" do
154
+ @user = Admin.get_user(@user_id)
155
+ assert_respond_to(@user, :gecos)
156
+ assert_kind_of([String, NilClass], @user.gecos)
157
+ end
158
+
159
+ test "user.quota behaves as expected" do
160
+ @user = Admin.get_user(@user_id)
161
+ assert_respond_to(@user, :quota)
162
+ assert_true([Fixnum, NilClass].include?(@user.quota.class))
163
+ end
164
+
165
+ test "user.age behaves as expected" do
166
+ @user = Admin.get_user(@user_id)
167
+ assert_respond_to(@user, :age)
168
+ assert_true([Fixnum, NilClass].include?(@user.age.class))
169
+ end
170
+
171
+ test "user.access behaves as expected" do
172
+ @user = Admin.get_user(@user_id)
173
+ assert_respond_to(@user, :access_class)
174
+ assert_true([String, NilClass].include?(@user.access_class.class))
175
+ end
176
+
177
+ test "user.comment behaves as expected" do
178
+ @user = Admin.get_user(@user_id)
179
+ assert_respond_to(@user, :comment)
180
+ assert_true([String, NilClass].include?(@user.comment.class))
181
+ end
182
+
183
+ test "user.expire behaves as expected" do
184
+ @user = Admin.get_user(@user_id)
185
+ assert_respond_to(@user, :expire)
186
+ assert_true([Time, NilClass].include?(@user.expire.class))
187
+ end
188
+
189
+ test "user.change behaves as expected" do
190
+ @user = Admin.get_user(@user_id)
191
+ assert_respond_to(@user, :change)
192
+ assert_true([Time, NilClass].include?(@user.change.class))
193
+ end
194
+
195
+ test "user.login_time behaves as expected" do
196
+ @user = Admin.get_user(@user_id)
197
+ assert_respond_to(@user, :login_time)
198
+ assert_true([Time, NilClass].include?(@user.login_time.class))
199
+ end
200
+
201
+ test "user.login_device behaves as expected" do
202
+ @user = Admin.get_user(@user_id)
203
+ assert_respond_to(@user, :login_device)
204
+ assert_true([String, NilClass].include?(@user.login_device.class))
205
+ end
206
+
207
+ test "user.login_host behaves as expected" do
208
+ @user = Admin.get_user(@user_id)
209
+ assert_respond_to(@user, :login_host)
210
+ assert_true([String, NilClass].include?(@user.login_host.class))
211
+ end
212
+
213
+ test "user.groups behaves as expected" do
214
+ @user = Admin.get_user(@user_id)
215
+ assert_respond_to(@user, :groups)
216
+ assert_kind_of(Array, @user.groups)
217
+ end
218
+
219
+ ## Group Tests
220
+
221
+ test "group.name behaves as expected" do
222
+ @group = Admin.get_group(@group_id)
223
+ assert_respond_to(@group, :name)
224
+ assert_kind_of(String, @group.name)
225
+ end
226
+
227
+ test "group.gid behaves as expected" do
228
+ @group = Admin.get_group(@group_id)
229
+ assert_respond_to(@group, :gid)
230
+ assert_kind_of(Fixnum, @group.gid)
231
+ end
232
+
233
+ test "group.members behaves as expected" do
234
+ @group = Admin.get_group(@group_id)
235
+ assert_respond_to(@group, :members)
236
+ assert_kind_of(Array, @group.members)
237
+ end
238
+
239
+ test "group.passwd behaves as expected" do
240
+ @group = Admin.get_group(@group_id)
241
+ assert_respond_to(@group, :passwd)
242
+ assert_kind_of(String, @group.passwd)
243
+ end
244
+
245
+ ## FFI
246
+
247
+ test "ffi functions are private" do
248
+ methods = Admin.methods(false).map{ |e| e.to_s }
249
+ assert_false(methods.include?('getlogin'))
250
+ assert_false(methods.include?('getlogin_r'))
251
+ assert_false(methods.include?('strerror'))
252
+ end
253
+
254
+ def teardown
255
+ @user = nil
256
+ @user_id = nil
257
+ @group = nil
258
+ @group_id = nil
259
+ end
260
+ end