winrm 1.8.1 → 2.0.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 -11
- data/.rubocop.yml +26 -22
- data/.travis.yml +11 -12
- data/Gemfile +3 -9
- data/LICENSE +202 -202
- data/README.md +232 -215
- data/Rakefile +34 -36
- data/Vagrantfile +6 -9
- data/WinrmAppveyor.psm1 +31 -31
- data/appveyor.yml +51 -51
- data/bin/rwinrm +97 -97
- data/changelog.md +86 -86
- data/lib/winrm.rb +39 -42
- data/lib/winrm/connection.rb +82 -0
- data/lib/winrm/connection_opts.rb +87 -0
- data/lib/winrm/{exceptions/exceptions.rb → exceptions.rb} +76 -57
- data/lib/winrm/http/response_handler.rb +96 -82
- data/lib/winrm/http/transport.rb +424 -435
- data/lib/winrm/http/transport_factory.rb +68 -0
- data/lib/winrm/output.rb +59 -43
- data/lib/winrm/psrp/create_pipeline.xml.erb +167 -0
- data/lib/winrm/psrp/fragment.rb +70 -0
- data/lib/winrm/psrp/init_runspace_pool.xml.erb +224 -0
- data/lib/winrm/psrp/message.rb +130 -0
- data/lib/winrm/psrp/message_data.rb +41 -0
- data/lib/winrm/psrp/message_data/base.rb +49 -0
- data/lib/winrm/psrp/message_data/error_record.rb +68 -0
- data/lib/winrm/psrp/message_data/pipeline_host_call.rb +32 -0
- data/lib/winrm/psrp/message_data/pipeline_output.rb +49 -0
- data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +32 -0
- data/lib/winrm/psrp/message_data/runspacepool_state.rb +39 -0
- data/lib/winrm/psrp/message_data/session_capability.rb +36 -0
- data/lib/winrm/psrp/message_defragmenter.rb +62 -0
- data/lib/winrm/psrp/message_factory.rb +75 -0
- data/lib/winrm/psrp/message_fragmenter.rb +60 -0
- data/lib/winrm/psrp/powershell_output_decoder.rb +120 -0
- data/lib/winrm/psrp/receive_response_reader.rb +93 -0
- data/lib/winrm/psrp/session_capability.xml.erb +7 -0
- data/lib/winrm/psrp/uuid.rb +40 -0
- data/lib/winrm/shells/base.rb +175 -0
- data/lib/winrm/shells/cmd.rb +65 -0
- data/lib/winrm/shells/power_shell.rb +201 -0
- data/lib/winrm/shells/retryable.rb +45 -0
- data/lib/winrm/shells/shell_factory.rb +50 -0
- data/lib/winrm/version.rb +7 -7
- data/lib/winrm/wsmv/base.rb +59 -0
- data/lib/winrm/wsmv/cleanup_command.rb +61 -0
- data/lib/winrm/wsmv/close_shell.rb +50 -0
- data/lib/winrm/wsmv/command.rb +101 -0
- data/lib/winrm/wsmv/command_output.rb +76 -0
- data/lib/winrm/wsmv/command_output_decoder.rb +55 -0
- data/lib/winrm/wsmv/configuration.rb +46 -0
- data/lib/winrm/wsmv/create_pipeline.rb +66 -0
- data/lib/winrm/wsmv/create_shell.rb +119 -0
- data/lib/winrm/wsmv/header.rb +203 -0
- data/lib/winrm/wsmv/init_runspace_pool.rb +95 -0
- data/lib/winrm/wsmv/iso8601_duration.rb +60 -0
- data/lib/winrm/wsmv/keep_alive.rb +68 -0
- data/lib/winrm/wsmv/receive_response_reader.rb +128 -0
- data/lib/winrm/wsmv/send_data.rb +68 -0
- data/lib/winrm/wsmv/soap.rb +51 -0
- data/lib/winrm/wsmv/wql_query.rb +79 -0
- data/lib/winrm/wsmv/write_stdin.rb +88 -0
- data/preamble +17 -17
- data/{spec → tests/integration}/auth_timeout_spec.rb +18 -16
- data/{spec → tests/integration}/cmd_spec.rb +104 -102
- data/{spec → tests/integration}/config-example.yml +16 -19
- data/{spec → tests/integration}/issue_59_spec.rb +26 -23
- data/tests/integration/powershell_spec.rb +154 -0
- data/{spec → tests/integration}/spec_helper.rb +65 -73
- data/{spec → tests/integration}/transport_spec.rb +99 -139
- data/{spec → tests/integration}/wql_spec.rb +16 -14
- data/{spec → tests}/matchers.rb +60 -74
- data/tests/spec/configuration_spec.rb +93 -0
- data/tests/spec/connection_spec.rb +39 -0
- data/{spec → tests/spec}/exception_spec.rb +50 -50
- data/tests/spec/http/transport_factory_spec.rb +68 -0
- data/tests/spec/http/transport_spec.rb +44 -0
- data/{spec → tests/spec}/output_spec.rb +127 -110
- data/tests/spec/psrp/fragment_spec.rb +62 -0
- data/tests/spec/psrp/message_data/base_spec.rb +13 -0
- data/tests/spec/psrp/message_data/error_record_spec.rb +41 -0
- data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +25 -0
- data/tests/spec/psrp/message_data/pipeline_output_spec.rb +32 -0
- data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +25 -0
- data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +16 -0
- data/tests/spec/psrp/message_data/session_capability_spec.rb +30 -0
- data/tests/spec/psrp/message_data_spec.rb +35 -0
- data/tests/spec/psrp/message_defragmenter_spec.rb +47 -0
- data/tests/spec/psrp/message_fragmenter_spec.rb +105 -0
- data/tests/spec/psrp/powershell_output_decoder_spec.rb +84 -0
- data/tests/spec/psrp/psrp_message_spec.rb +70 -0
- data/tests/spec/psrp/recieve_response_reader_spec.rb +154 -0
- data/tests/spec/psrp/uuid_spec.rb +28 -0
- data/{spec → tests/spec}/response_handler_spec.rb +61 -61
- data/tests/spec/shells/base_spec.rb +202 -0
- data/tests/spec/shells/cmd_spec.rb +75 -0
- data/tests/spec/shells/powershell_spec.rb +175 -0
- data/tests/spec/spec_helper.rb +47 -0
- data/tests/spec/stubs/clixml/error_record.xml.erb +84 -0
- data/{spec → 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 -0
- data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +10 -0
- data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +12 -0
- data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +9 -0
- data/{spec → tests/spec}/stubs/responses/open_shell_v1.xml +19 -19
- data/{spec → tests/spec}/stubs/responses/open_shell_v2.xml +20 -20
- data/{spec → tests/spec}/stubs/responses/soap_fault_v1.xml +36 -36
- data/{spec → tests/spec}/stubs/responses/soap_fault_v2.xml +42 -42
- data/{spec → tests/spec}/stubs/responses/wmi_error_v2.xml +41 -41
- data/tests/spec/wsmv/cleanup_command_spec.rb +22 -0
- data/tests/spec/wsmv/close_shell_spec.rb +17 -0
- data/{spec → tests/spec/wsmv}/command_output_decoder_spec.rb +37 -37
- data/tests/spec/wsmv/command_output_spec.rb +45 -0
- data/tests/spec/wsmv/command_spec.rb +19 -0
- data/tests/spec/wsmv/configuration_spec.rb +17 -0
- data/tests/spec/wsmv/create_pipeline_spec.rb +31 -0
- data/tests/spec/wsmv/create_shell_spec.rb +38 -0
- data/tests/spec/wsmv/init_runspace_pool_spec.rb +36 -0
- data/tests/spec/wsmv/keep_alive_spec.rb +21 -0
- data/tests/spec/wsmv/receive_response_reader_spec.rb +123 -0
- data/tests/spec/wsmv/send_data_spec.rb +30 -0
- data/tests/spec/wsmv/wql_query_spec.rb +13 -0
- data/tests/spec/wsmv/write_stdin_spec.rb +22 -0
- data/winrm.gemspec +42 -40
- metadata +140 -38
- data/.rspec +0 -3
- data/lib/winrm/command_executor.rb +0 -243
- data/lib/winrm/command_output_decoder.rb +0 -53
- data/lib/winrm/helpers/iso8601_duration.rb +0 -58
- data/lib/winrm/helpers/powershell_script.rb +0 -42
- data/lib/winrm/soap_provider.rb +0 -39
- data/lib/winrm/winrm_service.rb +0 -550
- data/spec/command_executor_spec.rb +0 -475
- data/spec/issue_184_spec.rb +0 -67
- data/spec/powershell_spec.rb +0 -97
- data/spec/winrm_options_spec.rb +0 -76
- data/spec/winrm_primitives_spec.rb +0 -51
@@ -0,0 +1,79 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright 2016 Shawn Neal <sneal@sneal.net>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'nori'
|
18
|
+
require_relative 'base'
|
19
|
+
|
20
|
+
module WinRM
|
21
|
+
module WSMV
|
22
|
+
# WSMV message to query Windows via WQL
|
23
|
+
class WqlQuery < Base
|
24
|
+
def initialize(session_opts, wql)
|
25
|
+
@session_opts = session_opts
|
26
|
+
@wql = wql
|
27
|
+
end
|
28
|
+
|
29
|
+
def process_response(response)
|
30
|
+
parser = Nori.new(
|
31
|
+
parser: :rexml,
|
32
|
+
advanced_typecasting: false,
|
33
|
+
convert_tags_to: ->(tag) { tag.snakecase.to_sym },
|
34
|
+
strip_namespaces: true
|
35
|
+
)
|
36
|
+
hresp = parser.parse(response.to_s)[:envelope][:body]
|
37
|
+
|
38
|
+
# Normalize items so the type always has an array even if it's just a single item.
|
39
|
+
items = {}
|
40
|
+
if hresp[:enumerate_response][:items]
|
41
|
+
hresp[:enumerate_response][:items].each_pair do |k, v|
|
42
|
+
items[k] = v.is_a?(Array) ? v : [v]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
items
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
|
50
|
+
def create_header(header)
|
51
|
+
header << Gyoku.xml(wql_header)
|
52
|
+
end
|
53
|
+
|
54
|
+
def create_body(body)
|
55
|
+
body.tag!("#{NS_ENUM}:Enumerate") { |en| en << Gyoku.xml(wql_body) }
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def wql_header
|
61
|
+
merge_headers(shared_headers(@session_opts), resource_uri_wmi, action_enumerate)
|
62
|
+
end
|
63
|
+
|
64
|
+
def wql_body
|
65
|
+
{
|
66
|
+
"#{NS_WSMAN_DMTF}:OptimizeEnumeration" => nil,
|
67
|
+
"#{NS_WSMAN_DMTF}:MaxElements" => '32000',
|
68
|
+
"#{NS_WSMAN_DMTF}:Filter" => @wql,
|
69
|
+
"#{NS_WSMAN_MSFT}:SessionId" => "uuid:#{@session_opts[:session_id]}",
|
70
|
+
:attributes! => {
|
71
|
+
"#{NS_WSMAN_DMTF}:Filter" => {
|
72
|
+
'Dialect' => 'http://schemas.microsoft.com/wbem/wsman/1/WQL'
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright 2016 Shawn Neal <sneal@sneal.net>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'base64'
|
18
|
+
require_relative 'base'
|
19
|
+
|
20
|
+
module WinRM
|
21
|
+
module WSMV
|
22
|
+
# WSMV message to send stdin to a remote shell
|
23
|
+
class WriteStdin < Base
|
24
|
+
def initialize(session_opts, stdin_opts)
|
25
|
+
validate_opts(session_opts, stdin_opts)
|
26
|
+
init_ops(session_opts, stdin_opts)
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def create_header(header)
|
32
|
+
header << Gyoku.xml(stdin_headers)
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_body(body)
|
36
|
+
body << Gyoku.xml(stdin_body)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def init_ops(session_opts, stdin_opts)
|
42
|
+
@session_opts = session_opts
|
43
|
+
@shell_id = stdin_opts[:shell_id]
|
44
|
+
@command_id = stdin_opts[:command_id]
|
45
|
+
@stdin = stdin_opts[:stdin]
|
46
|
+
@shell_uri = stdin_opts[:shell_uri] || RESOURCE_URI_CMD
|
47
|
+
end
|
48
|
+
|
49
|
+
def validate_opts(session_opts, stdin_opts)
|
50
|
+
raise 'session_opts is required' unless session_opts
|
51
|
+
raise 'stdin_opts[:shell_id] is required' unless stdin_opts[:shell_id]
|
52
|
+
raise 'stdin_opts[:command_id] is required' unless stdin_opts[:command_id]
|
53
|
+
raise 'stdin_opts[:stdin] is required' unless stdin_opts[:stdin]
|
54
|
+
end
|
55
|
+
|
56
|
+
def stdin_headers
|
57
|
+
merge_headers(shared_headers(@session_opts),
|
58
|
+
resource_uri_shell(@shell_uri),
|
59
|
+
action_send,
|
60
|
+
selector_shell_id(@shell_id))
|
61
|
+
end
|
62
|
+
|
63
|
+
def action_send
|
64
|
+
{
|
65
|
+
"#{NS_ADDRESSING}:Action" =>
|
66
|
+
'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Send',
|
67
|
+
:attributes! => {
|
68
|
+
"#{NS_ADDRESSING}:Action" => {
|
69
|
+
'mustUnderstand' => true
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
def stdin_body
|
76
|
+
{
|
77
|
+
"#{NS_WIN_SHELL}:Send" => {
|
78
|
+
"#{NS_WIN_SHELL}:Stream" => {
|
79
|
+
'@Name' => 'stdin',
|
80
|
+
'@CommandId' => @command_id,
|
81
|
+
:content! => Base64.encode64(@stdin)
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/preamble
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
=begin
|
2
|
-
This file is part of WinRM; the Ruby library for Microsoft WinRM.
|
3
|
-
|
4
|
-
Copyright © 2010 Dan Wanek <dan.wanek@gmail.com>
|
5
|
-
|
6
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
you may not use this file except in compliance with the License.
|
8
|
-
You may obtain a copy of the License at
|
9
|
-
|
10
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
|
12
|
-
Unless required by applicable law or agreed to in writing, software
|
13
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
See the License for the specific language governing permissions and
|
16
|
-
limitations under the License.
|
17
|
-
=end
|
1
|
+
=begin
|
2
|
+
This file is part of WinRM; the Ruby library for Microsoft WinRM.
|
3
|
+
|
4
|
+
Copyright © 2010 Dan Wanek <dan.wanek@gmail.com>
|
5
|
+
|
6
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
you may not use this file except in compliance with the License.
|
8
|
+
You may obtain a copy of the License at
|
9
|
+
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
|
12
|
+
Unless required by applicable law or agreed to in writing, software
|
13
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
See the License for the specific language governing permissions and
|
16
|
+
limitations under the License.
|
17
|
+
=end
|
@@ -1,16 +1,18 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
|
4
|
+
# This test may only be meaningful with kerberos auth
|
5
|
+
# Against server 2012, a kerberos connection will require reauth (get a 401)
|
6
|
+
# if there are no requests for >= 15 seconds
|
7
|
+
|
8
|
+
describe 'Verify kerberos will reauth when necessary', kerberos: true do
|
9
|
+
before(:all) do
|
10
|
+
@powershell = winrm_connection.shell(:powershell)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'work with a 18 second sleep' do
|
14
|
+
ps_command = 'Start-Sleep -s 18'
|
15
|
+
output = @powershell.run(ps_command)
|
16
|
+
expect(output.exitcode).to eq(0)
|
17
|
+
end
|
18
|
+
end
|
@@ -1,102 +1,104 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
it { should
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
it { should
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
it { should
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
#
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
it { should
|
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
|
-
it { should
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
it { should
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
it { should
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
|
4
|
+
describe 'winrm client cmd' do
|
5
|
+
before(:all) do
|
6
|
+
@cmd_shell = winrm_connection.shell(:cmd)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'empty string' do
|
10
|
+
subject(:output) { @cmd_shell.run('') }
|
11
|
+
it { should have_exit_code 0 }
|
12
|
+
it { should have_no_stdout }
|
13
|
+
it { should have_no_stderr }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'ipconfig' do
|
17
|
+
subject(:output) { @cmd_shell.run('ipconfig') }
|
18
|
+
it { should have_exit_code 0 }
|
19
|
+
it { should have_stdout_match(/Windows IP Configuration/) }
|
20
|
+
it { should have_no_stderr }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'echo \'hello world\' using apostrophes' do
|
24
|
+
subject(:output) { @cmd_shell.run("echo 'hello world'") }
|
25
|
+
it { should have_exit_code 0 }
|
26
|
+
it { should have_stdout_match(/'hello world'/) }
|
27
|
+
it { should have_no_stderr }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'echo "string with trailing \\" using double quotes' do
|
31
|
+
# This is a regression test for #131. " is converted to " when serializing
|
32
|
+
# the command to SOAP/XML. Any naive substitution performed on such a serialized
|
33
|
+
# string can result in any \& sequence being interpreted as a back-substitution.
|
34
|
+
subject(:output) { @cmd_shell.run('echo "string with trailing \\"') }
|
35
|
+
it { should have_exit_code 0 }
|
36
|
+
it { should have_stdout_match(/string with trailing \\/) }
|
37
|
+
it { should have_no_stderr }
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'capturing output from stdout and stderr' do
|
41
|
+
subject(:output) do
|
42
|
+
# Note: Multiple lines doesn't work:
|
43
|
+
# script = <<-eos
|
44
|
+
# echo Hello
|
45
|
+
# echo , world! 1>&2
|
46
|
+
# eos
|
47
|
+
|
48
|
+
script = 'echo Hello & echo , world! 1>&2'
|
49
|
+
|
50
|
+
@captured_stdout = ''
|
51
|
+
@captured_stderr = ''
|
52
|
+
@cmd_shell.run(script) do |stdout, stderr|
|
53
|
+
@captured_stdout << stdout if stdout
|
54
|
+
@captured_stderr << stderr if stderr
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should have stdout' do
|
59
|
+
expect(output.stdout).to eq("Hello \r\n")
|
60
|
+
expect(output.stdout).to eq(@captured_stdout)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should have stderr' do
|
64
|
+
expect(output.stderr).to eq(", world! \r\n")
|
65
|
+
expect(output.stderr).to eq(@captured_stderr)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should have output' do
|
69
|
+
expect(output.output).to eq("Hello \r\n, world! \r\n")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'ipconfig with /all argument' do
|
74
|
+
subject(:output) { @cmd_shell.run('ipconfig', %w(/all)) }
|
75
|
+
it { should have_exit_code 0 }
|
76
|
+
it { should have_stdout_match(/Windows IP Configuration/) }
|
77
|
+
it { should have_no_stderr }
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'dir with incorrect argument /z' do
|
81
|
+
subject(:output) { @cmd_shell.run('dir /z') }
|
82
|
+
it { should have_exit_code 1 }
|
83
|
+
it { should have_no_stdout }
|
84
|
+
it { should have_stderr_match(/Invalid switch/) }
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'ipconfig && echo error 1>&2' do
|
88
|
+
subject(:output) { @cmd_shell.run('ipconfig && echo error 1>&2') }
|
89
|
+
it { should have_exit_code 0 }
|
90
|
+
it { should have_stdout_match(/Windows IP Configuration/) }
|
91
|
+
it { should have_stderr_match(/error/) }
|
92
|
+
end
|
93
|
+
|
94
|
+
describe 'ipconfig with a block' do
|
95
|
+
subject(:stdout) do
|
96
|
+
outvar = ''
|
97
|
+
@cmd_shell.run('ipconfig') do |stdout, _stderr|
|
98
|
+
outvar << stdout
|
99
|
+
end
|
100
|
+
outvar
|
101
|
+
end
|
102
|
+
it { should match(/Windows IP Configuration/) }
|
103
|
+
end
|
104
|
+
end
|
@@ -1,19 +1,16 @@
|
|
1
|
-
# Copy this file to config.yml and edit the settings below.
|
2
|
-
# This should work out of the box for vagrant provisioned boxes.
|
3
|
-
|
4
|
-
## Kerberos
|
5
|
-
#auth_type: kerberos
|
6
|
-
#
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
#
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
options:
|
18
|
-
user: vagrant
|
19
|
-
pass: vagrant
|
1
|
+
# Copy this file to config.yml and edit the settings below.
|
2
|
+
# This should work out of the box for vagrant provisioned boxes.
|
3
|
+
|
4
|
+
## Kerberos
|
5
|
+
# auth_type: kerberos
|
6
|
+
# realm: "your.realm"
|
7
|
+
# endpoint: "http://<yourserver>:5985/wsman"
|
8
|
+
|
9
|
+
# If you are running this in a vagrant provisioned box using NAT,
|
10
|
+
# this will be the forwarded WinRM HTTP port to your VM.
|
11
|
+
# If you are running this on the VM, the default HTTP port is 5985.
|
12
|
+
# See README.md#Troubleshooting.
|
13
|
+
|
14
|
+
endpoint: "http://localhost:55985/wsman"
|
15
|
+
user: vagrant
|
16
|
+
password: vagrant
|