winrm 1.8.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -11
  3. data/.rubocop.yml +26 -22
  4. data/.travis.yml +11 -12
  5. data/Gemfile +3 -9
  6. data/LICENSE +202 -202
  7. data/README.md +232 -215
  8. data/Rakefile +34 -36
  9. data/Vagrantfile +6 -9
  10. data/WinrmAppveyor.psm1 +31 -31
  11. data/appveyor.yml +51 -51
  12. data/bin/rwinrm +97 -97
  13. data/changelog.md +86 -86
  14. data/lib/winrm.rb +39 -42
  15. data/lib/winrm/connection.rb +82 -0
  16. data/lib/winrm/connection_opts.rb +87 -0
  17. data/lib/winrm/{exceptions/exceptions.rb → exceptions.rb} +76 -57
  18. data/lib/winrm/http/response_handler.rb +96 -82
  19. data/lib/winrm/http/transport.rb +424 -435
  20. data/lib/winrm/http/transport_factory.rb +68 -0
  21. data/lib/winrm/output.rb +59 -43
  22. data/lib/winrm/psrp/create_pipeline.xml.erb +167 -0
  23. data/lib/winrm/psrp/fragment.rb +70 -0
  24. data/lib/winrm/psrp/init_runspace_pool.xml.erb +224 -0
  25. data/lib/winrm/psrp/message.rb +130 -0
  26. data/lib/winrm/psrp/message_data.rb +41 -0
  27. data/lib/winrm/psrp/message_data/base.rb +49 -0
  28. data/lib/winrm/psrp/message_data/error_record.rb +68 -0
  29. data/lib/winrm/psrp/message_data/pipeline_host_call.rb +32 -0
  30. data/lib/winrm/psrp/message_data/pipeline_output.rb +49 -0
  31. data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +32 -0
  32. data/lib/winrm/psrp/message_data/runspacepool_state.rb +39 -0
  33. data/lib/winrm/psrp/message_data/session_capability.rb +36 -0
  34. data/lib/winrm/psrp/message_defragmenter.rb +62 -0
  35. data/lib/winrm/psrp/message_factory.rb +75 -0
  36. data/lib/winrm/psrp/message_fragmenter.rb +60 -0
  37. data/lib/winrm/psrp/powershell_output_decoder.rb +120 -0
  38. data/lib/winrm/psrp/receive_response_reader.rb +93 -0
  39. data/lib/winrm/psrp/session_capability.xml.erb +7 -0
  40. data/lib/winrm/psrp/uuid.rb +40 -0
  41. data/lib/winrm/shells/base.rb +175 -0
  42. data/lib/winrm/shells/cmd.rb +65 -0
  43. data/lib/winrm/shells/power_shell.rb +201 -0
  44. data/lib/winrm/shells/retryable.rb +45 -0
  45. data/lib/winrm/shells/shell_factory.rb +50 -0
  46. data/lib/winrm/version.rb +7 -7
  47. data/lib/winrm/wsmv/base.rb +59 -0
  48. data/lib/winrm/wsmv/cleanup_command.rb +61 -0
  49. data/lib/winrm/wsmv/close_shell.rb +50 -0
  50. data/lib/winrm/wsmv/command.rb +101 -0
  51. data/lib/winrm/wsmv/command_output.rb +76 -0
  52. data/lib/winrm/wsmv/command_output_decoder.rb +55 -0
  53. data/lib/winrm/wsmv/configuration.rb +46 -0
  54. data/lib/winrm/wsmv/create_pipeline.rb +66 -0
  55. data/lib/winrm/wsmv/create_shell.rb +119 -0
  56. data/lib/winrm/wsmv/header.rb +203 -0
  57. data/lib/winrm/wsmv/init_runspace_pool.rb +95 -0
  58. data/lib/winrm/wsmv/iso8601_duration.rb +60 -0
  59. data/lib/winrm/wsmv/keep_alive.rb +68 -0
  60. data/lib/winrm/wsmv/receive_response_reader.rb +128 -0
  61. data/lib/winrm/wsmv/send_data.rb +68 -0
  62. data/lib/winrm/wsmv/soap.rb +51 -0
  63. data/lib/winrm/wsmv/wql_query.rb +79 -0
  64. data/lib/winrm/wsmv/write_stdin.rb +88 -0
  65. data/preamble +17 -17
  66. data/{spec → tests/integration}/auth_timeout_spec.rb +18 -16
  67. data/{spec → tests/integration}/cmd_spec.rb +104 -102
  68. data/{spec → tests/integration}/config-example.yml +16 -19
  69. data/{spec → tests/integration}/issue_59_spec.rb +26 -23
  70. data/tests/integration/powershell_spec.rb +154 -0
  71. data/{spec → tests/integration}/spec_helper.rb +65 -73
  72. data/{spec → tests/integration}/transport_spec.rb +99 -139
  73. data/{spec → tests/integration}/wql_spec.rb +16 -14
  74. data/{spec → tests}/matchers.rb +60 -74
  75. data/tests/spec/configuration_spec.rb +93 -0
  76. data/tests/spec/connection_spec.rb +39 -0
  77. data/{spec → tests/spec}/exception_spec.rb +50 -50
  78. data/tests/spec/http/transport_factory_spec.rb +68 -0
  79. data/tests/spec/http/transport_spec.rb +44 -0
  80. data/{spec → tests/spec}/output_spec.rb +127 -110
  81. data/tests/spec/psrp/fragment_spec.rb +62 -0
  82. data/tests/spec/psrp/message_data/base_spec.rb +13 -0
  83. data/tests/spec/psrp/message_data/error_record_spec.rb +41 -0
  84. data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +25 -0
  85. data/tests/spec/psrp/message_data/pipeline_output_spec.rb +32 -0
  86. data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +25 -0
  87. data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +16 -0
  88. data/tests/spec/psrp/message_data/session_capability_spec.rb +30 -0
  89. data/tests/spec/psrp/message_data_spec.rb +35 -0
  90. data/tests/spec/psrp/message_defragmenter_spec.rb +47 -0
  91. data/tests/spec/psrp/message_fragmenter_spec.rb +105 -0
  92. data/tests/spec/psrp/powershell_output_decoder_spec.rb +84 -0
  93. data/tests/spec/psrp/psrp_message_spec.rb +70 -0
  94. data/tests/spec/psrp/recieve_response_reader_spec.rb +154 -0
  95. data/tests/spec/psrp/uuid_spec.rb +28 -0
  96. data/{spec → tests/spec}/response_handler_spec.rb +61 -61
  97. data/tests/spec/shells/base_spec.rb +202 -0
  98. data/tests/spec/shells/cmd_spec.rb +75 -0
  99. data/tests/spec/shells/powershell_spec.rb +175 -0
  100. data/tests/spec/spec_helper.rb +47 -0
  101. data/tests/spec/stubs/clixml/error_record.xml.erb +84 -0
  102. data/{spec → tests/spec}/stubs/responses/get_command_output_response.xml.erb +13 -13
  103. data/tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb +10 -0
  104. data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +10 -0
  105. data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +12 -0
  106. data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +9 -0
  107. data/{spec → tests/spec}/stubs/responses/open_shell_v1.xml +19 -19
  108. data/{spec → tests/spec}/stubs/responses/open_shell_v2.xml +20 -20
  109. data/{spec → tests/spec}/stubs/responses/soap_fault_v1.xml +36 -36
  110. data/{spec → tests/spec}/stubs/responses/soap_fault_v2.xml +42 -42
  111. data/{spec → tests/spec}/stubs/responses/wmi_error_v2.xml +41 -41
  112. data/tests/spec/wsmv/cleanup_command_spec.rb +22 -0
  113. data/tests/spec/wsmv/close_shell_spec.rb +17 -0
  114. data/{spec → tests/spec/wsmv}/command_output_decoder_spec.rb +37 -37
  115. data/tests/spec/wsmv/command_output_spec.rb +45 -0
  116. data/tests/spec/wsmv/command_spec.rb +19 -0
  117. data/tests/spec/wsmv/configuration_spec.rb +17 -0
  118. data/tests/spec/wsmv/create_pipeline_spec.rb +31 -0
  119. data/tests/spec/wsmv/create_shell_spec.rb +38 -0
  120. data/tests/spec/wsmv/init_runspace_pool_spec.rb +36 -0
  121. data/tests/spec/wsmv/keep_alive_spec.rb +21 -0
  122. data/tests/spec/wsmv/receive_response_reader_spec.rb +123 -0
  123. data/tests/spec/wsmv/send_data_spec.rb +30 -0
  124. data/tests/spec/wsmv/wql_query_spec.rb +13 -0
  125. data/tests/spec/wsmv/write_stdin_spec.rb +22 -0
  126. data/winrm.gemspec +42 -40
  127. metadata +140 -38
  128. data/.rspec +0 -3
  129. data/lib/winrm/command_executor.rb +0 -243
  130. data/lib/winrm/command_output_decoder.rb +0 -53
  131. data/lib/winrm/helpers/iso8601_duration.rb +0 -58
  132. data/lib/winrm/helpers/powershell_script.rb +0 -42
  133. data/lib/winrm/soap_provider.rb +0 -39
  134. data/lib/winrm/winrm_service.rb +0 -550
  135. data/spec/command_executor_spec.rb +0 -475
  136. data/spec/issue_184_spec.rb +0 -67
  137. data/spec/powershell_spec.rb +0 -97
  138. data/spec/winrm_options_spec.rb +0 -76
  139. 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
