winrm 2.0.3 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -10
- data/.rubocop.yml +26 -26
- data/.travis.yml +11 -11
- data/Gemfile +3 -3
- data/README.md +260 -233
- data/Rakefile +34 -34
- data/Vagrantfile +6 -6
- data/WinrmAppveyor.psm1 +31 -31
- data/appveyor.yml +51 -51
- data/changelog.md +104 -101
- data/lib/winrm.rb +39 -39
- data/lib/winrm/connection.rb +83 -82
- data/lib/winrm/connection_opts.rb +91 -91
- data/lib/winrm/exceptions.rb +76 -76
- data/lib/winrm/http/response_handler.rb +96 -96
- data/lib/winrm/http/transport.rb +424 -424
- data/lib/winrm/http/transport_factory.rb +68 -68
- data/lib/winrm/output.rb +59 -59
- data/lib/winrm/psrp/create_pipeline.xml.erb +167 -167
- data/lib/winrm/psrp/fragment.rb +70 -70
- data/lib/winrm/psrp/init_runspace_pool.xml.erb +224 -224
- data/lib/winrm/psrp/message.rb +130 -130
- data/lib/winrm/psrp/message_data.rb +42 -42
- data/lib/winrm/psrp/message_data/base.rb +49 -49
- data/lib/winrm/psrp/message_data/error_record.rb +68 -68
- data/lib/winrm/psrp/message_data/pipeline_host_call.rb +32 -32
- data/lib/winrm/psrp/message_data/pipeline_output.rb +49 -49
- data/lib/winrm/psrp/message_data/pipeline_state.rb +40 -40
- data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +32 -32
- data/lib/winrm/psrp/message_data/runspacepool_state.rb +39 -39
- data/lib/winrm/psrp/message_data/session_capability.rb +36 -36
- data/lib/winrm/psrp/message_defragmenter.rb +62 -62
- data/lib/winrm/psrp/message_factory.rb +75 -75
- data/lib/winrm/psrp/message_fragmenter.rb +60 -60
- data/lib/winrm/psrp/powershell_output_decoder.rb +139 -139
- data/lib/winrm/psrp/receive_response_reader.rb +97 -97
- data/lib/winrm/psrp/session_capability.xml.erb +7 -7
- data/lib/winrm/psrp/uuid.rb +40 -40
- data/lib/winrm/shells/base.rb +180 -175
- data/lib/winrm/shells/cmd.rb +65 -65
- data/lib/winrm/shells/power_shell.rb +202 -202
- data/lib/winrm/shells/retryable.rb +45 -45
- data/lib/winrm/shells/shell_factory.rb +58 -50
- data/lib/winrm/version.rb +7 -7
- data/lib/winrm/wsmv/base.rb +59 -59
- data/lib/winrm/wsmv/cleanup_command.rb +61 -61
- data/lib/winrm/wsmv/close_shell.rb +50 -50
- data/lib/winrm/wsmv/command.rb +101 -101
- data/lib/winrm/wsmv/command_output.rb +76 -76
- data/lib/winrm/wsmv/command_output_decoder.rb +55 -55
- data/lib/winrm/wsmv/configuration.rb +46 -46
- data/lib/winrm/wsmv/create_pipeline.rb +66 -66
- data/lib/winrm/wsmv/create_shell.rb +119 -119
- data/lib/winrm/wsmv/header.rb +203 -203
- data/lib/winrm/wsmv/init_runspace_pool.rb +95 -95
- data/lib/winrm/wsmv/iso8601_duration.rb +60 -60
- data/lib/winrm/wsmv/keep_alive.rb +68 -68
- data/lib/winrm/wsmv/receive_response_reader.rb +126 -126
- data/lib/winrm/wsmv/send_data.rb +68 -68
- data/lib/winrm/wsmv/soap.rb +51 -51
- data/lib/winrm/wsmv/wql_query.rb +79 -79
- data/lib/winrm/wsmv/write_stdin.rb +88 -88
- data/tests/integration/auth_timeout_spec.rb +18 -18
- data/tests/integration/cmd_spec.rb +131 -110
- data/tests/integration/config-example.yml +16 -16
- data/tests/integration/issue_59_spec.rb +26 -26
- data/tests/integration/powershell_spec.rb +165 -165
- data/tests/integration/spec_helper.rb +65 -65
- data/tests/integration/transport_spec.rb +99 -99
- data/tests/integration/wql_spec.rb +16 -16
- data/tests/matchers.rb +60 -60
- data/tests/spec/configuration_spec.rb +184 -184
- data/tests/spec/connection_spec.rb +39 -39
- data/tests/spec/exception_spec.rb +50 -50
- data/tests/spec/http/transport_factory_spec.rb +68 -68
- data/tests/spec/http/transport_spec.rb +44 -44
- data/tests/spec/output_spec.rb +127 -127
- data/tests/spec/psrp/fragment_spec.rb +62 -62
- data/tests/spec/psrp/message_data/base_spec.rb +13 -13
- data/tests/spec/psrp/message_data/error_record_spec.rb +41 -41
- data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +25 -25
- data/tests/spec/psrp/message_data/pipeline_output_spec.rb +32 -32
- data/tests/spec/psrp/message_data/pipeline_state_spec.rb +40 -40
- data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +25 -25
- data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +16 -16
- data/tests/spec/psrp/message_data/session_capability_spec.rb +30 -30
- data/tests/spec/psrp/message_data_spec.rb +35 -35
- data/tests/spec/psrp/message_defragmenter_spec.rb +47 -47
- data/tests/spec/psrp/message_fragmenter_spec.rb +105 -105
- data/tests/spec/psrp/powershell_output_decoder_spec.rb +100 -100
- data/tests/spec/psrp/psrp_message_spec.rb +70 -70
- data/tests/spec/psrp/recieve_response_reader_spec.rb +172 -172
- data/tests/spec/psrp/uuid_spec.rb +28 -28
- data/tests/spec/response_handler_spec.rb +61 -61
- data/tests/spec/shells/base_spec.rb +202 -202
- data/tests/spec/shells/cmd_spec.rb +75 -75
- data/tests/spec/shells/powershell_spec.rb +175 -175
- data/tests/spec/spec_helper.rb +47 -47
- data/tests/spec/stubs/clixml/error_record.xml.erb +84 -84
- data/tests/spec/stubs/clixml/pipeline_state.xml.erb +88 -88
- data/tests/spec/stubs/responses/get_command_output_response.xml.erb +13 -13
- data/tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb +10 -10
- data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +10 -10
- data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +12 -12
- data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +9 -9
- data/tests/spec/stubs/responses/open_shell_v1.xml +19 -19
- data/tests/spec/stubs/responses/open_shell_v2.xml +20 -20
- data/tests/spec/stubs/responses/soap_fault_v1.xml +36 -36
- data/tests/spec/stubs/responses/soap_fault_v2.xml +42 -42
- data/tests/spec/stubs/responses/wmi_error_v2.xml +41 -41
- data/tests/spec/wsmv/cleanup_command_spec.rb +22 -22
- data/tests/spec/wsmv/close_shell_spec.rb +17 -17
- data/tests/spec/wsmv/command_output_decoder_spec.rb +37 -37
- data/tests/spec/wsmv/command_output_spec.rb +45 -45
- data/tests/spec/wsmv/command_spec.rb +19 -19
- data/tests/spec/wsmv/configuration_spec.rb +17 -17
- data/tests/spec/wsmv/create_pipeline_spec.rb +31 -31
- data/tests/spec/wsmv/create_shell_spec.rb +38 -38
- data/tests/spec/wsmv/init_runspace_pool_spec.rb +36 -36
- data/tests/spec/wsmv/keep_alive_spec.rb +21 -21
- data/tests/spec/wsmv/receive_response_reader_spec.rb +123 -123
- data/tests/spec/wsmv/send_data_spec.rb +30 -30
- data/tests/spec/wsmv/wql_query_spec.rb +13 -13
- data/tests/spec/wsmv/write_stdin_spec.rb +22 -22
- data/winrm.gemspec +42 -42
- metadata +2 -2
@@ -1,65 +1,65 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'rubygems'
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'winrm'
|
5
|
-
require 'json'
|
6
|
-
require_relative '../matchers'
|
7
|
-
|
8
|
-
# Creates a WinRM connection for integration tests
|
9
|
-
module ConnectionHelper
|
10
|
-
def winrm_connection
|
11
|
-
WinRM::Connection.new(connection_opts)
|
12
|
-
end
|
13
|
-
|
14
|
-
def connection_opts
|
15
|
-
@config ||= begin
|
16
|
-
cfg = symbolize_keys(YAML.load(File.read(winrm_config_path)))
|
17
|
-
merge_environment(cfg)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def merge_environment(config)
|
22
|
-
merge_config_option_from_environment(config, 'user')
|
23
|
-
merge_config_option_from_environment(config, 'password')
|
24
|
-
merge_config_option_from_environment(config, 'no_ssl_peer_verification')
|
25
|
-
if ENV['use_ssl_peer_fingerprint']
|
26
|
-
config[:ssl_peer_fingerprint] = ENV['winrm_cert']
|
27
|
-
end
|
28
|
-
config[:endpoint] = ENV['winrm_endpoint'] if ENV['winrm_endpoint']
|
29
|
-
config
|
30
|
-
end
|
31
|
-
|
32
|
-
def merge_config_option_from_environment(config, key)
|
33
|
-
env_key = 'winrm_' + key
|
34
|
-
config[key.to_sym] = ENV[env_key] if ENV[env_key]
|
35
|
-
end
|
36
|
-
|
37
|
-
def winrm_config_path
|
38
|
-
# Copy config-example.yml to config.yml and edit for your local ConnectionOpts
|
39
|
-
path = File.expand_path("#{File.dirname(__FILE__)}/config.yml")
|
40
|
-
unless File.exist?(path)
|
41
|
-
# user hasn't done this, so use sane defaults for unit tests
|
42
|
-
path = File.expand_path("#{File.dirname(__FILE__)}/config-example.yml")
|
43
|
-
end
|
44
|
-
path
|
45
|
-
end
|
46
|
-
|
47
|
-
def symbolize_keys(hash)
|
48
|
-
hash.each_with_object({}) do |(key, value), result|
|
49
|
-
new_key = case key
|
50
|
-
when String then key.to_sym
|
51
|
-
else key
|
52
|
-
end
|
53
|
-
new_value = case value
|
54
|
-
when Hash then symbolize_keys(value)
|
55
|
-
else value
|
56
|
-
end
|
57
|
-
result[new_key] = new_value
|
58
|
-
result
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
RSpec.configure do |config|
|
64
|
-
config.include(ConnectionHelper)
|
65
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'winrm'
|
5
|
+
require 'json'
|
6
|
+
require_relative '../matchers'
|
7
|
+
|
8
|
+
# Creates a WinRM connection for integration tests
|
9
|
+
module ConnectionHelper
|
10
|
+
def winrm_connection
|
11
|
+
WinRM::Connection.new(connection_opts)
|
12
|
+
end
|
13
|
+
|
14
|
+
def connection_opts
|
15
|
+
@config ||= begin
|
16
|
+
cfg = symbolize_keys(YAML.load(File.read(winrm_config_path)))
|
17
|
+
merge_environment(cfg)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def merge_environment(config)
|
22
|
+
merge_config_option_from_environment(config, 'user')
|
23
|
+
merge_config_option_from_environment(config, 'password')
|
24
|
+
merge_config_option_from_environment(config, 'no_ssl_peer_verification')
|
25
|
+
if ENV['use_ssl_peer_fingerprint']
|
26
|
+
config[:ssl_peer_fingerprint] = ENV['winrm_cert']
|
27
|
+
end
|
28
|
+
config[:endpoint] = ENV['winrm_endpoint'] if ENV['winrm_endpoint']
|
29
|
+
config
|
30
|
+
end
|
31
|
+
|
32
|
+
def merge_config_option_from_environment(config, key)
|
33
|
+
env_key = 'winrm_' + key
|
34
|
+
config[key.to_sym] = ENV[env_key] if ENV[env_key]
|
35
|
+
end
|
36
|
+
|
37
|
+
def winrm_config_path
|
38
|
+
# Copy config-example.yml to config.yml and edit for your local ConnectionOpts
|
39
|
+
path = File.expand_path("#{File.dirname(__FILE__)}/config.yml")
|
40
|
+
unless File.exist?(path)
|
41
|
+
# user hasn't done this, so use sane defaults for unit tests
|
42
|
+
path = File.expand_path("#{File.dirname(__FILE__)}/config-example.yml")
|
43
|
+
end
|
44
|
+
path
|
45
|
+
end
|
46
|
+
|
47
|
+
def symbolize_keys(hash)
|
48
|
+
hash.each_with_object({}) do |(key, value), result|
|
49
|
+
new_key = case key
|
50
|
+
when String then key.to_sym
|
51
|
+
else key
|
52
|
+
end
|
53
|
+
new_value = case value
|
54
|
+
when Hash then symbolize_keys(value)
|
55
|
+
else value
|
56
|
+
end
|
57
|
+
result[new_key] = new_value
|
58
|
+
result
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
RSpec.configure do |config|
|
64
|
+
config.include(ConnectionHelper)
|
65
|
+
end
|
@@ -1,99 +1,99 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require_relative 'spec_helper'
|
3
|
-
|
4
|
-
describe 'WinRM connection' do
|
5
|
-
let(:connection) do
|
6
|
-
endpoint = connection_opts[:endpoint].dup
|
7
|
-
if auth_type == :ssl
|
8
|
-
endpoint.sub!('5985', '5986')
|
9
|
-
endpoint.sub!('http', 'https')
|
10
|
-
end
|
11
|
-
conn_options = {
|
12
|
-
transport: auth_type,
|
13
|
-
endpoint: endpoint
|
14
|
-
}.merge(options)
|
15
|
-
WinRM::Connection.new(conn_options).shell(:cmd)
|
16
|
-
end
|
17
|
-
let(:options) do
|
18
|
-
opts = {}
|
19
|
-
opts[:user] = connection_opts[:user]
|
20
|
-
opts[:password] = connection_opts[:password]
|
21
|
-
opts[:basic_auth_only] = basic_auth_only
|
22
|
-
opts[:no_ssl_peer_verification] = no_ssl_peer_verification
|
23
|
-
opts[:ssl_peer_fingerprint] = ssl_peer_fingerprint
|
24
|
-
opts[:client_cert] = user_cert
|
25
|
-
opts[:client_key] = user_key
|
26
|
-
opts
|
27
|
-
end
|
28
|
-
let(:basic_auth_only) { false }
|
29
|
-
let(:no_ssl_peer_verification) { false }
|
30
|
-
let(:ssl_peer_fingerprint) { nil }
|
31
|
-
let(:user_cert) { nil }
|
32
|
-
let(:user_key) { nil }
|
33
|
-
|
34
|
-
subject(:output) { connection.run('ipconfig') }
|
35
|
-
|
36
|
-
after(:each) do
|
37
|
-
connection.close
|
38
|
-
end
|
39
|
-
|
40
|
-
shared_examples 'a valid_connection' do
|
41
|
-
it 'has a 0 exit code' do
|
42
|
-
expect(subject).to have_exit_code 0
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'includes command output' do
|
46
|
-
expect(subject).to have_stdout_match(/Windows IP Configuration/)
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'has no errors' do
|
50
|
-
expect(subject).to have_no_stderr
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context 'HttpPlaintext' do
|
55
|
-
let(:basic_auth_only) { true }
|
56
|
-
let(:auth_type) { :plaintext }
|
57
|
-
|
58
|
-
it_behaves_like 'a valid_connection'
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'HttpNegotiate' do
|
62
|
-
let(:auth_type) { :negotiate }
|
63
|
-
|
64
|
-
it_behaves_like 'a valid_connection'
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'BasicAuthSSL', skip: ENV['winrm_cert'].nil? do
|
68
|
-
let(:basic_auth_only) { true }
|
69
|
-
let(:auth_type) { :ssl }
|
70
|
-
let(:no_ssl_peer_verification) { true }
|
71
|
-
|
72
|
-
it_behaves_like 'a valid_connection'
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'ClientCertAuthSSL', skip: ENV['user_cert'].nil? do
|
76
|
-
let(:auth_type) { :ssl }
|
77
|
-
let(:no_ssl_peer_verification) { true }
|
78
|
-
let(:user_cert) { ENV['user_cert'] }
|
79
|
-
let(:user_key) { ENV['user_key'] }
|
80
|
-
|
81
|
-
before { options[:pass] = nil }
|
82
|
-
|
83
|
-
it_behaves_like 'a valid_connection'
|
84
|
-
end
|
85
|
-
|
86
|
-
context 'Negotiate over SSL', skip: ENV['winrm_cert'].nil? do
|
87
|
-
let(:auth_type) { :ssl }
|
88
|
-
let(:no_ssl_peer_verification) { true }
|
89
|
-
|
90
|
-
it_behaves_like 'a valid_connection'
|
91
|
-
end
|
92
|
-
|
93
|
-
context 'SSL fingerprint', skip: ENV['winrm_cert'].nil? do
|
94
|
-
let(:auth_type) { :ssl }
|
95
|
-
let(:ssl_peer_fingerprint) { ENV['winrm_cert'] }
|
96
|
-
|
97
|
-
it_behaves_like 'a valid_connection'
|
98
|
-
end
|
99
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
|
4
|
+
describe 'WinRM connection' do
|
5
|
+
let(:connection) do
|
6
|
+
endpoint = connection_opts[:endpoint].dup
|
7
|
+
if auth_type == :ssl
|
8
|
+
endpoint.sub!('5985', '5986')
|
9
|
+
endpoint.sub!('http', 'https')
|
10
|
+
end
|
11
|
+
conn_options = {
|
12
|
+
transport: auth_type,
|
13
|
+
endpoint: endpoint
|
14
|
+
}.merge(options)
|
15
|
+
WinRM::Connection.new(conn_options).shell(:cmd)
|
16
|
+
end
|
17
|
+
let(:options) do
|
18
|
+
opts = {}
|
19
|
+
opts[:user] = connection_opts[:user]
|
20
|
+
opts[:password] = connection_opts[:password]
|
21
|
+
opts[:basic_auth_only] = basic_auth_only
|
22
|
+
opts[:no_ssl_peer_verification] = no_ssl_peer_verification
|
23
|
+
opts[:ssl_peer_fingerprint] = ssl_peer_fingerprint
|
24
|
+
opts[:client_cert] = user_cert
|
25
|
+
opts[:client_key] = user_key
|
26
|
+
opts
|
27
|
+
end
|
28
|
+
let(:basic_auth_only) { false }
|
29
|
+
let(:no_ssl_peer_verification) { false }
|
30
|
+
let(:ssl_peer_fingerprint) { nil }
|
31
|
+
let(:user_cert) { nil }
|
32
|
+
let(:user_key) { nil }
|
33
|
+
|
34
|
+
subject(:output) { connection.run('ipconfig') }
|
35
|
+
|
36
|
+
after(:each) do
|
37
|
+
connection.close
|
38
|
+
end
|
39
|
+
|
40
|
+
shared_examples 'a valid_connection' do
|
41
|
+
it 'has a 0 exit code' do
|
42
|
+
expect(subject).to have_exit_code 0
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'includes command output' do
|
46
|
+
expect(subject).to have_stdout_match(/Windows IP Configuration/)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'has no errors' do
|
50
|
+
expect(subject).to have_no_stderr
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'HttpPlaintext' do
|
55
|
+
let(:basic_auth_only) { true }
|
56
|
+
let(:auth_type) { :plaintext }
|
57
|
+
|
58
|
+
it_behaves_like 'a valid_connection'
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'HttpNegotiate' do
|
62
|
+
let(:auth_type) { :negotiate }
|
63
|
+
|
64
|
+
it_behaves_like 'a valid_connection'
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'BasicAuthSSL', skip: ENV['winrm_cert'].nil? do
|
68
|
+
let(:basic_auth_only) { true }
|
69
|
+
let(:auth_type) { :ssl }
|
70
|
+
let(:no_ssl_peer_verification) { true }
|
71
|
+
|
72
|
+
it_behaves_like 'a valid_connection'
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'ClientCertAuthSSL', skip: ENV['user_cert'].nil? do
|
76
|
+
let(:auth_type) { :ssl }
|
77
|
+
let(:no_ssl_peer_verification) { true }
|
78
|
+
let(:user_cert) { ENV['user_cert'] }
|
79
|
+
let(:user_key) { ENV['user_key'] }
|
80
|
+
|
81
|
+
before { options[:pass] = nil }
|
82
|
+
|
83
|
+
it_behaves_like 'a valid_connection'
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'Negotiate over SSL', skip: ENV['winrm_cert'].nil? do
|
87
|
+
let(:auth_type) { :ssl }
|
88
|
+
let(:no_ssl_peer_verification) { true }
|
89
|
+
|
90
|
+
it_behaves_like 'a valid_connection'
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'SSL fingerprint', skip: ENV['winrm_cert'].nil? do
|
94
|
+
let(:auth_type) { :ssl }
|
95
|
+
let(:ssl_peer_fingerprint) { ENV['winrm_cert'] }
|
96
|
+
|
97
|
+
it_behaves_like 'a valid_connection'
|
98
|
+
end
|
99
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require_relative 'spec_helper'
|
3
|
-
|
4
|
-
describe 'winrm client wql' do
|
5
|
-
before(:all) do
|
6
|
-
@winrm = winrm_connection
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should query Win32_OperatingSystem' do
|
10
|
-
output = @winrm.run_wql('select * from Win32_OperatingSystem')
|
11
|
-
expect(output).to_not be_empty
|
12
|
-
output_caption = output[:win32_operating_system][0][:caption]
|
13
|
-
expect(output_caption).to include('Microsoft')
|
14
|
-
expect(output_caption).to include('Windows')
|
15
|
-
end
|
16
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
|
4
|
+
describe 'winrm client wql' do
|
5
|
+
before(:all) do
|
6
|
+
@winrm = winrm_connection
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should query Win32_OperatingSystem' do
|
10
|
+
output = @winrm.run_wql('select * from Win32_OperatingSystem')
|
11
|
+
expect(output).to_not be_empty
|
12
|
+
output_caption = output[:win32_operating_system][0][:caption]
|
13
|
+
expect(output_caption).to include('Microsoft')
|
14
|
+
expect(output_caption).to include('Windows')
|
15
|
+
end
|
16
|
+
end
|
data/tests/matchers.rb
CHANGED
@@ -1,60 +1,60 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'rspec/expectations'
|
3
|
-
|
4
|
-
# rspec matchers
|
5
|
-
RSpec::Matchers.define :have_stdout_match do |expected_stdout|
|
6
|
-
match do |actual_output|
|
7
|
-
!expected_stdout.match(actual_output.stdout).nil?
|
8
|
-
end
|
9
|
-
failure_message do |actual_output|
|
10
|
-
"expected that '#{actual_output.stdout}' would match #{expected_stdout}"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
RSpec::Matchers.define :have_stderr_match do |expected_stderr|
|
15
|
-
match do |actual_output|
|
16
|
-
!expected_stderr.match(actual_output.stderr).nil?
|
17
|
-
end
|
18
|
-
failure_message do |actual_output|
|
19
|
-
"expected that '#{actual_output.stderr}' would match #{expected_stderr}"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
RSpec::Matchers.define :have_no_stdout do
|
24
|
-
match do |actual_output|
|
25
|
-
stdout = actual_output.stdout
|
26
|
-
stdout == '\r\n' || stdout == ''
|
27
|
-
end
|
28
|
-
failure_message do |actual_output|
|
29
|
-
"expected that '#{actual_output.stdout}' would have no stdout"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
RSpec::Matchers.define :have_no_stderr do
|
34
|
-
match do |actual_output|
|
35
|
-
stderr = actual_output.stderr
|
36
|
-
stderr == '\r\n' || stderr == ''
|
37
|
-
end
|
38
|
-
failure_message do |actual_output|
|
39
|
-
"expected that '#{actual_output.stderr}' would have no stderr"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
RSpec::Matchers.define :have_exit_code do |expected_exit_code|
|
44
|
-
match do |actual_output|
|
45
|
-
expected_exit_code == actual_output.exitcode
|
46
|
-
end
|
47
|
-
failure_message do |actual_output|
|
48
|
-
"expected exit code #{expected_exit_code}, but got #{actual_output.exitcode}"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
RSpec::Matchers.define :be_a_uid do
|
53
|
-
match do |actual|
|
54
|
-
# WinRM1.1 returns uuid's prefixed with 'uuid:' where as later versions do not
|
55
|
-
actual && actual.to_s.match(/^(uuid:)*\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/)
|
56
|
-
end
|
57
|
-
failure_message do |actual|
|
58
|
-
"expected a uid, but got '#{actual}'"
|
59
|
-
end
|
60
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rspec/expectations'
|
3
|
+
|
4
|
+
# rspec matchers
|
5
|
+
RSpec::Matchers.define :have_stdout_match do |expected_stdout|
|
6
|
+
match do |actual_output|
|
7
|
+
!expected_stdout.match(actual_output.stdout).nil?
|
8
|
+
end
|
9
|
+
failure_message do |actual_output|
|
10
|
+
"expected that '#{actual_output.stdout}' would match #{expected_stdout}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
RSpec::Matchers.define :have_stderr_match do |expected_stderr|
|
15
|
+
match do |actual_output|
|
16
|
+
!expected_stderr.match(actual_output.stderr).nil?
|
17
|
+
end
|
18
|
+
failure_message do |actual_output|
|
19
|
+
"expected that '#{actual_output.stderr}' would match #{expected_stderr}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
RSpec::Matchers.define :have_no_stdout do
|
24
|
+
match do |actual_output|
|
25
|
+
stdout = actual_output.stdout
|
26
|
+
stdout == '\r\n' || stdout == ''
|
27
|
+
end
|
28
|
+
failure_message do |actual_output|
|
29
|
+
"expected that '#{actual_output.stdout}' would have no stdout"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
RSpec::Matchers.define :have_no_stderr do
|
34
|
+
match do |actual_output|
|
35
|
+
stderr = actual_output.stderr
|
36
|
+
stderr == '\r\n' || stderr == ''
|
37
|
+
end
|
38
|
+
failure_message do |actual_output|
|
39
|
+
"expected that '#{actual_output.stderr}' would have no stderr"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
RSpec::Matchers.define :have_exit_code do |expected_exit_code|
|
44
|
+
match do |actual_output|
|
45
|
+
expected_exit_code == actual_output.exitcode
|
46
|
+
end
|
47
|
+
failure_message do |actual_output|
|
48
|
+
"expected exit code #{expected_exit_code}, but got #{actual_output.exitcode}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
RSpec::Matchers.define :be_a_uid do
|
53
|
+
match do |actual|
|
54
|
+
# WinRM1.1 returns uuid's prefixed with 'uuid:' where as later versions do not
|
55
|
+
actual && actual.to_s.match(/^(uuid:)*\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/)
|
56
|
+
end
|
57
|
+
failure_message do |actual|
|
58
|
+
"expected a uid, but got '#{actual}'"
|
59
|
+
end
|
60
|
+
end
|