serverspec 0.11.5 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -5
- data/lib/serverspec.rb +2 -36
- data/lib/serverspec/helper.rb +2 -32
- data/lib/serverspec/helper/backend.rb +11 -0
- data/lib/serverspec/helper/os.rb +25 -0
- data/lib/serverspec/setup.rb +3 -3
- data/lib/serverspec/version.rb +1 -1
- data/serverspec.gemspec +1 -0
- data/spec/aix/command_spec.rb +1 -1
- data/spec/aix/cron_spec.rb +1 -1
- data/spec/aix/default_gateway_spec.rb +1 -1
- data/spec/aix/file_spec.rb +1 -1
- data/spec/aix/group_spec.rb +1 -1
- data/spec/aix/host_spec.rb +1 -1
- data/spec/aix/package_spec.rb +1 -1
- data/spec/aix/php_config_spec.rb +1 -1
- data/spec/aix/port_spec.rb +1 -1
- data/spec/aix/routing_table_spec.rb +1 -1
- data/spec/aix/service_spec.rb +1 -1
- data/spec/aix/user_spec.rb +1 -1
- data/spec/backend/cmd/configuration_spec.rb +2 -2
- data/spec/backend/exec/build_command_spec.rb +1 -1
- data/spec/backend/exec/configuration_spec.rb +2 -3
- data/spec/backend/powershell/script_helper_spec.rb +4 -4
- data/spec/backend/ssh/build_command_spec.rb +1 -1
- data/spec/backend/ssh/configuration_spec.rb +2 -3
- data/spec/backend/winrm/configuration_spec.rb +2 -2
- data/spec/darwin/command_spec.rb +1 -1
- data/spec/darwin/cron_spec.rb +1 -1
- data/spec/darwin/default_gateway_spec.rb +1 -1
- data/spec/darwin/file_spec.rb +1 -1
- data/spec/darwin/group_spec.rb +1 -1
- data/spec/darwin/host_spec.rb +1 -1
- data/spec/darwin/mail_alias_spec.rb +1 -1
- data/spec/darwin/package_spec.rb +1 -1
- data/spec/darwin/php_config_spec.rb +1 -1
- data/spec/darwin/port_spec.rb +1 -1
- data/spec/darwin/routing_table_spec.rb +1 -1
- data/spec/darwin/service_spec.rb +1 -1
- data/spec/darwin/user_spec.rb +1 -1
- data/spec/debian/cgroup_spec.rb +1 -1
- data/spec/debian/command_spec.rb +1 -1
- data/spec/debian/cron_spec.rb +1 -1
- data/spec/debian/default_gateway_spec.rb +1 -1
- data/spec/debian/file_spec.rb +1 -1
- data/spec/debian/group_spec.rb +1 -1
- data/spec/debian/host_spec.rb +1 -1
- data/spec/debian/interface_spec.rb +1 -1
- data/spec/debian/iptables_spec.rb +1 -1
- data/spec/debian/kernel_module_spec.rb +1 -1
- data/spec/debian/linux_kernel_parameter_spec.rb +1 -1
- data/spec/debian/lxc_spec.rb +1 -1
- data/spec/debian/mail_alias_spec.rb +1 -1
- data/spec/debian/package_spec.rb +1 -1
- data/spec/debian/php_config_spec.rb +1 -1
- data/spec/debian/port_spec.rb +1 -1
- data/spec/debian/routing_table_spec.rb +1 -1
- data/spec/debian/selinux_spec.rb +1 -1
- data/spec/debian/service_spec.rb +1 -1
- data/spec/debian/user_spec.rb +1 -1
- data/spec/debian/zfs_spec.rb +1 -1
- data/spec/freebsd/command_spec.rb +1 -1
- data/spec/freebsd/cron_spec.rb +1 -1
- data/spec/freebsd/default_gateway_spec.rb +1 -1
- data/spec/freebsd/file_spec.rb +1 -1
- data/spec/freebsd/group_spec.rb +1 -1
- data/spec/freebsd/host_spec.rb +1 -1
- data/spec/freebsd/package_spec.rb +1 -1
- data/spec/freebsd/php_config_spec.rb +1 -1
- data/spec/freebsd/port_spec.rb +1 -1
- data/spec/freebsd/routing_table_spec.rb +1 -1
- data/spec/freebsd/service_spec.rb +1 -1
- data/spec/freebsd/user_spec.rb +1 -1
- data/spec/gentoo/cgroup_spec.rb +1 -1
- data/spec/gentoo/command_spec.rb +1 -1
- data/spec/gentoo/cron_spec.rb +1 -1
- data/spec/gentoo/default_gateway_spec.rb +1 -1
- data/spec/gentoo/file_spec.rb +1 -1
- data/spec/gentoo/group_spec.rb +1 -1
- data/spec/gentoo/host_spec.rb +1 -1
- data/spec/gentoo/interface_spec.rb +1 -1
- data/spec/gentoo/iptables_spec.rb +1 -1
- data/spec/gentoo/kernel_module_spec.rb +1 -1
- data/spec/gentoo/linux_kernel_parameter_spec.rb +1 -1
- data/spec/gentoo/lxc_spec.rb +1 -1
- data/spec/gentoo/mail_alias_spec.rb +1 -1
- data/spec/gentoo/package_spec.rb +1 -1
- data/spec/gentoo/php_config_spec.rb +1 -1
- data/spec/gentoo/port_spec.rb +1 -1
- data/spec/gentoo/routing_table_spec.rb +1 -1
- data/spec/gentoo/selinux_spec.rb +1 -1
- data/spec/gentoo/service_spec.rb +1 -1
- data/spec/gentoo/user_spec.rb +1 -1
- data/spec/gentoo/zfs_spec.rb +1 -1
- data/spec/plamo/cgroup_spec.rb +1 -1
- data/spec/plamo/command_spec.rb +1 -1
- data/spec/plamo/cron_spec.rb +1 -1
- data/spec/plamo/default_gateway_spec.rb +1 -1
- data/spec/plamo/file_spec.rb +1 -1
- data/spec/plamo/group_spec.rb +1 -1
- data/spec/plamo/host_spec.rb +1 -1
- data/spec/plamo/interface_spec.rb +1 -1
- data/spec/plamo/iptables_spec.rb +1 -1
- data/spec/plamo/kernel_module_spec.rb +1 -1
- data/spec/plamo/linux_kernel_parameter_spec.rb +1 -1
- data/spec/plamo/lxc_spec.rb +1 -1
- data/spec/plamo/mail_alias_spec.rb +1 -1
- data/spec/plamo/package_spec.rb +1 -1
- data/spec/plamo/php_config_spec.rb +1 -1
- data/spec/plamo/port_spec.rb +1 -1
- data/spec/plamo/routing_table_spec.rb +1 -1
- data/spec/plamo/selinux_spec.rb +1 -1
- data/spec/plamo/service_spec.rb +1 -1
- data/spec/plamo/user_spec.rb +1 -1
- data/spec/plamo/zfs_spec.rb +1 -1
- data/spec/redhat/cgroup_spec.rb +1 -1
- data/spec/redhat/command_spec.rb +1 -1
- data/spec/redhat/cron_spec.rb +1 -1
- data/spec/redhat/default_gateway_spec.rb +1 -1
- data/spec/redhat/file_spec.rb +1 -1
- data/spec/redhat/group_spec.rb +1 -1
- data/spec/redhat/host_spec.rb +1 -1
- data/spec/redhat/interface_spec.rb +1 -1
- data/spec/redhat/iptables_spec.rb +1 -1
- data/spec/redhat/kernel_module_spec.rb +1 -1
- data/spec/redhat/linux_kernel_parameter_spec.rb +1 -1
- data/spec/redhat/lxc_spec.rb +1 -1
- data/spec/redhat/mail_alias_spec.rb +1 -1
- data/spec/redhat/package_spec.rb +1 -1
- data/spec/redhat/php_config_spec.rb +1 -1
- data/spec/redhat/port_spec.rb +1 -1
- data/spec/redhat/routing_table_spec.rb +1 -1
- data/spec/redhat/selinux_spec.rb +1 -1
- data/spec/redhat/service_spec.rb +1 -1
- data/spec/redhat/user_spec.rb +1 -1
- data/spec/redhat/yumrepo_spec.rb +1 -1
- data/spec/redhat/zfs_spec.rb +1 -1
- data/spec/smartos/mail_alias_spec.rb +1 -1
- data/spec/solaris/command_spec.rb +1 -1
- data/spec/solaris/cron_spec.rb +1 -1
- data/spec/solaris/default_gateway_spec.rb +1 -1
- data/spec/solaris/file_spec.rb +1 -1
- data/spec/solaris/group_spec.rb +1 -1
- data/spec/solaris/host_spec.rb +1 -1
- data/spec/solaris/ipfilter_spec.rb +1 -1
- data/spec/solaris/ipnat_spec.rb +1 -1
- data/spec/solaris/mail_alias_spec.rb +1 -1
- data/spec/solaris/package_spec.rb +1 -1
- data/spec/solaris/php_config_spec.rb +1 -1
- data/spec/solaris/port_spec.rb +1 -1
- data/spec/solaris/routing_table_spec.rb +1 -1
- data/spec/solaris/service_spec.rb +1 -1
- data/spec/solaris/svcprop_spec.rb +1 -1
- data/spec/solaris/user_spec.rb +1 -1
- data/spec/solaris/zfs_spec.rb +1 -1
- data/spec/solaris10/file_spec.rb +1 -1
- data/spec/solaris10/group_spec.rb +1 -1
- data/spec/solaris10/mail_alias_spec.rb +1 -1
- data/spec/solaris10/package_spec.rb +1 -1
- data/spec/solaris10/php_config_spec.rb +1 -1
- data/spec/solaris10/user_spec.rb +1 -1
- data/spec/solaris11/command_spec.rb +1 -1
- data/spec/solaris11/cron_spec.rb +1 -1
- data/spec/solaris11/default_gateway_spec.rb +1 -1
- data/spec/solaris11/file_spec.rb +1 -1
- data/spec/solaris11/group_spec.rb +1 -1
- data/spec/solaris11/host_spec.rb +1 -1
- data/spec/solaris11/ipfilter_spec.rb +1 -1
- data/spec/solaris11/ipnat_spec.rb +1 -1
- data/spec/solaris11/mail_alias_spec.rb +1 -1
- data/spec/solaris11/package_spec.rb +1 -1
- data/spec/solaris11/php_config_spec.rb +1 -1
- data/spec/solaris11/port_spec.rb +1 -1
- data/spec/solaris11/routing_table_spec.rb +1 -1
- data/spec/solaris11/service_spec.rb +1 -1
- data/spec/solaris11/svcprop_spec.rb +1 -1
- data/spec/solaris11/user_spec.rb +1 -1
- data/spec/solaris11/zfs_spec.rb +1 -1
- data/spec/spec_helper.rb +8 -6
- data/spec/windows/command_spec.rb +2 -2
- data/spec/windows/file_spec.rb +2 -2
- data/spec/windows/group_spec.rb +2 -2
- data/spec/windows/port_spec.rb +2 -2
- data/spec/windows/service_spec.rb +2 -2
- data/spec/windows/user_spec.rb +2 -2
- data/spec/windows/windows_registry_key_spec.rb +2 -2
- metadata +18 -45
- data/lib/serverspec/attributes.rb +0 -17
- data/lib/serverspec/backend.rb +0 -7
- data/lib/serverspec/backend/base.rb +0 -31
- data/lib/serverspec/backend/cmd.rb +0 -39
- data/lib/serverspec/backend/exec.rb +0 -218
- data/lib/serverspec/backend/powershell/command.rb +0 -40
- data/lib/serverspec/backend/powershell/script_helper.rb +0 -85
- data/lib/serverspec/backend/powershell/support/check_file_access_rules.ps1 +0 -8
- data/lib/serverspec/backend/powershell/support/crop_text.ps1 +0 -11
- data/lib/serverspec/backend/powershell/support/find_group.ps1 +0 -8
- data/lib/serverspec/backend/powershell/support/find_installed_application.ps1 +0 -7
- data/lib/serverspec/backend/powershell/support/find_service.ps1 +0 -5
- data/lib/serverspec/backend/powershell/support/find_user.ps1 +0 -8
- data/lib/serverspec/backend/powershell/support/find_usergroup.ps1 +0 -9
- data/lib/serverspec/backend/powershell/support/is_port_listening.ps1 +0 -13
- data/lib/serverspec/backend/ssh.rb +0 -93
- data/lib/serverspec/backend/winrm.rb +0 -26
- data/lib/serverspec/configuration.rb +0 -12
- data/lib/serverspec/helper/aix.rb +0 -9
- data/lib/serverspec/helper/attributes.rb +0 -16
- data/lib/serverspec/helper/base.rb +0 -9
- data/lib/serverspec/helper/cmd.rb +0 -15
- data/lib/serverspec/helper/configuration.rb +0 -37
- data/lib/serverspec/helper/darwin.rb +0 -9
- data/lib/serverspec/helper/debian.rb +0 -9
- data/lib/serverspec/helper/detect_os.rb +0 -19
- data/lib/serverspec/helper/exec.rb +0 -14
- data/lib/serverspec/helper/freebsd.rb +0 -9
- data/lib/serverspec/helper/gentoo.rb +0 -9
- data/lib/serverspec/helper/plamo.rb +0 -9
- data/lib/serverspec/helper/properties.rb +0 -14
- data/lib/serverspec/helper/puppet.rb +0 -9
- data/lib/serverspec/helper/redhat.rb +0 -9
- data/lib/serverspec/helper/smartos.rb +0 -10
- data/lib/serverspec/helper/solaris.rb +0 -9
- data/lib/serverspec/helper/solaris10.rb +0 -9
- data/lib/serverspec/helper/solaris11.rb +0 -9
- data/lib/serverspec/helper/ssh.rb +0 -15
- data/lib/serverspec/helper/windows.rb +0 -9
- data/lib/serverspec/helper/winrm.rb +0 -15
- data/lib/serverspec/properties.rb +0 -17
- data/spec/helpers/properties_spec.rb +0 -11
@@ -1,40 +0,0 @@
|
|
1
|
-
module Serverspec
|
2
|
-
module Backend
|
3
|
-
module PowerShell
|
4
|
-
class Command
|
5
|
-
attr_reader :import_functions, :script
|
6
|
-
def initialize &block
|
7
|
-
@import_functions = []
|
8
|
-
@script = ""
|
9
|
-
instance_eval &block if block_given?
|
10
|
-
end
|
11
|
-
|
12
|
-
def using *functions
|
13
|
-
functions.each { |f| import_functions << f }
|
14
|
-
end
|
15
|
-
|
16
|
-
def exec code
|
17
|
-
@script = code
|
18
|
-
end
|
19
|
-
|
20
|
-
def convert_regexp(target)
|
21
|
-
case target
|
22
|
-
when Regexp
|
23
|
-
target.source
|
24
|
-
else
|
25
|
-
target.to_s.gsub '/', ''
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def get_identity id
|
30
|
-
raise "You must provide a specific Windows user/group" if id =~ /(owner|group|others)/
|
31
|
-
identity = id || 'Everyone'
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_s
|
35
|
-
@script
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'base64'
|
2
|
-
|
3
|
-
module Serverspec
|
4
|
-
module Backend
|
5
|
-
module PowerShell
|
6
|
-
module ScriptHelper
|
7
|
-
def build_command(cmd)
|
8
|
-
path = Serverspec.configuration.path || RSpec.configuration.path
|
9
|
-
if path
|
10
|
-
cmd.strip!
|
11
|
-
cmd =
|
12
|
-
<<-EOF
|
13
|
-
$env:path = "#{path};$env:path"
|
14
|
-
#{cmd}
|
15
|
-
EOF
|
16
|
-
end
|
17
|
-
cmd
|
18
|
-
end
|
19
|
-
|
20
|
-
def add_pre_command(cmd)
|
21
|
-
path = Serverspec.configuration.path || RSpec.configuration.path
|
22
|
-
if Serverspec.configuration.pre_command
|
23
|
-
cmd.strip!
|
24
|
-
cmd =
|
25
|
-
<<-EOF
|
26
|
-
if (#{Serverspec.configuration.pre_command})
|
27
|
-
{
|
28
|
-
#{cmd}
|
29
|
-
}
|
30
|
-
EOF
|
31
|
-
cmd = "$env:path = \"#{path};$env:path\"\n#{cmd}" if path
|
32
|
-
end
|
33
|
-
cmd
|
34
|
-
end
|
35
|
-
|
36
|
-
def encode_script script
|
37
|
-
script_text = script.chars.to_a.join("\x00").chomp
|
38
|
-
script_text << "\x00" unless script_text[-1].eql? "\x00"
|
39
|
-
if script_text.respond_to?(:encode)
|
40
|
-
script_text = script_text.encode('ASCII-8BIT')
|
41
|
-
end
|
42
|
-
if Base64.respond_to?(:strict_encode64)
|
43
|
-
Base64.strict_encode64(script_text)
|
44
|
-
else
|
45
|
-
[ script_text ].pack("m").strip
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def create_script command
|
50
|
-
if command.is_a? Command
|
51
|
-
ps_functions = command.import_functions.map { |f| File.read(File.join(File.dirname(__FILE__), 'support', f)) }
|
52
|
-
script = build_command(command.script)
|
53
|
-
script = add_pre_command(script)
|
54
|
-
<<-EOF
|
55
|
-
$exitCode = 1
|
56
|
-
try {
|
57
|
-
#{ps_functions.join("\n")}
|
58
|
-
$success = (#{script})
|
59
|
-
if ($success -is [Boolean] -and $success) { $exitCode = 0 }
|
60
|
-
} catch {
|
61
|
-
Write-Output $_.Exception.Message
|
62
|
-
}
|
63
|
-
Write-Output "Exiting with code: $exitCode"
|
64
|
-
exit $exitCode
|
65
|
-
EOF
|
66
|
-
else
|
67
|
-
script = build_command(command.to_s)
|
68
|
-
add_pre_command(script)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def check_running(process)
|
73
|
-
ret = run_command(commands.check_running(process))
|
74
|
-
|
75
|
-
# If the service is not registered, check the process
|
76
|
-
if ret[:exit_status] == 1
|
77
|
-
ret = run_command(commands.check_process(process))
|
78
|
-
end
|
79
|
-
|
80
|
-
ret[:exit_status] == 0
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
@@ -1,8 +0,0 @@
|
|
1
|
-
function CheckFileAccessRules
|
2
|
-
{
|
3
|
-
param($path, $identity, $rules)
|
4
|
-
|
5
|
-
$accessRules = @((Get-Acl $path).access | Where-Object {$_.AccessControlType -eq 'Allow' -and $_.IdentityReference -eq $identity })
|
6
|
-
$match = @($accessRules | Where-Object {($_.FileSystemRights.ToString().Split(',') | % {$_.trim()} | ? {$rules -contains $_}) -ne $null})
|
7
|
-
$match.count -gt 0
|
8
|
-
}
|
@@ -1,11 +0,0 @@
|
|
1
|
-
function CropText
|
2
|
-
{
|
3
|
-
param($text, $fromPattern, $toPattern)
|
4
|
-
|
5
|
-
$from, $to = ([regex]::matches($text, $fromPattern)), ([regex]::matches($text, $toPattern))
|
6
|
-
if ($from.count -gt 0 -and $to.count -gt 0) {
|
7
|
-
$text.substring($from[0].index, $to[0].index + $to[0].length - $from[0].index)
|
8
|
-
} else {
|
9
|
-
""
|
10
|
-
}
|
11
|
-
}
|
@@ -1,7 +0,0 @@
|
|
1
|
-
function FindInstalledApplication
|
2
|
-
{
|
3
|
-
param($appName, $appVersion)
|
4
|
-
$selectionCriteria = "(Name like '$appName' or PackageName like '$appName') and InstallState = 5"
|
5
|
-
if ($appVersion -ne $null) { $selectionCriteria += " and version = '$appVersion'"}
|
6
|
-
Get-WmiObject Win32_Product -filter $selectionCriteria
|
7
|
-
}
|
@@ -1,8 +0,0 @@
|
|
1
|
-
function FindUser
|
2
|
-
{
|
3
|
-
param($userName, $domain)
|
4
|
-
if ($domain -eq $null) {$selectionCriteria = " and LocalAccount = true"}
|
5
|
-
else {$selectionCriteria = " and Domain = '$domain'"}
|
6
|
-
|
7
|
-
Get-WmiObject Win32_UserAccount -filter "Name = '$userName' $selectionCriteria"
|
8
|
-
}
|
@@ -1,9 +0,0 @@
|
|
1
|
-
function FindUserGroup
|
2
|
-
{
|
3
|
-
param($userName, $groupName, $userDomain, $groupDomain)
|
4
|
-
$user = FindUser -userName $userName -domain $userDomain
|
5
|
-
$group = FindGroup -groupName $groupName -domain $groupDomain
|
6
|
-
if ($user -and $group) {
|
7
|
-
Get-WmiObject Win32_GroupUser -filter ("GroupComponent = 'Win32_Group.Domain=`"" + $group.domain + "`",Name=`"" + $group.name + "`"' and PartComponent = 'Win32_UserAccount.Domain=`"" + $user.domain + "`",Name=`"" + $user.name + "`"'")
|
8
|
-
}
|
9
|
-
}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
function IsPortListening
|
2
|
-
{
|
3
|
-
param($portNumber, $protocol)
|
4
|
-
$netstatOutput = netstat -an | Out-String
|
5
|
-
$networkIPs = (Get-WmiObject Win32_NetworkAdapterConfiguration | ? {$_.IPEnabled}) | %{ $_.IPAddress[0] }
|
6
|
-
foreach ($ipaddress in $networkIPs)
|
7
|
-
{
|
8
|
-
$matchExpression = ("$ipaddress" + ":" + $portNumber)
|
9
|
-
if ($protocol) { $matchExpression = ($protocol.toUpper() + "\s+$matchExpression") }
|
10
|
-
if ($netstatOutput -match $matchExpression) { return $true }
|
11
|
-
}
|
12
|
-
$false
|
13
|
-
}
|
@@ -1,93 +0,0 @@
|
|
1
|
-
require 'serverspec/backend/exec'
|
2
|
-
|
3
|
-
module Serverspec
|
4
|
-
module Backend
|
5
|
-
class Ssh < Exec
|
6
|
-
def run_command(cmd, opt={})
|
7
|
-
cmd = build_command(cmd)
|
8
|
-
cmd = add_pre_command(cmd)
|
9
|
-
ret = ssh_exec!(cmd)
|
10
|
-
|
11
|
-
ret[:stdout].gsub!(/\r\n/, "\n")
|
12
|
-
|
13
|
-
if @example
|
14
|
-
@example.metadata[:command] = cmd
|
15
|
-
@example.metadata[:stdout] = ret[:stdout]
|
16
|
-
end
|
17
|
-
|
18
|
-
ret
|
19
|
-
end
|
20
|
-
|
21
|
-
def build_command(cmd)
|
22
|
-
cmd = super(cmd)
|
23
|
-
if RSpec.configuration.ssh.options[:user] != 'root'
|
24
|
-
cmd = "#{sudo} #{cmd}"
|
25
|
-
cmd.gsub!(/(\&\&\s*!?\(?\s*)/, "\\1#{sudo} ")
|
26
|
-
cmd.gsub!(/(\|\|\s*!?\(?\s*)/, "\\1#{sudo} ")
|
27
|
-
end
|
28
|
-
cmd
|
29
|
-
end
|
30
|
-
|
31
|
-
def add_pre_command(cmd)
|
32
|
-
cmd = super(cmd)
|
33
|
-
user = RSpec.configuration.ssh.options[:user]
|
34
|
-
pre_command = Serverspec.configuration.pre_command
|
35
|
-
if pre_command && user != 'root'
|
36
|
-
cmd = "#{sudo} #{cmd}"
|
37
|
-
end
|
38
|
-
cmd
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
def ssh_exec!(command)
|
43
|
-
stdout_data = ''
|
44
|
-
stderr_data = ''
|
45
|
-
exit_status = nil
|
46
|
-
exit_signal = nil
|
47
|
-
pass_prompt = RSpec.configuration.pass_prompt || /^\[sudo\] password for/
|
48
|
-
|
49
|
-
ssh = RSpec.configuration.ssh
|
50
|
-
ssh.open_channel do |channel|
|
51
|
-
channel.request_pty do |ch, success|
|
52
|
-
abort "Could not obtain pty " if !success
|
53
|
-
end
|
54
|
-
channel.exec("#{command}") do |ch, success|
|
55
|
-
abort "FAILED: couldn't execute command (ssh.channel.exec)" if !success
|
56
|
-
channel.on_data do |ch, data|
|
57
|
-
if data.match pass_prompt
|
58
|
-
abort "Please set sudo password by using SUDO_PASSWORD or ASK_SUDO_PASSWORD environment variable" if RSpec.configuration.sudo_password.nil?
|
59
|
-
channel.send_data "#{RSpec.configuration.sudo_password}\n"
|
60
|
-
else
|
61
|
-
stdout_data += data
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
channel.on_extended_data do |ch, type, data|
|
66
|
-
stderr_data += data
|
67
|
-
end
|
68
|
-
|
69
|
-
channel.on_request("exit-status") do |ch, data|
|
70
|
-
exit_status = data.read_long
|
71
|
-
end
|
72
|
-
|
73
|
-
channel.on_request("exit-signal") do |ch, data|
|
74
|
-
exit_signal = data.read_long
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
ssh.loop
|
79
|
-
{ :stdout => stdout_data, :stderr => stderr_data, :exit_status => exit_status, :exit_signal => exit_signal }
|
80
|
-
end
|
81
|
-
|
82
|
-
def sudo
|
83
|
-
sudo_path = Serverspec.configuration.sudo_path || RSpec.configuration.sudo_path
|
84
|
-
if sudo_path
|
85
|
-
"#{sudo_path}/sudo"
|
86
|
-
else
|
87
|
-
'sudo'
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module Serverspec
|
2
|
-
module Backend
|
3
|
-
class WinRM < Base
|
4
|
-
include PowerShell::ScriptHelper
|
5
|
-
|
6
|
-
def run_command(cmd, opts={})
|
7
|
-
script = create_script(cmd)
|
8
|
-
winrm = RSpec.configuration.winrm
|
9
|
-
|
10
|
-
result = winrm.powershell(script)
|
11
|
-
stdout, stderr = [:stdout, :stderr].map do |s|
|
12
|
-
result[:data].select {|item| item.key? s}.map {|item| item[s]}.join
|
13
|
-
end
|
14
|
-
result[:exitcode] = 1 if result[:exitcode] == 0 and !stderr.empty?
|
15
|
-
|
16
|
-
if @example
|
17
|
-
@example.metadata[:command] = script
|
18
|
-
@example.metadata[:stdout] = stdout + stderr
|
19
|
-
end
|
20
|
-
|
21
|
-
{ :stdout => stdout, :stderr => stderr,
|
22
|
-
:exit_status => result[:exitcode], :exit_signal => nil }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module Serverspec
|
2
|
-
module Configuration
|
3
|
-
class << self
|
4
|
-
VALID_OPTIONS_KEYS = [:path, :pre_command, :stdout, :stderr, :sudo_path, :pass_prompt].freeze
|
5
|
-
attr_accessor(*VALID_OPTIONS_KEYS)
|
6
|
-
|
7
|
-
def defaults
|
8
|
-
VALID_OPTIONS_KEYS.inject({}) { |o, k| o.merge!(k => send(k)) }
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'serverspec/attributes'
|
2
|
-
|
3
|
-
module Serverspec
|
4
|
-
module Helper
|
5
|
-
module Attributes
|
6
|
-
def attr
|
7
|
-
puts "Warning: attr method will be obsoleted. Please use property method instead."
|
8
|
-
Serverspec::Attributes.instance.attributes
|
9
|
-
end
|
10
|
-
def attr_set(attr)
|
11
|
-
puts "Warning: attr_set method will be obsoleted. Please use set_property method instead."
|
12
|
-
Serverspec::Attributes.instance.attributes(attr)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Serverspec
|
2
|
-
module Helper
|
3
|
-
module Cmd
|
4
|
-
def backend(commands_object=nil)
|
5
|
-
if ! respond_to?(:commands)
|
6
|
-
commands_object = Serverspec::Commands::Windows.new
|
7
|
-
end
|
8
|
-
instance = Serverspec::Backend::Cmd.instance
|
9
|
-
instance.set_commands(commands_object || commands)
|
10
|
-
instance
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module Serverspec
|
2
|
-
module Helper
|
3
|
-
module Configuration
|
4
|
-
def subject
|
5
|
-
example.metadata[:subject] = described_class
|
6
|
-
build_configurations
|
7
|
-
super
|
8
|
-
end
|
9
|
-
|
10
|
-
# You can create a set of configurations provided to all specs in your spec_helper:
|
11
|
-
#
|
12
|
-
# RSpec.configure { |c| c.pre_command = "source ~/.zshrc" }
|
13
|
-
#
|
14
|
-
# Any configurations you provide with `let(:option_name)` in a spec will
|
15
|
-
# automatically be merged on top of the configurations.
|
16
|
-
#
|
17
|
-
# @example
|
18
|
-
#
|
19
|
-
# describe 'Gem' do
|
20
|
-
# let(:pre_command) { "source ~/.zshrc" }
|
21
|
-
#
|
22
|
-
# %w(pry awesome_print bundler).each do |p|
|
23
|
-
# describe package(p) do
|
24
|
-
# it { should be_installed.by('gem') }
|
25
|
-
# end
|
26
|
-
# end
|
27
|
-
# end
|
28
|
-
def build_configurations
|
29
|
-
Serverspec::Configuration.defaults.keys.each do |c|
|
30
|
-
value = self.respond_to?(c.to_sym) ?
|
31
|
-
self.send(c) : RSpec.configuration.send(c)
|
32
|
-
Serverspec::Configuration.send(:"#{c}=", value)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|