winrm 2.3.0 → 2.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/winrm/http/response_handler.rb +1 -1
- data/lib/winrm/http/transport.rb +2 -2
- data/lib/winrm/psrp/message.rb +128 -128
- data/lib/winrm/psrp/message_data/error_record.rb +2 -0
- data/lib/winrm/psrp/message_data/pipeline_output.rb +1 -1
- data/lib/winrm/psrp/message_factory.rb +14 -2
- data/lib/winrm/psrp/powershell_output_decoder.rb +142 -142
- data/lib/winrm/shells/base.rb +1 -0
- data/lib/winrm/shells/power_shell.rb +4 -4
- data/lib/winrm/version.rb +1 -1
- metadata +16 -90
- data/.gitignore +0 -10
- data/.rubocop.yml +0 -38
- data/.travis.yml +0 -10
- data/Gemfile +0 -2
- data/Rakefile +0 -33
- data/Vagrantfile +0 -6
- data/WinrmAppveyor.psm1 +0 -32
- data/appveyor.yml +0 -50
- data/changelog.md +0 -133
- data/preamble +0 -17
- data/tests/integration/auth_timeout_spec.rb +0 -17
- data/tests/integration/cmd_spec.rb +0 -130
- data/tests/integration/config-example.yml +0 -16
- data/tests/integration/issue_59_spec.rb +0 -25
- data/tests/integration/powershell_spec.rb +0 -164
- data/tests/integration/spec_helper.rb +0 -62
- data/tests/integration/transport_spec.rb +0 -98
- data/tests/integration/wql_spec.rb +0 -33
- data/tests/matchers.rb +0 -59
- data/tests/spec/configuration_spec.rb +0 -183
- data/tests/spec/connection_spec.rb +0 -37
- data/tests/spec/exception_spec.rb +0 -49
- data/tests/spec/http/transport_factory_spec.rb +0 -66
- data/tests/spec/http/transport_spec.rb +0 -43
- data/tests/spec/output_spec.rb +0 -128
- data/tests/spec/psrp/fragment_spec.rb +0 -60
- data/tests/spec/psrp/message_data/base_spec.rb +0 -11
- data/tests/spec/psrp/message_data/error_record_spec.rb +0 -39
- data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +0 -23
- data/tests/spec/psrp/message_data/pipeline_output_spec.rb +0 -30
- data/tests/spec/psrp/message_data/pipeline_state_spec.rb +0 -38
- data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +0 -23
- data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +0 -14
- data/tests/spec/psrp/message_data/session_capability_spec.rb +0 -28
- data/tests/spec/psrp/message_data_spec.rb +0 -33
- data/tests/spec/psrp/message_defragmenter_spec.rb +0 -45
- data/tests/spec/psrp/message_fragmenter_spec.rb +0 -103
- data/tests/spec/psrp/powershell_output_decoder_spec.rb +0 -98
- data/tests/spec/psrp/psrp_message_spec.rb +0 -73
- data/tests/spec/psrp/recieve_response_reader_spec.rb +0 -170
- data/tests/spec/psrp/uuid_spec.rb +0 -28
- data/tests/spec/response_handler_spec.rb +0 -69
- data/tests/spec/shells/base_spec.rb +0 -227
- data/tests/spec/shells/cmd_spec.rb +0 -75
- data/tests/spec/shells/powershell_spec.rb +0 -221
- data/tests/spec/spec_helper.rb +0 -46
- data/tests/spec/stubs/clixml/error_record.xml.erb +0 -84
- data/tests/spec/stubs/clixml/pipeline_state.xml.erb +0 -88
- data/tests/spec/stubs/responses/get_command_output_response.xml.erb +0 -13
- data/tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb +0 -10
- data/tests/spec/stubs/responses/get_omi_command_output_response.xml.erb +0 -23
- data/tests/spec/stubs/responses/get_omi_command_output_response_not_done.xml.erb +0 -24
- data/tests/spec/stubs/responses/get_omi_config_response.xml +0 -45
- data/tests/spec/stubs/responses/get_omi_powershell_keepalive_response.xml.erb +0 -33
- data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +0 -10
- data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +0 -12
- data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +0 -9
- data/tests/spec/stubs/responses/open_shell_omi.xml +0 -43
- data/tests/spec/stubs/responses/open_shell_v1.xml +0 -19
- data/tests/spec/stubs/responses/open_shell_v2.xml +0 -20
- data/tests/spec/stubs/responses/soap_fault_omi.xml +0 -31
- data/tests/spec/stubs/responses/soap_fault_v1.xml +0 -36
- data/tests/spec/stubs/responses/soap_fault_v2.xml +0 -42
- data/tests/spec/stubs/responses/wmi_error_v2.xml +0 -41
- data/tests/spec/wsmv/cleanup_command_spec.rb +0 -20
- data/tests/spec/wsmv/close_shell_spec.rb +0 -15
- data/tests/spec/wsmv/command_output_decoder_spec.rb +0 -35
- data/tests/spec/wsmv/command_output_spec.rb +0 -43
- data/tests/spec/wsmv/command_spec.rb +0 -17
- data/tests/spec/wsmv/configuration_spec.rb +0 -15
- data/tests/spec/wsmv/create_pipeline_spec.rb +0 -30
- data/tests/spec/wsmv/create_shell_spec.rb +0 -39
- data/tests/spec/wsmv/init_runspace_pool_spec.rb +0 -38
- data/tests/spec/wsmv/keep_alive_spec.rb +0 -21
- data/tests/spec/wsmv/receive_response_reader_spec.rb +0 -124
- data/tests/spec/wsmv/send_data_spec.rb +0 -30
- data/tests/spec/wsmv/wql_query_spec.rb +0 -11
- data/tests/spec/wsmv/write_stdin_spec.rb +0 -20
- data/winrm.gemspec +0 -46
data/preamble
DELETED
@@ -1,17 +0,0 @@
|
|
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,17 +0,0 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
|
3
|
-
# This test may only be meaningful with kerberos auth
|
4
|
-
# Against server 2012, a kerberos connection will require reauth (get a 401)
|
5
|
-
# if there are no requests for >= 15 seconds
|
6
|
-
|
7
|
-
describe 'Verify kerberos will reauth when necessary', kerberos: true do
|
8
|
-
before(:all) do
|
9
|
-
@powershell = winrm_connection.shell(:powershell)
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'work with a 18 second sleep' do
|
13
|
-
ps_command = 'Start-Sleep -s 18'
|
14
|
-
output = @powershell.run(ps_command)
|
15
|
-
expect(output.exitcode).to eq(0)
|
16
|
-
end
|
17
|
-
end
|
@@ -1,130 +0,0 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
|
3
|
-
describe 'winrm client cmd' do
|
4
|
-
before(:all) do
|
5
|
-
@cmd_shell = winrm_connection.shell(:cmd)
|
6
|
-
end
|
7
|
-
|
8
|
-
describe 'empty string' do
|
9
|
-
subject(:output) { @cmd_shell.run('') }
|
10
|
-
it { should have_exit_code 0 }
|
11
|
-
it { should have_no_stdout }
|
12
|
-
it { should have_no_stderr }
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'ipconfig' do
|
16
|
-
subject(:output) { @cmd_shell.run('ipconfig') }
|
17
|
-
it { should have_exit_code 0 }
|
18
|
-
it { should have_stdout_match(/Windows IP Configuration/) }
|
19
|
-
it { should have_no_stderr }
|
20
|
-
end
|
21
|
-
|
22
|
-
describe 'codepage' do
|
23
|
-
let(:options) { {} }
|
24
|
-
let(:shell) { winrm_connection.shell(:cmd, options) }
|
25
|
-
|
26
|
-
after { shell.close }
|
27
|
-
|
28
|
-
subject(:output) { shell.run('chcp') }
|
29
|
-
|
30
|
-
it 'should default to UTF-8 (65001)' do
|
31
|
-
should have_stdout_match(/Active code page: 65001/)
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'when changing the codepage' do
|
35
|
-
let(:options) { { codepage: 437 } }
|
36
|
-
|
37
|
-
it 'sets the codepage to the one given' do
|
38
|
-
should have_stdout_match(/Active code page: 437/)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe 'echo \'hello world\' using apostrophes' do
|
44
|
-
subject(:output) { @cmd_shell.run("echo 'hello world'") }
|
45
|
-
it { should have_exit_code 0 }
|
46
|
-
it { should have_stdout_match(/'hello world'/) }
|
47
|
-
it { should have_no_stderr }
|
48
|
-
end
|
49
|
-
|
50
|
-
describe 'multi stream output from large file' do
|
51
|
-
subject(:output) { @cmd_shell.run('type c:\windows\logs\dism\dism.log') }
|
52
|
-
it { should have_exit_code 0 }
|
53
|
-
it { should have_no_stderr }
|
54
|
-
end
|
55
|
-
|
56
|
-
describe 'echo "string with trailing \\" using double quotes' do
|
57
|
-
# This is a regression test for #131. " is converted to " when serializing
|
58
|
-
# the command to SOAP/XML. Any naive substitution performed on such a serialized
|
59
|
-
# string can result in any \& sequence being interpreted as a back-substitution.
|
60
|
-
subject(:output) { @cmd_shell.run('echo "string with trailing \\"') }
|
61
|
-
it { should have_exit_code 0 }
|
62
|
-
it { should have_stdout_match(/string with trailing \\/) }
|
63
|
-
it { should have_no_stderr }
|
64
|
-
end
|
65
|
-
|
66
|
-
describe 'capturing output from stdout and stderr' do
|
67
|
-
subject(:output) do
|
68
|
-
# Note: Multiple lines doesn't work:
|
69
|
-
# script = <<-eos
|
70
|
-
# echo Hello
|
71
|
-
# echo , world! 1>&2
|
72
|
-
# eos
|
73
|
-
|
74
|
-
script = 'echo Hello & echo , world! 1>&2'
|
75
|
-
|
76
|
-
@captured_stdout = ''
|
77
|
-
@captured_stderr = ''
|
78
|
-
@cmd_shell.run(script) do |stdout, stderr|
|
79
|
-
@captured_stdout << stdout if stdout
|
80
|
-
@captured_stderr << stderr if stderr
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'should have stdout' do
|
85
|
-
expect(output.stdout).to eq("Hello \r\n")
|
86
|
-
expect(output.stdout).to eq(@captured_stdout)
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'should have stderr' do
|
90
|
-
expect(output.stderr).to eq(", world! \r\n")
|
91
|
-
expect(output.stderr).to eq(@captured_stderr)
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'should have output' do
|
95
|
-
expect(output.output).to eq("Hello \r\n, world! \r\n")
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe 'ipconfig with /all argument' do
|
100
|
-
subject(:output) { @cmd_shell.run('ipconfig', %w[/all]) }
|
101
|
-
it { should have_exit_code 0 }
|
102
|
-
it { should have_stdout_match(/Windows IP Configuration/) }
|
103
|
-
it { should have_no_stderr }
|
104
|
-
end
|
105
|
-
|
106
|
-
describe 'dir with incorrect argument /z' do
|
107
|
-
subject(:output) { @cmd_shell.run('dir /z') }
|
108
|
-
it { should have_exit_code 1 }
|
109
|
-
it { should have_no_stdout }
|
110
|
-
it { should have_stderr_match(/Invalid switch/) }
|
111
|
-
end
|
112
|
-
|
113
|
-
describe 'ipconfig && echo error 1>&2' do
|
114
|
-
subject(:output) { @cmd_shell.run('ipconfig && echo error 1>&2') }
|
115
|
-
it { should have_exit_code 0 }
|
116
|
-
it { should have_stdout_match(/Windows IP Configuration/) }
|
117
|
-
it { should have_stderr_match(/error/) }
|
118
|
-
end
|
119
|
-
|
120
|
-
describe 'ipconfig with a block' do
|
121
|
-
subject(:stdout) do
|
122
|
-
outvar = ''
|
123
|
-
@cmd_shell.run('ipconfig') do |stdout, _stderr|
|
124
|
-
outvar << stdout
|
125
|
-
end
|
126
|
-
outvar
|
127
|
-
end
|
128
|
-
it { should match(/Windows IP Configuration/) }
|
129
|
-
end
|
130
|
-
end
|
@@ -1,16 +0,0 @@
|
|
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
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
|
3
|
-
describe 'issue 59' do
|
4
|
-
describe 'long running script without output' do
|
5
|
-
let(:logged_output) { StringIO.new }
|
6
|
-
let(:logger) { Logging.logger(logged_output) }
|
7
|
-
|
8
|
-
before do
|
9
|
-
opts = connection_opts.dup
|
10
|
-
opts[:operation_timeout] = 1
|
11
|
-
conn = WinRM::Connection.new(opts)
|
12
|
-
conn.logger = logger
|
13
|
-
@powershell = conn.shell(:powershell)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should not error' do
|
17
|
-
out = @powershell.run('$ProgressPreference="SilentlyContinue";sleep 3; Write-Host "Hello"')
|
18
|
-
|
19
|
-
expect(out).to have_exit_code 0
|
20
|
-
expect(out).to have_stdout_match(/Hello/)
|
21
|
-
expect(out).to have_no_stderr
|
22
|
-
expect(logged_output.string).to match(/retrying receive request/)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,164 +0,0 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
|
3
|
-
describe 'winrm client powershell' do
|
4
|
-
before(:all) do
|
5
|
-
@powershell = winrm_connection.shell(:powershell)
|
6
|
-
end
|
7
|
-
|
8
|
-
describe 'ipconfig' do
|
9
|
-
subject(:output) { @powershell.run('ipconfig') }
|
10
|
-
it { should have_exit_code 0 }
|
11
|
-
it { should have_stdout_match(/Windows IP Configuration/) }
|
12
|
-
it { should have_no_stderr }
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'ipconfig with invalid args' do
|
16
|
-
subject(:output) { @powershell.run('ipconfig blah') }
|
17
|
-
it { should have_exit_code 1 }
|
18
|
-
end
|
19
|
-
|
20
|
-
describe 'throw' do
|
21
|
-
subject(:output) { @powershell.run("throw 'an error occured'") }
|
22
|
-
it { should have_exit_code 0 }
|
23
|
-
it { should have_stderr_match(/an error occured/) }
|
24
|
-
end
|
25
|
-
|
26
|
-
describe 'exit' do
|
27
|
-
subject(:output) { @powershell.run('exit 5') }
|
28
|
-
it { should have_exit_code 5 }
|
29
|
-
end
|
30
|
-
|
31
|
-
describe 'echo \'hello world\' using apostrophes' do
|
32
|
-
subject(:output) { @powershell.run("echo 'hello world'") }
|
33
|
-
it { should have_exit_code 0 }
|
34
|
-
it { should have_stdout_match(/hello world/) }
|
35
|
-
it { should have_no_stderr }
|
36
|
-
end
|
37
|
-
|
38
|
-
describe 'handling special XML characters' do
|
39
|
-
subject(:output) { @powershell.run("echo 'hello & <world>'") }
|
40
|
-
it { should have_exit_code 0 }
|
41
|
-
it { should have_stdout_match(/hello & <world>/) }
|
42
|
-
it { should have_no_stderr }
|
43
|
-
end
|
44
|
-
|
45
|
-
describe 'dir with incorrect argument /z' do
|
46
|
-
subject(:output) { @powershell.run('dir /z') }
|
47
|
-
it { should have_stderr_match(/Cannot find path/) }
|
48
|
-
it { should have_no_stdout }
|
49
|
-
end
|
50
|
-
|
51
|
-
describe 'Math area calculation' do
|
52
|
-
subject(:output) do
|
53
|
-
@powershell.run <<-EOH
|
54
|
-
$diameter = 4.5
|
55
|
-
$area = [Math]::pow([Math]::PI * ($diameter/2), 2)
|
56
|
-
Write-Host $area
|
57
|
-
EOH
|
58
|
-
end
|
59
|
-
it { should have_exit_code 0 }
|
60
|
-
it { should have_stdout_match(/49.9648722805149/) }
|
61
|
-
it { should have_no_stderr }
|
62
|
-
end
|
63
|
-
|
64
|
-
describe 'ipconfig with a block' do
|
65
|
-
subject(:stdout) do
|
66
|
-
outvar = ''
|
67
|
-
@powershell.run('ipconfig') do |stdout, _stderr|
|
68
|
-
outvar << stdout
|
69
|
-
end
|
70
|
-
outvar
|
71
|
-
end
|
72
|
-
it { should match(/Windows IP Configuration/) }
|
73
|
-
end
|
74
|
-
|
75
|
-
describe 'capturing output from Write-Host and Write-Error' do
|
76
|
-
subject(:output) do
|
77
|
-
script = <<-EOS
|
78
|
-
Write-Host 'Hello'
|
79
|
-
$host.ui.WriteErrorLine(', world!')
|
80
|
-
EOS
|
81
|
-
|
82
|
-
@captured_stdout = ''
|
83
|
-
@captured_stderr = ''
|
84
|
-
@powershell.run(script) do |stdout, stderr|
|
85
|
-
@captured_stdout << stdout if stdout
|
86
|
-
@captured_stderr << stderr if stderr
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'should have stdout' do
|
91
|
-
expect(output.stdout).to eq("Hello\r\n")
|
92
|
-
expect(output.stdout).to eq(@captured_stdout)
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'should have stderr' do
|
96
|
-
expect(output.stderr).to eq(", world!\r\n")
|
97
|
-
expect(output.stderr).to eq(@captured_stderr)
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'should have output' do
|
101
|
-
expect(output.output).to eq("Hello\r\n, world!\r\n")
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe 'capturing output from pipeline followed by Host' do
|
106
|
-
subject(:output) do
|
107
|
-
script = <<-EOS
|
108
|
-
Write-Output 'output'
|
109
|
-
$host.UI.Writeline('host')
|
110
|
-
EOS
|
111
|
-
|
112
|
-
@captured_stdout = ''
|
113
|
-
@captured_stderr = ''
|
114
|
-
@powershell.run(script) do |stdout, stderr|
|
115
|
-
@captured_stdout << stdout if stdout
|
116
|
-
@captured_stderr << stderr if stderr
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'should print from the pipeline first' do
|
121
|
-
expect(output.stdout).to start_with("output\r\n")
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'should write to host last' do
|
125
|
-
expect(output.stdout).to end_with("host\r\n")
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
describe 'it should handle utf-8 characters' do
|
130
|
-
subject(:output) { @powershell.run('echo "✓1234-äöü"') }
|
131
|
-
it { should have_exit_code 0 }
|
132
|
-
it { should have_stdout_match(/✓1234-äöü/) }
|
133
|
-
end
|
134
|
-
|
135
|
-
describe 'output exceeds a single fragment' do
|
136
|
-
subject(:output) { @powershell.run('Write-Output $("a"*600000)') }
|
137
|
-
it { should have_exit_code 0 }
|
138
|
-
it 'has assebled the output' do
|
139
|
-
expect(output.stdout).to eq('a' * 600000 + "\r\n")
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
describe 'command exceeds a single fragment' do
|
144
|
-
subject(:output) { @powershell.run("$var='#{'a' * 600000}';Write-Output 'long var'") }
|
145
|
-
it { should have_exit_code 0 }
|
146
|
-
it 'has sent the output' do
|
147
|
-
expect(output.stdout).to eq("long var\r\n")
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe 'reading pipeline messages' do
|
152
|
-
subject(:messages) { @powershell.send_pipeline_command('ipconfig') }
|
153
|
-
|
154
|
-
it 'returns multiple messages' do
|
155
|
-
expect(messages.length).to be > 1
|
156
|
-
end
|
157
|
-
it 'first message is pipeline output' do
|
158
|
-
expect(messages.first.type).to eq(WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output])
|
159
|
-
end
|
160
|
-
it 'last message is pipeline state' do
|
161
|
-
expect(messages.last.type).to eq(WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_state])
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler/setup'
|
3
|
-
require 'winrm'
|
4
|
-
require 'json'
|
5
|
-
require_relative '../matchers'
|
6
|
-
|
7
|
-
# Creates a WinRM connection for integration tests
|
8
|
-
module ConnectionHelper
|
9
|
-
def winrm_connection
|
10
|
-
WinRM::Connection.new(connection_opts)
|
11
|
-
end
|
12
|
-
|
13
|
-
def connection_opts
|
14
|
-
@connection_opts ||= begin
|
15
|
-
cfg = symbolize_keys(YAML.safe_load(File.read(winrm_config_path)))
|
16
|
-
merge_environment(cfg)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def merge_environment(config)
|
21
|
-
merge_config_option_from_environment(config, 'user')
|
22
|
-
merge_config_option_from_environment(config, 'password')
|
23
|
-
merge_config_option_from_environment(config, 'no_ssl_peer_verification')
|
24
|
-
config[:ssl_peer_fingerprint] = ENV['winrm_cert'] if ENV['use_ssl_peer_fingerprint']
|
25
|
-
config[:endpoint] = ENV['winrm_endpoint'] if ENV['winrm_endpoint']
|
26
|
-
config
|
27
|
-
end
|
28
|
-
|
29
|
-
def merge_config_option_from_environment(config, key)
|
30
|
-
env_key = 'winrm_' + key
|
31
|
-
config[key.to_sym] = ENV[env_key] if ENV[env_key]
|
32
|
-
end
|
33
|
-
|
34
|
-
def winrm_config_path
|
35
|
-
# Copy config-example.yml to config.yml and edit for your local ConnectionOpts
|
36
|
-
path = File.expand_path("#{File.dirname(__FILE__)}/config.yml")
|
37
|
-
unless File.exist?(path)
|
38
|
-
# user hasn't done this, so use sane defaults for unit tests
|
39
|
-
path = File.expand_path("#{File.dirname(__FILE__)}/config-example.yml")
|
40
|
-
end
|
41
|
-
path
|
42
|
-
end
|
43
|
-
|
44
|
-
def symbolize_keys(hash)
|
45
|
-
hash.each_with_object({}) do |(key, value), result|
|
46
|
-
new_key = case key
|
47
|
-
when String then key.to_sym
|
48
|
-
else key
|
49
|
-
end
|
50
|
-
new_value = case value
|
51
|
-
when Hash then symbolize_keys(value)
|
52
|
-
else value
|
53
|
-
end
|
54
|
-
result[new_key] = new_value
|
55
|
-
result
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
RSpec.configure do |config|
|
61
|
-
config.include(ConnectionHelper)
|
62
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
|
3
|
-
describe 'WinRM connection' do
|
4
|
-
let(:connection) do
|
5
|
-
endpoint = connection_opts[:endpoint].dup
|
6
|
-
if auth_type == :ssl
|
7
|
-
endpoint.sub!('5985', '5986')
|
8
|
-
endpoint.sub!('http', 'https')
|
9
|
-
end
|
10
|
-
conn_options = {
|
11
|
-
transport: auth_type,
|
12
|
-
endpoint: endpoint
|
13
|
-
}.merge(options)
|
14
|
-
WinRM::Connection.new(conn_options).shell(:cmd)
|
15
|
-
end
|
16
|
-
let(:options) do
|
17
|
-
opts = {}
|
18
|
-
opts[:user] = connection_opts[:user]
|
19
|
-
opts[:password] = connection_opts[:password]
|
20
|
-
opts[:basic_auth_only] = basic_auth_only
|
21
|
-
opts[:no_ssl_peer_verification] = no_ssl_peer_verification
|
22
|
-
opts[:ssl_peer_fingerprint] = ssl_peer_fingerprint
|
23
|
-
opts[:client_cert] = user_cert
|
24
|
-
opts[:client_key] = user_key
|
25
|
-
opts
|
26
|
-
end
|
27
|
-
let(:basic_auth_only) { false }
|
28
|
-
let(:no_ssl_peer_verification) { false }
|
29
|
-
let(:ssl_peer_fingerprint) { nil }
|
30
|
-
let(:user_cert) { nil }
|
31
|
-
let(:user_key) { nil }
|
32
|
-
|
33
|
-
subject(:output) { connection.run('ipconfig') }
|
34
|
-
|
35
|
-
after(:each) do
|
36
|
-
connection.close
|
37
|
-
end
|
38
|
-
|
39
|
-
shared_examples 'a valid_connection' do
|
40
|
-
it 'has a 0 exit code' do
|
41
|
-
expect(subject).to have_exit_code 0
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'includes command output' do
|
45
|
-
expect(subject).to have_stdout_match(/Windows IP Configuration/)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'has no errors' do
|
49
|
-
expect(subject).to have_no_stderr
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'HttpPlaintext' do
|
54
|
-
let(:basic_auth_only) { true }
|
55
|
-
let(:auth_type) { :plaintext }
|
56
|
-
|
57
|
-
it_behaves_like 'a valid_connection'
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'HttpNegotiate' do
|
61
|
-
let(:auth_type) { :negotiate }
|
62
|
-
|
63
|
-
it_behaves_like 'a valid_connection'
|
64
|
-
end
|
65
|
-
|
66
|
-
context 'BasicAuthSSL', skip: ENV['winrm_cert'].nil? do
|
67
|
-
let(:basic_auth_only) { true }
|
68
|
-
let(:auth_type) { :ssl }
|
69
|
-
let(:no_ssl_peer_verification) { true }
|
70
|
-
|
71
|
-
it_behaves_like 'a valid_connection'
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'ClientCertAuthSSL', skip: ENV['user_cert'].nil? do
|
75
|
-
let(:auth_type) { :ssl }
|
76
|
-
let(:no_ssl_peer_verification) { true }
|
77
|
-
let(:user_cert) { ENV['user_cert'] }
|
78
|
-
let(:user_key) { ENV['user_key'] }
|
79
|
-
|
80
|
-
before { options[:pass] = nil }
|
81
|
-
|
82
|
-
it_behaves_like 'a valid_connection'
|
83
|
-
end
|
84
|
-
|
85
|
-
context 'Negotiate over SSL', skip: ENV['winrm_cert'].nil? do
|
86
|
-
let(:auth_type) { :ssl }
|
87
|
-
let(:no_ssl_peer_verification) { true }
|
88
|
-
|
89
|
-
it_behaves_like 'a valid_connection'
|
90
|
-
end
|
91
|
-
|
92
|
-
context 'SSL fingerprint', skip: ENV['winrm_cert'].nil? do
|
93
|
-
let(:auth_type) { :ssl }
|
94
|
-
let(:ssl_peer_fingerprint) { ENV['winrm_cert'] }
|
95
|
-
|
96
|
-
it_behaves_like 'a valid_connection'
|
97
|
-
end
|
98
|
-
end
|