sys-admin 1.8.1-universal-mingw32 → 1.8.3-universal-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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGES.md +14 -0
- data/MANIFEST.md +4 -3
- data/README.md +6 -1
- data/Rakefile +5 -2
- data/lib/bsd/sys/admin.rb +37 -26
- data/lib/darwin/sys/admin.rb +22 -11
- data/lib/linux/sys/admin.rb +27 -16
- data/lib/sunos/sys/admin.rb +16 -12
- data/lib/sys/admin/common.rb +5 -4
- data/lib/sys/admin/custom.rb +6 -3
- data/lib/sys/admin.rb +7 -1
- data/lib/sys-admin.rb +2 -0
- data/lib/unix/sys/admin.rb +6 -6
- data/lib/windows/sys/admin.rb +77 -81
- data/spec/spec_helper.rb +10 -1
- data/spec/sys_admin_shared.rb +15 -0
- data/spec/sys_admin_unix_spec.rb +83 -52
- data/spec/sys_admin_windows_spec.rb +79 -86
- data/sys-admin.gemspec +11 -7
- data.tar.gz.sig +0 -0
- metadata +35 -5
- metadata.gz.sig +0 -0
- data/spec/sys_admin_version_spec.rb +0 -11
data/spec/sys_admin_unix_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
###############################################################################
|
2
4
|
# sys_admin_unix_rspec.rb
|
3
5
|
#
|
@@ -12,60 +14,60 @@ RSpec.describe Sys::Admin, :unix do
|
|
12
14
|
let(:group) { 'sys' }
|
13
15
|
let(:group_id) { 3 }
|
14
16
|
|
15
|
-
context
|
16
|
-
describe
|
17
|
-
example
|
17
|
+
context 'singleton methods' do
|
18
|
+
describe 'get_login' do
|
19
|
+
example 'get_login basic functionality' do
|
18
20
|
expect(described_class).to respond_to(:get_login)
|
19
21
|
expect{ described_class.get_login }.not_to raise_error
|
20
22
|
end
|
21
23
|
|
22
|
-
example
|
24
|
+
example 'get_login returns a string' do
|
23
25
|
expect(described_class.get_login).to be_kind_of(String)
|
24
26
|
expect(described_class.get_login.length).to be > 0
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
|
-
describe
|
29
|
-
example
|
30
|
+
describe 'get_user' do
|
31
|
+
example 'get_user basic functionality' do
|
30
32
|
expect(described_class).to respond_to(:get_user)
|
31
33
|
expect{ described_class.get_user(user) }.not_to raise_error
|
32
34
|
expect{ described_class.get_user(user_id) }.not_to raise_error
|
33
35
|
end
|
34
36
|
|
35
|
-
example
|
37
|
+
example 'get_user with a string argument works as expected' do
|
36
38
|
expect(described_class.get_user(user)).to be_kind_of(Sys::Admin::User)
|
37
39
|
end
|
38
40
|
|
39
|
-
example
|
41
|
+
example 'get_user with an integer argument works as expected' do
|
40
42
|
expect(described_class.get_user(user_id)).to be_kind_of(Sys::Admin::User)
|
41
43
|
end
|
42
44
|
|
43
|
-
example
|
45
|
+
example 'get_user requires at least one argument' do
|
44
46
|
expect{ described_class.get_user }.to raise_error(ArgumentError)
|
45
47
|
end
|
46
48
|
|
47
|
-
example
|
49
|
+
example 'get_user requires a string or integer argument' do
|
48
50
|
expect{ described_class.get_user([]) }.to raise_error(TypeError)
|
49
51
|
end
|
50
52
|
|
51
|
-
example
|
53
|
+
example 'get_user raises an Error if the user cannot be found' do
|
52
54
|
expect{ described_class.get_user('foofoofoo') }.to raise_error(Sys::Admin::Error)
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
56
|
-
describe
|
57
|
-
example
|
58
|
+
describe 'users' do
|
59
|
+
example 'users basic functionality' do
|
58
60
|
expect(described_class).to respond_to(:users)
|
59
61
|
expect{ described_class.users }.not_to raise_error
|
60
62
|
end
|
61
63
|
|
62
|
-
example
|
64
|
+
example 'users returns an array of User objects' do
|
63
65
|
users = described_class.users
|
64
66
|
expect(users).to be_kind_of(Array)
|
65
67
|
expect(users).to all(be_kind_of(Sys::Admin::User))
|
66
68
|
end
|
67
69
|
|
68
|
-
example
|
70
|
+
example 'users accepts an optional lastlog argument on darwin', :darwin => true do
|
69
71
|
users = described_class.users(:lastlog => false)
|
70
72
|
expect(users).to be_kind_of(Array)
|
71
73
|
expect(users).to all(be_kind_of(Sys::Admin::User))
|
@@ -73,178 +75,207 @@ RSpec.describe Sys::Admin, :unix do
|
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
76
|
-
describe
|
77
|
-
|
78
|
+
describe 'get_group' do
|
79
|
+
before do
|
80
|
+
described_class.class_eval do
|
81
|
+
public :getgrgid_r
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
example 'get_group basic functionality' do
|
78
86
|
expect(described_class).to respond_to(:get_group)
|
79
87
|
expect{ described_class.get_group(group) }.not_to raise_error
|
80
88
|
expect{ described_class.get_group(group_id) }.not_to raise_error
|
81
89
|
end
|
82
90
|
|
83
|
-
example
|
91
|
+
example 'get_group accepts a string argument' do
|
84
92
|
expect(described_class.get_group(group)).to be_kind_of(Sys::Admin::Group)
|
85
93
|
end
|
86
94
|
|
87
|
-
example
|
95
|
+
example 'get_group accepts an integer argument' do
|
88
96
|
expect(described_class.get_group(group_id)).to be_kind_of(Sys::Admin::Group)
|
89
97
|
end
|
90
98
|
|
91
|
-
example
|
99
|
+
example 'get_group requires one argument only' do
|
92
100
|
expect{ described_class.get_group }.to raise_error(ArgumentError)
|
93
101
|
expect{ described_class.get_group(group_id, group_id) }.to raise_error(ArgumentError)
|
94
102
|
end
|
95
103
|
|
96
|
-
example
|
104
|
+
example 'get_group raises a TypeError if an invalid type is passed' do
|
97
105
|
expect{ described_class.get_group([]) }.to raise_error(TypeError)
|
98
106
|
end
|
99
107
|
|
100
|
-
example
|
108
|
+
example 'get_group raises an Error if the group cannot be found' do
|
109
|
+
expect{ described_class.get_group(123456789) }.to raise_error(Sys::Admin::Error)
|
101
110
|
expect{ described_class.get_group('foofoofoo') }.to raise_error(Sys::Admin::Error)
|
102
111
|
end
|
112
|
+
|
113
|
+
example 'get_group handles large groups and will retry an ERANGE' do
|
114
|
+
allow(Sys::Admin).to receive(:getgrgid_r).with(any_args).and_return(34)
|
115
|
+
allow(Sys::Admin).to receive(:getgrgid_r).with(any_args).and_call_original
|
116
|
+
expect{ described_class.get_group(group_id) }.not_to raise_error
|
117
|
+
end
|
118
|
+
|
119
|
+
example 'get_group will raise the expected error for an ENOENT' do
|
120
|
+
allow(Sys::Admin).to receive(:getgrgid_r).with(any_args).and_return(2)
|
121
|
+
expect{ described_class.get_group(group_id) }.to raise_error(Sys::Admin::Error)
|
122
|
+
end
|
123
|
+
|
124
|
+
example 'get_group will raise the expected error for a failed getgrxxx function call' do
|
125
|
+
allow(Sys::Admin).to receive(:getgrgid_r).with(any_args).and_return(22)
|
126
|
+
allow_any_instance_of(FFI::MemoryPointer).to receive(:null?).and_return(true)
|
127
|
+
expect{ described_class.get_group(group_id) }.to raise_error(Errno::EINVAL)
|
128
|
+
end
|
129
|
+
|
130
|
+
example 'get_group will not retry failures other than an ERANGE' do
|
131
|
+
allow(Sys::Admin).to receive(:getgrgid_r).with(any_args).and_return(35)
|
132
|
+
expect{ described_class.get_group(group_id) }.to raise_error(Sys::Admin::Error)
|
133
|
+
end
|
103
134
|
end
|
104
135
|
|
105
|
-
describe
|
106
|
-
example
|
136
|
+
describe 'groups' do
|
137
|
+
example 'groups basic functionality' do
|
107
138
|
expect(described_class).to respond_to(:groups)
|
108
139
|
expect{ described_class.groups }.not_to raise_error
|
109
140
|
end
|
110
141
|
|
111
|
-
example
|
142
|
+
example 'groups returns an array of Group objects' do
|
112
143
|
groups = described_class.groups
|
113
144
|
expect(groups).to be_kind_of(Array)
|
114
145
|
expect(groups).to all(be_kind_of(Sys::Admin::Group))
|
115
146
|
end
|
116
147
|
|
117
|
-
example
|
148
|
+
example 'groups method does not accept any arguments' do
|
118
149
|
expect{ described_class.groups(group_id) }.to raise_error(ArgumentError)
|
119
150
|
end
|
120
151
|
end
|
121
152
|
end
|
122
153
|
|
123
|
-
context
|
124
|
-
describe
|
125
|
-
example
|
154
|
+
context 'instance methods' do
|
155
|
+
describe 'User instance methods' do
|
156
|
+
example 'user.name behaves as expected' do
|
126
157
|
user = described_class.get_user(user_id)
|
127
158
|
expect(user).to respond_to(:name)
|
128
159
|
expect(user.name).to be_kind_of(String)
|
129
160
|
end
|
130
161
|
|
131
|
-
example
|
162
|
+
example 'user.passwd behaves as expected' do
|
132
163
|
user = described_class.get_user(user_id)
|
133
164
|
expect(user).to respond_to(:passwd)
|
134
165
|
expect(user.passwd).to be_kind_of(String)
|
135
166
|
end
|
136
167
|
|
137
|
-
example
|
168
|
+
example 'user.uid behaves as expected' do
|
138
169
|
user = described_class.get_user(user_id)
|
139
170
|
expect(user).to respond_to(:uid)
|
140
171
|
expect(user.uid).to be_kind_of(Integer)
|
141
172
|
end
|
142
173
|
|
143
|
-
example
|
174
|
+
example 'user.gid behaves as expected' do
|
144
175
|
user = described_class.get_user(user_id)
|
145
176
|
expect(user).to respond_to(:gid)
|
146
177
|
expect(user.gid).to be_kind_of(Integer)
|
147
178
|
end
|
148
179
|
|
149
|
-
example
|
180
|
+
example 'user.dir behaves as expected' do
|
150
181
|
user = described_class.get_user(user_id)
|
151
182
|
expect(user).to respond_to(:dir)
|
152
183
|
expect(user.dir).to be_kind_of(String)
|
153
184
|
end
|
154
185
|
|
155
|
-
example
|
186
|
+
example 'user.shell behaves as expected' do
|
156
187
|
user = described_class.get_user(user_id)
|
157
188
|
expect(user).to respond_to(:shell)
|
158
189
|
expect(user.shell).to be_kind_of(String)
|
159
190
|
end
|
160
191
|
|
161
|
-
example
|
192
|
+
example 'user.gecos behaves as expected' do
|
162
193
|
user = described_class.get_user(user_id)
|
163
194
|
expect(user).to respond_to(:gecos)
|
164
195
|
expect(user.gecos).to be_kind_of(String).or be_nil
|
165
196
|
end
|
166
197
|
|
167
|
-
example
|
198
|
+
example 'user.quota behaves as expected' do
|
168
199
|
user = described_class.get_user(user_id)
|
169
200
|
expect(user).to respond_to(:quota)
|
170
201
|
expect(user.quota).to be_kind_of(Integer).or be_nil
|
171
202
|
end
|
172
203
|
|
173
|
-
example
|
204
|
+
example 'user.age behaves as expected' do
|
174
205
|
user = described_class.get_user(user_id)
|
175
206
|
expect(user).to respond_to(:age)
|
176
207
|
expect(user.age).to be_kind_of(Integer).or be_nil
|
177
208
|
end
|
178
209
|
|
179
|
-
example
|
210
|
+
example 'user.access behaves as expected' do
|
180
211
|
user = described_class.get_user(user_id)
|
181
212
|
expect(user).to respond_to(:access_class)
|
182
213
|
expect(user.access_class).to be_kind_of(String).or be_nil
|
183
214
|
end
|
184
215
|
|
185
|
-
example
|
216
|
+
example 'user.comment behaves as expected' do
|
186
217
|
user = described_class.get_user(user_id)
|
187
218
|
expect(user).to respond_to(:comment)
|
188
219
|
expect(user.comment).to be_kind_of(String).or be_nil
|
189
220
|
end
|
190
221
|
|
191
|
-
example
|
222
|
+
example 'user.expire behaves as expected' do
|
192
223
|
user = described_class.get_user(user_id)
|
193
224
|
expect(user).to respond_to(:expire)
|
194
225
|
expect(user.expire).to be_kind_of(Time).or be_nil
|
195
226
|
end
|
196
227
|
|
197
|
-
example
|
228
|
+
example 'user.change behaves as expected' do
|
198
229
|
user = described_class.get_user(user_id)
|
199
230
|
expect(user).to respond_to(:change)
|
200
231
|
expect(user.change).to be_kind_of(Time).or be_nil
|
201
232
|
end
|
202
233
|
|
203
|
-
example
|
234
|
+
example 'user.login_time behaves as expected' do
|
204
235
|
user = described_class.get_user(user_id)
|
205
236
|
expect(user).to respond_to(:login_time)
|
206
237
|
expect(user.login_time).to be_kind_of(Time).or be_nil
|
207
238
|
end
|
208
239
|
|
209
|
-
example
|
240
|
+
example 'user.login_device behaves as expected' do
|
210
241
|
user = described_class.get_user(user_id)
|
211
242
|
expect(user).to respond_to(:login_device)
|
212
243
|
expect(user.login_device).to be_kind_of(String).or be_nil
|
213
244
|
end
|
214
245
|
|
215
|
-
example
|
246
|
+
example 'user.login_host behaves as expected' do
|
216
247
|
user = described_class.get_user(user_id)
|
217
248
|
expect(user).to respond_to(:login_host)
|
218
249
|
expect(user.login_host).to be_kind_of(String).or be_nil
|
219
250
|
end
|
220
251
|
|
221
|
-
example
|
252
|
+
example 'user.groups behaves as expected' do
|
222
253
|
user = described_class.get_user(user_id)
|
223
254
|
expect(user).to respond_to(:groups)
|
224
255
|
expect(user.groups).to be_kind_of(Array)
|
225
256
|
end
|
226
257
|
end
|
227
258
|
|
228
|
-
describe
|
229
|
-
example
|
259
|
+
describe 'Group instance methods' do
|
260
|
+
example 'group.name behaves as expected' do
|
230
261
|
group = described_class.get_group(group_id)
|
231
262
|
expect(group).to respond_to(:name)
|
232
263
|
expect(group.name).to be_kind_of(String)
|
233
264
|
end
|
234
265
|
|
235
|
-
example
|
266
|
+
example 'group.gid behaves as expected' do
|
236
267
|
group = described_class.get_group(group_id)
|
237
268
|
expect(group).to respond_to(:gid)
|
238
269
|
expect(group.gid).to be_kind_of(Integer)
|
239
270
|
end
|
240
271
|
|
241
|
-
example
|
272
|
+
example 'group.members behaves as expected' do
|
242
273
|
group = described_class.get_group(group_id)
|
243
274
|
expect(group).to respond_to(:members)
|
244
275
|
expect(group.members).to be_kind_of(Array)
|
245
276
|
end
|
246
277
|
|
247
|
-
example
|
278
|
+
example 'group.passwd behaves as expected' do
|
248
279
|
group = described_class.get_group(group_id)
|
249
280
|
expect(group).to respond_to(:passwd)
|
250
281
|
expect(group.passwd).to be_kind_of(String)
|
@@ -252,8 +283,8 @@ RSpec.describe Sys::Admin, :unix do
|
|
252
283
|
end
|
253
284
|
end
|
254
285
|
|
255
|
-
context
|
256
|
-
example
|
286
|
+
context 'ffi functions' do
|
287
|
+
example 'ffi functions are private' do
|
257
288
|
methods = described_class.methods(false).map(&:to_s)
|
258
289
|
expect(methods).not_to include('getlogin')
|
259
290
|
expect(methods).not_to include('getlogin_r')
|