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.
@@ -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 "singleton methods" do
16
- describe "get_login" do
17
- example "get_login basic functionality" do
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 "get_login returns a string" do
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 "get_user" do
29
- example "get_user basic functionality" do
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 "get_user with a string argument works as expected" do
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 "get_user with an integer argument works as expected" do
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 "get_user requires at least one argument" do
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 "get_user requires a string or integer argument" do
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 "get_user raises an Error if the user cannot be found" do
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 "users" do
57
- example "users basic functionality" do
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 "users returns an array of User objects" do
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 "users accepts an optional lastlog argument on darwin", :darwin => true do
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 "get_group" do
77
- example "get_group basic functionality" do
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 "get_group accepts a string argument" do
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 "get_group accepts an integer argument" do
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 "get_group requires one argument only" do
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 "get_group raises a TypeError if an invalid type is passed" do
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 "get_group raises an Error if the group cannot be found" do
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 "groups" do
106
- example "groups basic functionality" do
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 "groups returns an array of Group objects" do
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 "groups method does not accept any arguments" do
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 "instance methods" do
124
- describe "User instance methods" do
125
- example "user.name behaves as expected" do
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 "user.passwd behaves as expected" do
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 "user.uid behaves as expected" do
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 "user.gid behaves as expected" do
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 "user.dir behaves as expected" do
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 "user.shell behaves as expected" do
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 "user.gecos behaves as expected" do
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 "user.quota behaves as expected" do
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 "user.age behaves as expected" do
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 "user.access behaves as expected" do
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 "user.comment behaves as expected" do
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 "user.expire behaves as expected" do
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 "user.change behaves as expected" do
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 "user.login_time behaves as expected" do
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 "user.login_device behaves as expected" do
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 "user.login_host behaves as expected" do
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 "user.groups behaves as expected" do
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 "Group instance methods" do
229
- example "group.name behaves as expected" do
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 "group.gid behaves as expected" do
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 "group.members behaves as expected" do
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 "group.passwd behaves as expected" do
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 "ffi functions" do
256
- example "ffi functions are private" do
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')