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
data/spec/issue_184_spec.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'winrm/winrm_service'
|
3
|
-
require 'rexml/document'
|
4
|
-
require 'erb'
|
5
|
-
require 'base64'
|
6
|
-
|
7
|
-
describe 'issue 184', unit: true do
|
8
|
-
let(:shell_id) { 'shell-123' }
|
9
|
-
let(:command_id) { 123 }
|
10
|
-
let(:test_data_xml_template) do
|
11
|
-
ERB.new(File.read('spec/stubs/responses/get_command_output_response.xml.erb'))
|
12
|
-
end
|
13
|
-
let(:service) do
|
14
|
-
WinRM::WinRMWebService.new(
|
15
|
-
'http://dummy/wsman',
|
16
|
-
:plaintext,
|
17
|
-
user: 'dummy',
|
18
|
-
pass: 'dummy')
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'response doc stdout with invalid UTF-8 characters' do
|
22
|
-
let(:test_data_stdout) { 'ffff' } # Base64-decodes to '}\xF7\xDF', an invalid sequence
|
23
|
-
let(:test_data_stderr) { '' }
|
24
|
-
let(:test_data_xml) { test_data_xml_template.result(binding) }
|
25
|
-
|
26
|
-
before do
|
27
|
-
allow(service).to receive(:send_get_output_message).and_return(
|
28
|
-
REXML::Document.new(test_data_xml)
|
29
|
-
)
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'does not raise an ArgumentError: invalid byte sequence in UTF-8' do
|
33
|
-
begin
|
34
|
-
expect(
|
35
|
-
service.get_command_output(shell_id, command_id)
|
36
|
-
).not_to raise_error
|
37
|
-
rescue RSpec::Expectations::ExpectationNotMetError => e
|
38
|
-
expect(e.message).not_to include 'ArgumentError'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'does not have an empty stdout' do
|
43
|
-
expect(
|
44
|
-
service.get_command_output(shell_id, command_id)[:data][0][:stdout]
|
45
|
-
).not_to be_empty
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe 'response doc stdout with valid UTF-8' do
|
50
|
-
let(:test_data_raw) { '✓1234-äöü' }
|
51
|
-
let(:test_data_stdout) { Base64.encode64(test_data_raw) }
|
52
|
-
let(:test_data_stderr) { '' }
|
53
|
-
let(:test_data_xml) { test_data_xml_template.result(binding) }
|
54
|
-
|
55
|
-
before do
|
56
|
-
allow(service).to receive(:send_get_output_message).and_return(
|
57
|
-
REXML::Document.new(test_data_xml)
|
58
|
-
)
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'decodes to match input data' do
|
62
|
-
expect(
|
63
|
-
service.get_command_output(shell_id, command_id)[:data][0][:stdout]
|
64
|
-
).to eq(test_data_raw)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
data/spec/powershell_spec.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
describe 'winrm client powershell', integration: true do
|
3
|
-
before(:all) do
|
4
|
-
@winrm = winrm_connection
|
5
|
-
end
|
6
|
-
|
7
|
-
describe 'ipconfig' do
|
8
|
-
subject(:output) { @winrm.powershell('ipconfig') }
|
9
|
-
it { should have_exit_code 0 }
|
10
|
-
it { should have_stdout_match(/Windows IP Configuration/) }
|
11
|
-
it { should have_no_stderr }
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'echo \'hello world\' using apostrophes' do
|
15
|
-
subject(:output) { @winrm.powershell("echo 'hello world'") }
|
16
|
-
it { should have_exit_code 0 }
|
17
|
-
it { should have_stdout_match(/hello world/) }
|
18
|
-
it { should have_no_stderr }
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'dir with incorrect argument /z' do
|
22
|
-
subject(:output) { @winrm.powershell('dir /z') }
|
23
|
-
it { should have_exit_code 1 }
|
24
|
-
it { should have_no_stdout }
|
25
|
-
end
|
26
|
-
|
27
|
-
describe 'Math area calculation' do
|
28
|
-
subject(:output) do
|
29
|
-
@winrm.powershell(<<-EOH
|
30
|
-
$diameter = 4.5
|
31
|
-
$area = [Math]::pow([Math]::PI * ($diameter/2), 2)
|
32
|
-
Write-Host $area
|
33
|
-
EOH
|
34
|
-
)
|
35
|
-
end
|
36
|
-
it { should have_exit_code 0 }
|
37
|
-
it { should have_stdout_match(/49.9648722805149/) }
|
38
|
-
it { should have_no_stderr }
|
39
|
-
end
|
40
|
-
|
41
|
-
describe 'ipconfig with a block' do
|
42
|
-
subject(:stdout) do
|
43
|
-
outvar = ''
|
44
|
-
@winrm.powershell('ipconfig') do |stdout, _stderr|
|
45
|
-
outvar << stdout
|
46
|
-
end
|
47
|
-
outvar
|
48
|
-
end
|
49
|
-
it { should match(/Windows IP Configuration/) }
|
50
|
-
end
|
51
|
-
|
52
|
-
describe 'capturing output from Write-Host and Write-Error' do
|
53
|
-
subject(:output) do
|
54
|
-
script = <<-eos
|
55
|
-
Write-Host 'Hello'
|
56
|
-
$host.ui.WriteErrorLine(', world!')
|
57
|
-
eos
|
58
|
-
|
59
|
-
@captured_stdout = ''
|
60
|
-
@captured_stderr = ''
|
61
|
-
@winrm.powershell(script) do |stdout, stderr|
|
62
|
-
@captured_stdout << stdout if stdout
|
63
|
-
@captured_stderr << stderr if stderr
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'should have stdout' do
|
68
|
-
expect(output.stdout).to eq("Hello\n")
|
69
|
-
expect(output.stdout).to eq(@captured_stdout)
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'should have stderr' do
|
73
|
-
# TODO: Option to parse CLIXML
|
74
|
-
# expect(output.output).to eq("Hello\n, world!")
|
75
|
-
# expect(output.stderr).to eq(", world!")
|
76
|
-
expect(output.stderr).to eq(
|
77
|
-
"#< CLIXML\r\n<Objs Version=\"1.1.0.1\" " \
|
78
|
-
"xmlns=\"http://schemas.microsoft.com/powershell/2004/04\">" \
|
79
|
-
"<S S=\"Error\">, world!_x000D__x000A_</S></Objs>")
|
80
|
-
expect(output.stderr).to eq(@captured_stderr)
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'should have output' do
|
84
|
-
# TODO: Option to parse CLIXML
|
85
|
-
# expect(output.output).to eq("Hello\n, world!")
|
86
|
-
expect(output.output).to eq("Hello\n#< CLIXML\r\n<Objs Version=\"1.1.0.1\" " \
|
87
|
-
"xmlns=\"http://schemas.microsoft.com/powershell/2004/04\">" \
|
88
|
-
"<S S=\"Error\">, world!_x000D__x000A_</S></Objs>")
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe 'it should handle utf-8 characters' do
|
93
|
-
subject(:output) { @winrm.powershell('echo "✓1234-äöü"') }
|
94
|
-
it { should have_exit_code 0 }
|
95
|
-
it { should have_stdout_match(/✓1234-äöü/) }
|
96
|
-
end
|
97
|
-
end
|
data/spec/winrm_options_spec.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
describe 'WinRM options', unit: true do
|
3
|
-
let(:subject) { WinRM::WinRMWebService.new('http://localhost:55985/wsman', :plaintext) }
|
4
|
-
|
5
|
-
context 'when operations timeout is set to 60' do
|
6
|
-
before(:each) { subject.set_timeout(60) }
|
7
|
-
describe '#receive_timeout' do
|
8
|
-
it 'is set to 70s' do
|
9
|
-
transportclass = subject.instance_variable_get(:@xfer)
|
10
|
-
expect(transportclass.receive_timeout).to eql(70)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
describe '#op_timeout' do
|
14
|
-
it 'is set to 60s' do
|
15
|
-
expect(subject.timeout).to eql('PT60S')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'when operations timeout is set to 30 and receive timeout is set to 120' do
|
21
|
-
before(:each) { subject.set_timeout(30, 120) }
|
22
|
-
describe '#receive_timeout' do
|
23
|
-
it 'is set to 120s' do
|
24
|
-
transportclass = subject.instance_variable_get(:@xfer)
|
25
|
-
expect(transportclass.receive_timeout).to eql(120)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
describe '#op_timeout' do
|
29
|
-
it 'is set to 30s' do
|
30
|
-
expect(subject.timeout).to eql('PT30S')
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'when max_env_size is set to 614400' do
|
36
|
-
before(:each) { subject.max_env_size(614_400) }
|
37
|
-
describe '@max_env_sz' do
|
38
|
-
it 'is set to 614400' do
|
39
|
-
expect(subject.instance_variable_get('@max_env_sz')).to eq(614_400)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'when locale is set to en-CA' do
|
45
|
-
before(:each) { subject.locale('en-CA') }
|
46
|
-
describe '@locale' do
|
47
|
-
it 'is set to en-CA' do
|
48
|
-
expect(subject.instance_variable_get('@locale')).to eq('en-CA')
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'default' do
|
54
|
-
describe '#receive_timeout' do
|
55
|
-
it 'should be 70s' do
|
56
|
-
transportclass = subject.instance_variable_get(:@xfer)
|
57
|
-
expect(transportclass.receive_timeout).to eql(70)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
describe '#timeout' do
|
61
|
-
it 'should be 60s' do
|
62
|
-
expect(subject.timeout).to eql('PT60S')
|
63
|
-
end
|
64
|
-
end
|
65
|
-
describe '@locale' do
|
66
|
-
it 'should be en-US' do
|
67
|
-
expect(subject.instance_variable_get('@locale')).to eq('en-US')
|
68
|
-
end
|
69
|
-
end
|
70
|
-
describe '@max_env_sz' do
|
71
|
-
it 'should be 153600' do
|
72
|
-
expect(subject.instance_variable_get('@max_env_sz')).to eq(153_600)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
describe 'winrm client primitives' do
|
3
|
-
before(:all) do
|
4
|
-
@winrm = winrm_connection
|
5
|
-
end
|
6
|
-
|
7
|
-
describe 'open and close shell', integration: true do
|
8
|
-
it 'should #open_shell and #close_shell' do
|
9
|
-
sid = @winrm.open_shell
|
10
|
-
expect(sid).to be_a_uid
|
11
|
-
expect(@winrm.close_shell(sid)).to be true
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should #run_command and #cleanup_command' do
|
15
|
-
sid = @winrm.open_shell
|
16
|
-
|
17
|
-
cmd_id = @winrm.run_command(sid, 'ipconfig', %w(/all))
|
18
|
-
expect(sid).to be_a_uid
|
19
|
-
|
20
|
-
expect(@winrm.cleanup_command(sid, cmd_id)).to be true
|
21
|
-
@winrm.close_shell(sid)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should #get_command_output' do
|
25
|
-
sid = @winrm.open_shell
|
26
|
-
cmd_id = @winrm.run_command(sid, 'ipconfig', %w(/all))
|
27
|
-
|
28
|
-
output = @winrm.get_command_output(sid, cmd_id)
|
29
|
-
expect(output).to have_exit_code 0
|
30
|
-
expect(output).to have_stdout_match(/.+/)
|
31
|
-
expect(output).to have_no_stderr
|
32
|
-
|
33
|
-
@winrm.cleanup_command(sid, cmd_id)
|
34
|
-
@winrm.close_shell(sid)
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should #get_command_output with a block' do
|
38
|
-
sid = @winrm.open_shell
|
39
|
-
cmd_id = @winrm.run_command(sid, 'ipconfig', %w(/all))
|
40
|
-
|
41
|
-
outvar = ''
|
42
|
-
@winrm.get_command_output(sid, cmd_id) do |stdout, _stderr|
|
43
|
-
outvar << stdout
|
44
|
-
end
|
45
|
-
expect(outvar).to match(/Windows IP Configuration/)
|
46
|
-
|
47
|
-
@winrm.cleanup_command(sid, cmd_id)
|
48
|
-
@winrm.close_shell(sid)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|