serverspec 0.12.0 → 0.13.0
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.
- data/lib/serverspec.rb +0 -16
- data/lib/serverspec/version.rb +1 -1
- data/serverspec.gemspec +1 -1
- data/spec/backend/exec/configuration_spec.rb +7 -0
- data/spec/windows/file_spec.rb +1 -1
- data/spec/windows/group_spec.rb +1 -2
- data/spec/windows/user_spec.rb +1 -1
- metadata +120 -109
- checksums.yaml +0 -7
- data/lib/serverspec/commands/aix.rb +0 -69
- data/lib/serverspec/commands/base.rb +0 -305
- data/lib/serverspec/commands/darwin.rb +0 -42
- data/lib/serverspec/commands/debian.rb +0 -24
- data/lib/serverspec/commands/freebsd.rb +0 -23
- data/lib/serverspec/commands/gentoo.rb +0 -18
- data/lib/serverspec/commands/linux.rb +0 -70
- data/lib/serverspec/commands/plamo.rb +0 -21
- data/lib/serverspec/commands/redhat.rb +0 -32
- data/lib/serverspec/commands/smartos.rb +0 -21
- data/lib/serverspec/commands/solaris.rb +0 -117
- data/lib/serverspec/commands/solaris10.rb +0 -78
- data/lib/serverspec/commands/solaris11.rb +0 -7
- data/lib/serverspec/commands/windows.rb +0 -213
@@ -1,213 +0,0 @@
|
|
1
|
-
module Serverspec
|
2
|
-
module Commands
|
3
|
-
class Windows
|
4
|
-
class NotSupportedError < Exception; end
|
5
|
-
REGISTRY_KEY_TYPES = {
|
6
|
-
:type_string => 'String',
|
7
|
-
:type_binary => 'Binary',
|
8
|
-
:type_dword => 'DWord',
|
9
|
-
:type_qword => 'QWord',
|
10
|
-
:type_multistring => 'MultiString',
|
11
|
-
:type_expandstring => 'ExpandString'
|
12
|
-
}
|
13
|
-
|
14
|
-
def method_missing method, *args
|
15
|
-
raise NotSupportedError.new "#{method} currently not supported in Windows os" if method.to_s =~ /^check_.+/
|
16
|
-
super(method, *args)
|
17
|
-
end
|
18
|
-
|
19
|
-
def check_file(file)
|
20
|
-
cmd = item_has_attribute file, 'Archive'
|
21
|
-
Backend::PowerShell::Command.new do
|
22
|
-
exec cmd
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def check_file_hidden(file)
|
27
|
-
cmd = item_has_attribute file, 'Hidden'
|
28
|
-
Backend::PowerShell::Command.new do
|
29
|
-
exec cmd
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def check_file_readonly(file)
|
34
|
-
cmd = item_has_attribute file, 'ReadOnly'
|
35
|
-
Backend::PowerShell::Command.new do
|
36
|
-
exec cmd
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def check_file_system(file)
|
41
|
-
cmd = item_has_attribute file, 'System'
|
42
|
-
Backend::PowerShell::Command.new do
|
43
|
-
exec cmd
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def check_directory(dir)
|
48
|
-
cmd = item_has_attribute dir, 'Directory'
|
49
|
-
Backend::PowerShell::Command.new do
|
50
|
-
exec cmd
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def check_file_contain(file, pattern)
|
55
|
-
Backend::PowerShell::Command.new do
|
56
|
-
exec "[Io.File]::ReadAllText('#{file}') -match '#{convert_regexp(pattern)}'"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def check_file_contain_within file, pattern, from=nil, to=nil
|
61
|
-
from ||= '^'
|
62
|
-
to ||= '$'
|
63
|
-
Backend::PowerShell::Command.new do
|
64
|
-
using 'crop_text.ps1'
|
65
|
-
exec %Q[(CropText -text ([Io.File]::ReadAllText('#{file}')) -fromPattern '#{convert_regexp(from)}' -toPattern '#{convert_regexp(to)}') -match '#{pattern}']
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def check_access_by_user(file, user, access)
|
70
|
-
case access
|
71
|
-
when 'r'
|
72
|
-
check_readable(file, user)
|
73
|
-
when 'w'
|
74
|
-
check_writable(file, user)
|
75
|
-
when 'x'
|
76
|
-
check_executable(file, user)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def check_readable(file, by_whom)
|
81
|
-
Backend::PowerShell::Command.new do
|
82
|
-
using 'check_file_access_rules.ps1'
|
83
|
-
exec "CheckFileAccessRules -path '#{file}' -identity '#{get_identity by_whom}' -rules @('FullControl', 'Modify', 'ReadAndExecute', 'Read', 'ListDirectory')"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def check_writable(file, by_whom)
|
88
|
-
Backend::PowerShell::Command.new do
|
89
|
-
using 'check_file_access_rules.ps1'
|
90
|
-
exec "CheckFileAccessRules -path '#{file}' -identity '#{get_identity by_whom}' -rules @('FullControl', 'Modify', 'Write')"
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def check_executable(file, by_whom)
|
95
|
-
Backend::PowerShell::Command.new do
|
96
|
-
using 'check_file_access_rules.ps1'
|
97
|
-
exec "CheckFileAccessRules -path '#{file}' -identity '#{get_identity by_whom}' -rules @('FullControl', 'Modify', 'ReadAndExecute', 'ExecuteFile')"
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def check_installed(package, version=nil)
|
102
|
-
version_selection = version.nil? ? "" : "-appVersion '#{version}'"
|
103
|
-
Backend::PowerShell::Command.new do
|
104
|
-
using 'find_installed_application.ps1'
|
105
|
-
exec "(FindInstalledApplication -appName '#{package}' #{version_selection}) -ne $null"
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def check_enabled(service, level=nil)
|
110
|
-
Backend::PowerShell::Command.new do
|
111
|
-
using 'find_service.ps1'
|
112
|
-
exec "(FindService -name '#{service}').StartMode -eq 'Auto'"
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def check_running(service)
|
117
|
-
Backend::PowerShell::Command.new do
|
118
|
-
using 'find_service.ps1'
|
119
|
-
exec "(FindService -name '#{service}').State -eq 'Running'"
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def check_process(process)
|
124
|
-
Backend::PowerShell::Command.new do
|
125
|
-
exec "(Get-Process '#{process}') -ne $null"
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
def check_listening(port)
|
130
|
-
Backend::PowerShell::Command.new do
|
131
|
-
using 'is_port_listening.ps1'
|
132
|
-
exec "IsPortListening -portNumber #{port}"
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def check_listening_with_protocol(port, protocol)
|
137
|
-
Backend::PowerShell::Command.new do
|
138
|
-
using 'is_port_listening.ps1'
|
139
|
-
exec "IsPortListening -portNumber #{port} -protocol '#{protocol}'"
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def check_user(user)
|
144
|
-
user_id, domain = windows_account user
|
145
|
-
Backend::PowerShell::Command.new do
|
146
|
-
using 'find_user.ps1'
|
147
|
-
exec "(FindUser -userName '#{user_id}'#{domain.nil? ? "" : " -domain '#{domain}'"}) -ne $null"
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
def check_group(group)
|
152
|
-
group_id, domain = windows_account group
|
153
|
-
Backend::PowerShell::Command.new do
|
154
|
-
using 'find_group.ps1'
|
155
|
-
exec "(FindGroup -groupName '#{group_id}'#{domain.nil? ? "" : " -domain '#{domain}'"}) -ne $null"
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
def check_belonging_group(user, group)
|
160
|
-
user_id, user_domain = windows_account user
|
161
|
-
group_id, group_domain = windows_account group
|
162
|
-
Backend::PowerShell::Command.new do
|
163
|
-
using 'find_user.ps1'
|
164
|
-
using 'find_group.ps1'
|
165
|
-
using 'find_usergroup.ps1'
|
166
|
-
exec "(FindUserGroup -userName '#{user_id}'#{user_domain.nil? ? "" : " -userDomain '#{user_domain}'"} -groupName '#{group_id}'#{group_domain.nil? ? "" : " -groupDomain '#{group_domain}'"}) -ne $null"
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def check_registry_key(key_name, key_property = {})
|
171
|
-
if key_property.empty?
|
172
|
-
cmd = "(Get-Item 'Registry::#{key_name}') -ne $null"
|
173
|
-
else
|
174
|
-
if key_property.key? :value
|
175
|
-
value = convert_key_property_value key_property
|
176
|
-
cmd = "(Compare-Object (Get-Item 'Registry::#{key_name}').GetValue('#{key_property[:name]}') #{value}) -eq $null"
|
177
|
-
else
|
178
|
-
cmd = "(Get-Item 'Registry::#{key_name}').GetValueKind('#{key_property[:name]}') -eq '#{REGISTRY_KEY_TYPES[key_property[:type]]}'"
|
179
|
-
end
|
180
|
-
end
|
181
|
-
Backend::PowerShell::Command.new { exec cmd }
|
182
|
-
end
|
183
|
-
|
184
|
-
private
|
185
|
-
|
186
|
-
def item_has_attribute item, attribute
|
187
|
-
"((Get-Item -Path '#{item}' -Force).attributes.ToString() -Split ', ') -contains '#{attribute}'"
|
188
|
-
end
|
189
|
-
|
190
|
-
def convert_key_property_value property
|
191
|
-
case property[:type]
|
192
|
-
when :type_binary
|
193
|
-
byte_array = [property[:value]].pack('H*').bytes.to_a
|
194
|
-
"([byte[]] #{byte_array.join(',')})"
|
195
|
-
when :type_dword
|
196
|
-
[property[:value].scan(/[0-9a-f]{2}/i).reverse.join].pack("H*").unpack("l").first
|
197
|
-
when :type_qword
|
198
|
-
property[:value].hex
|
199
|
-
else
|
200
|
-
string_array = property[:value].split("\n").map {|s| "'#{s}'"}.reduce {|acc, s| "#{acc},#{s}"}
|
201
|
-
"@(#{string_array})"
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
def windows_account account
|
206
|
-
match = /((.+)\\)?(.+)/.match account
|
207
|
-
domain = match[2]
|
208
|
-
name = match[3]
|
209
|
-
[name, domain]
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|