forked from puppetlabs/puppetlabs-wsus_client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsus_client_spec.rb
295 lines (264 loc) · 9.58 KB
/
wsus_client_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
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
require 'spec_helper_acceptance'
RSpec.describe 'wsus_client' do
let(:reg_type) { :type_dword_converted }
base_key = 'HKLM\\Software\\Policies\\Microsoft\\Windows\\WindowsUpdate'
au_key = "#{base_key}\\AU"
def clear_registry
pp = <<-PP
service {'wuauserv':
ensure => stopped,
}->
registry_key{'HKLM\\Software\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU':
ensure => absent,
purge_values => true,
}->
registry_key{'HKLM\\Software\\Policies\\Microsoft\\Windows\\WindowsUpdate':
ensure => absent,
purge_values => true,
}
PP
apply_manifest_on(default, pp, :catch_failures => false)
end
def create_apply_manifest(params, clear_first = true)
if clear_first
clear_registry
end
pp = "class {'wsus_client':"
params.each { |k, v|
v = "'#{v}'" if v.is_a? String
pp << "\n #{k.to_s} => #{v},"
}
pp << "}"
apply_manifest_on(default, pp, :catch_failures => true)
end
shared_examples 'registry_value' do |property, key = base_key|
describe windows_registry_key(key) do
it { should exist }
it {
if !reg_data.nil?
should have_property_value(property, reg_type, reg_data)
end
should have_property(property, reg_type)
}
end
end
shared_examples 'registry_value undefined' do |property, key = base_key|
describe windows_registry_key(key) do
it { should_not have_property(property, reg_type) }
end
end
shared_examples 'boolean values' do |param, property, key = base_key|
[true, false].each do |enabled|
describe "#{enabled}" do
it { create_apply_manifest param => enabled }
let(:reg_data) { enabled ? 1 : 0 }
it_behaves_like 'registry_value', property, key
end
end
end
shared_examples 'enabled range' do |param, property, array_range, key = base_key|
array_range.each do |valid_value|
describe "#{valid_value}" do
before :all do
create_apply_manifest param => valid_value
end
describe windows_registry_key(key) do
it { should exist }
it { should have_property_value(property, :type_dword_converted, valid_value) }
it { should have_property_value("#{property}Enabled", :type_dword_converted, 1) }
end
end
end
describe 'false' do
it { create_apply_manifest param => false }
describe windows_registry_key(key) do
it { should exist }
it { should have_property_value("#{property}Enabled", :type_dword_converted, 0) }
end
end
end
context "server_url =>", {:testrail => ['70183', '70185', '70184']} do
let(:reg_type) { :type_string }
['http://SERVER:8530', 'https://SERVER:8531'].each do |wsus_url|
describe wsus_url do
let(:reg_data) { wsus_url }
it { create_apply_manifest :server_url => wsus_url }
it_behaves_like 'registry_value', "WUServer"
it_behaves_like 'registry_value undefined', "WUStatusServer"
it_behaves_like 'registry_value', "UseWUServer", au_key do
let(:reg_data) { 1 }
let(:reg_type) { :type_dword_converted }
end
end
end
describe "true", {:testrail => ['70189']} do
let(:reg_data) { 'http://myserver:8530' }
it { create_apply_manifest(
{:server_url => 'http://myserver:8530',
:enable_status_server => true,
}) }
it_behaves_like 'registry_value', "WUStatusServer"
it_behaves_like 'registry_value', "WUServer"
end
describe "false", {:testrail => ['70190']} do
let(:reg_data) { 'http://myserver:8530' }
it { create_apply_manifest(
{:server_url => 'http://myserver:8530',
:enable_status_server => false,
}, false) }
it_behaves_like 'registry_value undefined', "WUStatusServer"
it_behaves_like 'registry_value', "WUServer"
end
end
context 'auto_update_option =>' do
{'notifyonly' => 2,
'autonotify' => 3,
'autoinstall' => 5}.each do |key, au_opt|
describe "#{au_opt}", {:testcase => ['70197', '70198', '70200']} do
it { create_apply_manifest :auto_update_option => au_opt }
it_behaves_like 'registry_value', 'AUOptions', au_key do
let(:reg_data) { au_opt }
end
end
describe "#{key}", {:testcase => ['70201', '70202', '70204']} do
it { create_apply_manifest :auto_update_option => key }
it_behaves_like 'registry_value', 'AUOptions', au_key do
let(:reg_data) { au_opt }
end
end
end
['Scheduled', 4].each do |scheduled|
describe 'Scheduled', {:testrail => ['70203', '70199']} do
it { create_apply_manifest(
{:auto_update_option => scheduled,
:scheduled_install_day => 0,
:scheduled_install_hour => 19, }) }
it_behaves_like 'registry_value', 'AUOptions', au_key do
let(:reg_data) { 4 }
end
it_behaves_like 'registry_value', 'ScheduledInstallDay', au_key do
let(:reg_data) { 0 }
end
it_behaves_like 'registry_value', 'ScheduledInstallTime', au_key do
let(:reg_data) { 19 }
end
end
end
end
context 'accept_trusted_publisher_certs =>', {:testrail => ['70193', '70194']} do
it_behaves_like 'boolean values',
:accept_trusted_publisher_certs,
'AcceptTrustedPublisherCerts'
end
context 'auto_install_minor_updates =>', {:testrail => ['70210', '70211']} do
it_behaves_like 'boolean values',
:auto_install_minor_updates,
'AutoInstallMinorUpdates', au_key
end
context 'detection_frequency_hours =>', {:testrail => ['70213', '70214', '70215']} do
it_behaves_like 'enabled range',
:detection_frequency_hours,
'DetectionFrequency',
[1, 22],
au_key
end
context 'disable_windows_update_access =>', {:testrail => ['70220', '70221']} do
it_behaves_like 'boolean values',
:disable_windows_update_access,
'DisableWindowsUpdateAccess'
end
context 'elevate_non_admins =>', {:testrail => ['70223', '70224']} do
it_behaves_like 'boolean values',
:elevate_non_admins,
'ElevateNonAdmins'
end
context 'no_auto_reboot_with_logged_on_users =>', {:testrail => ['70226', '70227']} do
it_behaves_like 'boolean values',
:no_auto_reboot_with_logged_on_users,
'NoAutoRebootWithLoggedOnUsers',
au_key
end
context 'no_auto_update =>', {:testrail => ['70229', '70230']} do
it_behaves_like 'boolean values',
:no_auto_update,
'NoAutoUpdate',
au_key
end
context 'reboot_relaunch_timeout_minutes =>', {:testrail => ['70232', '70233', '70234']} do
it_behaves_like 'enabled range',
:reboot_relaunch_timeout_minutes,
'RebootRelaunchTimeout',
[1, 1440],
au_key
end
context 'reboot_warning_timeout_minutes =>', {:testrail => ['70239', '70240', '70241']} do
it_behaves_like 'enabled range',
:reboot_warning_timeout_minutes,
'RebootWarningTimeout',
[1, 30],
au_key
end
context 'reschedule_wait_time_minutes =>', {:testrail => ['70246', '70247', '70248']} do
it_behaves_like 'enabled range',
:reschedule_wait_time_minutes,
'RescheduleWaitTime',
[1, 60],
au_key
end
context 'scheduled_install_day =>', {:testrail => ['70253', '70254', '70255', '70256']} do
{'Everyday' => 0, 'Tuesday' => 3, 0 => 0, 3 => 3}.each do |day, expected_value|
describe "#{day}" do
it {
create_apply_manifest :auto_update_option => 'Scheduled',
:scheduled_install_day => day,
:scheduled_install_hour => 18 }
it_behaves_like 'registry_value', 'ScheduledInstallDay', au_key do
let(:reg_data) { expected_value }
end
it_behaves_like 'registry_value', 'AUOptions', au_key do
let(:reg_data) { 4 }
end
end
end
end
context 'scheduled_install_hour =>', {:testrail => ['70263', '70264']} do
[0, 23].each do |hour|
describe "#{hour}" do
it {
create_apply_manifest :auto_update_option => 'Scheduled',
:scheduled_install_day => 'Tuesday',
:scheduled_install_hour => hour }
it_behaves_like 'registry_value', 'ScheduledInstallTime', au_key do
let(:reg_data) { hour }
end
it_behaves_like 'registry_value', 'AUOptions', au_key do
let(:reg_data) { 4 }
end
end
end
end
context 'target_group =>', {:testrail => ['70268']} do
describe 'testTargetGroup' do
it {
create_apply_manifest :target_group => 'testTargetGroup'
}
it_behaves_like 'registry_value', 'TargetGroup' do
let(:reg_data) { 'testTargetGroup' }
let(:reg_type) { :type_string }
end
it_behaves_like 'registry_value', 'TargetGroupEnabled' do
let(:reg_data) { 1 }
let(:reg_type) { :type_dword_converted }
end
end
describe 'false', {:testrail => ['89606']} do
it {
create_apply_manifest :target_group => false
}
it_behaves_like 'registry_value', 'TargetGroupEnabled' do
let(:reg_data) { 0 }
let(:reg_type) { :type_dword_converted }
end
end
end
end