- # This test may only be meaningful with kerberos auth
3
- # Against server 2012, a kerberos connection will require reauth (get a 401)
4
- # if there are no requests for >= 15 seconds
5
-
6
- describe 'Verify kerberos will reauth when necessary', kerberos: true do
7
- before(:all) do
8
- @winrm = winrm_connection
9
- end
10
-
11
- it 'work with a 18 second sleep' do
12
- ps_command = 'Start-Sleep -s 18'
13
- output = @winrm.run_powershell_script(ps_command)
14
- output[:exitcode].should == 0
15
- end
16
- end
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
- describe 'winrm client cmd', integration: true do
3
- before(:all) do
4
- @winrm = winrm_connection
5
- end
6
-
7
- describe 'empty string' do
8
- subject(:output) { @winrm.cmd('') }
9
- it { should have_exit_code 0 }
10
- it { should have_no_stdout }
11
- it { should have_no_stderr }
12
- end
13
-
14
- describe 'ipconfig' do
15
- subject(:output) { @winrm.cmd('ipconfig') }
16
- it { should have_exit_code 0 }
17
- it { should have_stdout_match(/Windows IP Configuration/) }
18
- it { should have_no_stderr }
19
- end
20
-
21
- describe 'echo \'hello world\' using apostrophes' do
22
- subject(:output) { @winrm.cmd("echo 'hello world'") }
23
- it { should have_exit_code 0 }
24
- it { should have_stdout_match(/'hello world'/) }
25
- it { should have_no_stderr }
26
- end
27
-
28
- describe 'echo "string with trailing \\" using double quotes' do
29
- # This is a regression test for #131. " is converted to &quot; when serializing
30
- # the command to SOAP/XML. Any naive substitution performed on such a serialized
31
- # string can result in any \& sequence being interpreted as a back-substitution.
32
- subject(:output) { @winrm.cmd('echo "string with trailing \\"') }
33
- it { should have_exit_code 0 }
34
- it { should have_stdout_match(/string with trailing \\/) }
35
- it { should have_no_stderr }
36
- end
37
-
38
- describe 'capturing output from stdout and stderr' do
39
- subject(:output) do
40
- # Note: Multiple lines doesn't work:
41
- # script = <<-eos
42
- # echo Hello
43
- # echo , world! 1>&2
44
- # eos
45
-
46
- script = 'echo Hello & echo , world! 1>&2'
47
-
48
- @captured_stdout = ''
49
- @captured_stderr = ''
50
- @winrm.cmd(script) do |stdout, stderr|
51
- @captured_stdout << stdout if stdout
52
- @captured_stderr << stderr if stderr
53
- end
54
- end
55
-
56
- it 'should have stdout' do
57
- expect(output.stdout).to eq("Hello \r\n")
58
- expect(output.stdout).to eq(@captured_stdout)
59
- end
60
-
61
- it 'should have stderr' do
62
- expect(output.stderr).to eq(", world! \r\n")
63
- expect(output.stderr).to eq(@captured_stderr)
64
- end
65
-
66
- it 'should have output' do
67
- expect(output.output).to eq("Hello \r\n, world! \r\n")
68
- end
69
- end
70
-
71
- describe 'ipconfig with /all argument' do
72
- subject(:output) { @winrm.cmd('ipconfig', %w(/all)) }
73
- it { should have_exit_code 0 }
74
- it { should have_stdout_match(/Windows IP Configuration/) }
75
- it { should have_no_stderr }
76
- end
77
-
78
- describe 'dir with incorrect argument /z' do
79
- subject(:output) { @winrm.cmd('dir /z') }
80
- it { should have_exit_code 1 }
81
- it { should have_no_stdout }
82
- it { should have_stderr_match(/Invalid switch/) }
83
- end
84
-
85
- describe 'ipconfig && echo error 1>&2' do
86
- subject(:output) { @winrm.cmd('ipconfig && echo error 1>&2') }
87
- it { should have_exit_code 0 }
88
- it { should have_stdout_match(/Windows IP Configuration/) }
89
- it { should have_stderr_match(/error/) }
90
- end
91
-
92
- describe 'ipconfig with a block' do
93
- subject(:stdout) do
94
- outvar = ''
95
- @winrm.cmd('ipconfig') do |stdout, _stderr|
96
- outvar << stdout
97
- end
98
- outvar
99
- end
100
- it { should match(/Windows IP Configuration/) }
101
- end
102
- end
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 &quot; 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
- #endpoint: "http://<yourserver>:5985/wsman"
7
- #options:
8
- # realm: "your.realm"
9
-
10
- ## Plain Text
11
- auth_type: plaintext
12
- # If you are running this in a vagrant provisioned box using NAT,
13
- # this will be the forwarded WinRM HTTP port to your VM.
14
- # If you are running this on the VM, the default HTTP port is 5985.
15
- # See README.md#Troubleshooting.
16
- endpoint: "http://localhost:55985/wsman"
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