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,18 +1,18 @@
|
|
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
|
+
# 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,110 +1,131 @@
|
|
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 '
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
it
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
it
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
it
|
96
|
-
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
describe 'ipconfig with
|
101
|
-
subject(:
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
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 'codepage' do
|
24
|
+
let(:options) { Hash.new }
|
25
|
+
let(:shell) { winrm_connection.shell(:cmd, options) }
|
26
|
+
|
27
|
+
after { shell.close }
|
28
|
+
|
29
|
+
subject(:output) { shell.run('chcp') }
|
30
|
+
|
31
|
+
it 'should default to UTF-8 (65001)' do
|
32
|
+
should have_stdout_match(/Active code page: 65001/)
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when changing the codepage' do
|
36
|
+
let(:options) { { codepage: 437 } }
|
37
|
+
|
38
|
+
it 'sets the codepage to the one given' do
|
39
|
+
should have_stdout_match(/Active code page: 437/)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'echo \'hello world\' using apostrophes' do
|
45
|
+
subject(:output) { @cmd_shell.run("echo 'hello world'") }
|
46
|
+
it { should have_exit_code 0 }
|
47
|
+
it { should have_stdout_match(/'hello world'/) }
|
48
|
+
it { should have_no_stderr }
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'multi stream output from large file' do
|
52
|
+
subject(:output) { @cmd_shell.run('type c:\windows\logs\dism\dism.log') }
|
53
|
+
it { should have_exit_code 0 }
|
54
|
+
it { should have_no_stderr }
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'echo "string with trailing \\" using double quotes' do
|
58
|
+
# This is a regression test for #131. " is converted to " when serializing
|
59
|
+
# the command to SOAP/XML. Any naive substitution performed on such a serialized
|
60
|
+
# string can result in any \& sequence being interpreted as a back-substitution.
|
61
|
+
subject(:output) { @cmd_shell.run('echo "string with trailing \\"') }
|
62
|
+
it { should have_exit_code 0 }
|
63
|
+
it { should have_stdout_match(/string with trailing \\/) }
|
64
|
+
it { should have_no_stderr }
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'capturing output from stdout and stderr' do
|
68
|
+
subject(:output) do
|
69
|
+
# Note: Multiple lines doesn't work:
|
70
|
+
# script = <<-eos
|
71
|
+
# echo Hello
|
72
|
+
# echo , world! 1>&2
|
73
|
+
# eos
|
74
|
+
|
75
|
+
script = 'echo Hello & echo , world! 1>&2'
|
76
|
+
|
77
|
+
@captured_stdout = ''
|
78
|
+
@captured_stderr = ''
|
79
|
+
@cmd_shell.run(script) do |stdout, stderr|
|
80
|
+
@captured_stdout << stdout if stdout
|
81
|
+
@captured_stderr << stderr if stderr
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should have stdout' do
|
86
|
+
expect(output.stdout).to eq("Hello \r\n")
|
87
|
+
expect(output.stdout).to eq(@captured_stdout)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should have stderr' do
|
91
|
+
expect(output.stderr).to eq(", world! \r\n")
|
92
|
+
expect(output.stderr).to eq(@captured_stderr)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should have output' do
|
96
|
+
expect(output.output).to eq("Hello \r\n, world! \r\n")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe 'ipconfig with /all argument' do
|
101
|
+
subject(:output) { @cmd_shell.run('ipconfig', %w(/all)) }
|
102
|
+
it { should have_exit_code 0 }
|
103
|
+
it { should have_stdout_match(/Windows IP Configuration/) }
|
104
|
+
it { should have_no_stderr }
|
105
|
+
end
|
106
|
+
|
107
|
+
describe 'dir with incorrect argument /z' do
|
108
|
+
subject(:output) { @cmd_shell.run('dir /z') }
|
109
|
+
it { should have_exit_code 1 }
|
110
|
+
it { should have_no_stdout }
|
111
|
+
it { should have_stderr_match(/Invalid switch/) }
|
112
|
+
end
|
113
|
+
|
114
|
+
describe 'ipconfig && echo error 1>&2' do
|
115
|
+
subject(:output) { @cmd_shell.run('ipconfig && echo error 1>&2') }
|
116
|
+
it { should have_exit_code 0 }
|
117
|
+
it { should have_stdout_match(/Windows IP Configuration/) }
|
118
|
+
it { should have_stderr_match(/error/) }
|
119
|
+
end
|
120
|
+
|
121
|
+
describe 'ipconfig with a block' do
|
122
|
+
subject(:stdout) do
|
123
|
+
outvar = ''
|
124
|
+
@cmd_shell.run('ipconfig') do |stdout, _stderr|
|
125
|
+
outvar << stdout
|
126
|
+
end
|
127
|
+
outvar
|
128
|
+
end
|
129
|
+
it { should match(/Windows IP Configuration/) }
|
130
|
+
end
|
131
|
+
end
|
@@ -1,16 +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
|
-
# 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
|
+
# 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,26 +1,26 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require_relative 'spec_helper'
|
3
|
-
|
4
|
-
describe 'issue 59' do
|
5
|
-
describe 'long running script without output' do
|
6
|
-
let(:logged_output) { StringIO.new }
|
7
|
-
let(:logger) { Logging.logger(logged_output) }
|
8
|
-
|
9
|
-
before do
|
10
|
-
opts = connection_opts.dup
|
11
|
-
opts[:operation_timeout] = 1
|
12
|
-
conn = WinRM::Connection.new(opts)
|
13
|
-
conn.logger = logger
|
14
|
-
@powershell = conn.shell(:powershell)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should not error' do
|
18
|
-
out = @powershell.run('$ProgressPreference="SilentlyContinue";sleep 3; Write-Host "Hello"')
|
19
|
-
|
20
|
-
expect(out).to have_exit_code 0
|
21
|
-
expect(out).to have_stdout_match(/Hello/)
|
22
|
-
expect(out).to have_no_stderr
|
23
|
-
expect(logged_output.string).to match(/retrying receive request/)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
|
4
|
+
describe 'issue 59' do
|
5
|
+
describe 'long running script without output' do
|
6
|
+
let(:logged_output) { StringIO.new }
|
7
|
+
let(:logger) { Logging.logger(logged_output) }
|
8
|
+
|
9
|
+
before do
|
10
|
+
opts = connection_opts.dup
|
11
|
+
opts[:operation_timeout] = 1
|
12
|
+
conn = WinRM::Connection.new(opts)
|
13
|
+
conn.logger = logger
|
14
|
+
@powershell = conn.shell(:powershell)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should not error' do
|
18
|
+
out = @powershell.run('$ProgressPreference="SilentlyContinue";sleep 3; Write-Host "Hello"')
|
19
|
+
|
20
|
+
expect(out).to have_exit_code 0
|
21
|
+
expect(out).to have_stdout_match(/Hello/)
|
22
|
+
expect(out).to have_no_stderr
|
23
|
+
expect(logged_output.string).to match(/retrying receive request/)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,165 +1,165 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require_relative 'spec_helper'
|
3
|
-
|
4
|
-
describe 'winrm client powershell' do
|
5
|
-
before(:all) do
|
6
|
-
@powershell = winrm_connection.shell(:powershell)
|
7
|
-
end
|
8
|
-
|
9
|
-
describe 'ipconfig' do
|
10
|
-
subject(:output) { @powershell.run('ipconfig') }
|
11
|
-
it { should have_exit_code 0 }
|
12
|
-
it { should have_stdout_match(/Windows IP Configuration/) }
|
13
|
-
it { should have_no_stderr }
|
14
|
-
end
|
15
|
-
|
16
|
-
describe 'ipconfig with invalid args' do
|
17
|
-
subject(:output) { @powershell.run('ipconfig blah') }
|
18
|
-
it { should have_exit_code 1 }
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'throw' do
|
22
|
-
subject(:output) { @powershell.run("throw 'an error occured'") }
|
23
|
-
it { should have_exit_code 0 }
|
24
|
-
it { should have_stderr_match(/an error occured/) }
|
25
|
-
end
|
26
|
-
|
27
|
-
describe 'exit' do
|
28
|
-
subject(:output) { @powershell.run('exit 5') }
|
29
|
-
it { should have_exit_code 5 }
|
30
|
-
end
|
31
|
-
|
32
|
-
describe 'echo \'hello world\' using apostrophes' do
|
33
|
-
subject(:output) { @powershell.run("echo 'hello world'") }
|
34
|
-
it { should have_exit_code 0 }
|
35
|
-
it { should have_stdout_match(/hello world/) }
|
36
|
-
it { should have_no_stderr }
|
37
|
-
end
|
38
|
-
|
39
|
-
describe 'handling special XML characters' do
|
40
|
-
subject(:output) { @powershell.run("echo 'hello & <world>'") }
|
41
|
-
it { should have_exit_code 0 }
|
42
|
-
it { should have_stdout_match(/hello & <world>/) }
|
43
|
-
it { should have_no_stderr }
|
44
|
-
end
|
45
|
-
|
46
|
-
describe 'dir with incorrect argument /z' do
|
47
|
-
subject(:output) { @powershell.run('dir /z') }
|
48
|
-
it { should have_stderr_match(/Cannot find path/) }
|
49
|
-
it { should have_no_stdout }
|
50
|
-
end
|
51
|
-
|
52
|
-
describe 'Math area calculation' do
|
53
|
-
subject(:output) do
|
54
|
-
@powershell.run <<-EOH
|
55
|
-
$diameter = 4.5
|
56
|
-
$area = [Math]::pow([Math]::PI * ($diameter/2), 2)
|
57
|
-
Write-Host $area
|
58
|
-
EOH
|
59
|
-
end
|
60
|
-
it { should have_exit_code 0 }
|
61
|
-
it { should have_stdout_match(/49.9648722805149/) }
|
62
|
-
it { should have_no_stderr }
|
63
|
-
end
|
64
|
-
|
65
|
-
describe 'ipconfig with a block' do
|
66
|
-
subject(:stdout) do
|
67
|
-
outvar = ''
|
68
|
-
@powershell.run('ipconfig') do |stdout, _stderr|
|
69
|
-
outvar << stdout
|
70
|
-
end
|
71
|
-
outvar
|
72
|
-
end
|
73
|
-
it { should match(/Windows IP Configuration/) }
|
74
|
-
end
|
75
|
-
|
76
|
-
describe 'capturing output from Write-Host and Write-Error' do
|
77
|
-
subject(:output) do
|
78
|
-
script = <<-eos
|
79
|
-
Write-Host 'Hello'
|
80
|
-
$host.ui.WriteErrorLine(', world!')
|
81
|
-
eos
|
82
|
-
|
83
|
-
@captured_stdout = ''
|
84
|
-
@captured_stderr = ''
|
85
|
-
@powershell.run(script) do |stdout, stderr|
|
86
|
-
@captured_stdout << stdout if stdout
|
87
|
-
@captured_stderr << stderr if stderr
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'should have stdout' do
|
92
|
-
expect(output.stdout).to eq("Hello\r\n")
|
93
|
-
expect(output.stdout).to eq(@captured_stdout)
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'should have stderr' do
|
97
|
-
expect(output.stderr).to eq(", world!\r\n")
|
98
|
-
expect(output.stderr).to eq(@captured_stderr)
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'should have output' do
|
102
|
-
expect(output.output).to eq("Hello\r\n, world!\r\n")
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe 'capturing output from pipeline followed by Host' do
|
107
|
-
subject(:output) do
|
108
|
-
script = <<-eos
|
109
|
-
Write-Output 'output'
|
110
|
-
$host.UI.Writeline('host')
|
111
|
-
eos
|
112
|
-
|
113
|
-
@captured_stdout = ''
|
114
|
-
@captured_stderr = ''
|
115
|
-
@powershell.run(script) do |stdout, stderr|
|
116
|
-
@captured_stdout << stdout if stdout
|
117
|
-
@captured_stderr << stderr if stderr
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'should print from the pipeline first' do
|
122
|
-
expect(output.stdout).to start_with("output\r\n")
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'should write to host last' do
|
126
|
-
expect(output.stdout).to end_with("host\r\n")
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
describe 'it should handle utf-8 characters' do
|
131
|
-
subject(:output) { @powershell.run('echo "✓1234-äöü"') }
|
132
|
-
it { should have_exit_code 0 }
|
133
|
-
it { should have_stdout_match(/✓1234-äöü/) }
|
134
|
-
end
|
135
|
-
|
136
|
-
describe 'output exceeds a single fragment' do
|
137
|
-
subject(:output) { @powershell.run('Write-Output $("a"*600000)') }
|
138
|
-
it { should have_exit_code 0 }
|
139
|
-
it 'has assebled the output' do
|
140
|
-
expect(output.stdout).to eq('a' * 600000 + "\r\n")
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
describe 'command exceeds a single fragment' do
|
145
|
-
subject(:output) { @powershell.run("$var='#{'a' * 600000}';Write-Output 'long var'") }
|
146
|
-
it { should have_exit_code 0 }
|
147
|
-
it 'has sent the output' do
|
148
|
-
expect(output.stdout).to eq("long var\r\n")
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe 'reading pipeline messages' do
|
153
|
-
subject(:messages) { @powershell.send_pipeline_command('ipconfig') }
|
154
|
-
|
155
|
-
it 'returns multiple messages' do
|
156
|
-
expect(messages.length).to be > 1
|
157
|
-
end
|
158
|
-
it 'first message is pipeline output' do
|
159
|
-
expect(messages.first.type).to eq(WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output])
|
160
|
-
end
|
161
|
-
it 'last message is pipeline state' do
|
162
|
-
expect(messages.last.type).to eq(WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_state])
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
|
4
|
+
describe 'winrm client powershell' do
|
5
|
+
before(:all) do
|
6
|
+
@powershell = winrm_connection.shell(:powershell)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'ipconfig' do
|
10
|
+
subject(:output) { @powershell.run('ipconfig') }
|
11
|
+
it { should have_exit_code 0 }
|
12
|
+
it { should have_stdout_match(/Windows IP Configuration/) }
|
13
|
+
it { should have_no_stderr }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'ipconfig with invalid args' do
|
17
|
+
subject(:output) { @powershell.run('ipconfig blah') }
|
18
|
+
it { should have_exit_code 1 }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'throw' do
|
22
|
+
subject(:output) { @powershell.run("throw 'an error occured'") }
|
23
|
+
it { should have_exit_code 0 }
|
24
|
+
it { should have_stderr_match(/an error occured/) }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'exit' do
|
28
|
+
subject(:output) { @powershell.run('exit 5') }
|
29
|
+
it { should have_exit_code 5 }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'echo \'hello world\' using apostrophes' do
|
33
|
+
subject(:output) { @powershell.run("echo 'hello world'") }
|
34
|
+
it { should have_exit_code 0 }
|
35
|
+
it { should have_stdout_match(/hello world/) }
|
36
|
+
it { should have_no_stderr }
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'handling special XML characters' do
|
40
|
+
subject(:output) { @powershell.run("echo 'hello & <world>'") }
|
41
|
+
it { should have_exit_code 0 }
|
42
|
+
it { should have_stdout_match(/hello & <world>/) }
|
43
|
+
it { should have_no_stderr }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'dir with incorrect argument /z' do
|
47
|
+
subject(:output) { @powershell.run('dir /z') }
|
48
|
+
it { should have_stderr_match(/Cannot find path/) }
|
49
|
+
it { should have_no_stdout }
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'Math area calculation' do
|
53
|
+
subject(:output) do
|
54
|
+
@powershell.run <<-EOH
|
55
|
+
$diameter = 4.5
|
56
|
+
$area = [Math]::pow([Math]::PI * ($diameter/2), 2)
|
57
|
+
Write-Host $area
|
58
|
+
EOH
|
59
|
+
end
|
60
|
+
it { should have_exit_code 0 }
|
61
|
+
it { should have_stdout_match(/49.9648722805149/) }
|
62
|
+
it { should have_no_stderr }
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'ipconfig with a block' do
|
66
|
+
subject(:stdout) do
|
67
|
+
outvar = ''
|
68
|
+
@powershell.run('ipconfig') do |stdout, _stderr|
|
69
|
+
outvar << stdout
|
70
|
+
end
|
71
|
+
outvar
|
72
|
+
end
|
73
|
+
it { should match(/Windows IP Configuration/) }
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'capturing output from Write-Host and Write-Error' do
|
77
|
+
subject(:output) do
|
78
|
+
script = <<-eos
|
79
|
+
Write-Host 'Hello'
|
80
|
+
$host.ui.WriteErrorLine(', world!')
|
81
|
+
eos
|
82
|
+
|
83
|
+
@captured_stdout = ''
|
84
|
+
@captured_stderr = ''
|
85
|
+
@powershell.run(script) do |stdout, stderr|
|
86
|
+
@captured_stdout << stdout if stdout
|
87
|
+
@captured_stderr << stderr if stderr
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should have stdout' do
|
92
|
+
expect(output.stdout).to eq("Hello\r\n")
|
93
|
+
expect(output.stdout).to eq(@captured_stdout)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should have stderr' do
|
97
|
+
expect(output.stderr).to eq(", world!\r\n")
|
98
|
+
expect(output.stderr).to eq(@captured_stderr)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should have output' do
|
102
|
+
expect(output.output).to eq("Hello\r\n, world!\r\n")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe 'capturing output from pipeline followed by Host' do
|
107
|
+
subject(:output) do
|
108
|
+
script = <<-eos
|
109
|
+
Write-Output 'output'
|
110
|
+
$host.UI.Writeline('host')
|
111
|
+
eos
|
112
|
+
|
113
|
+
@captured_stdout = ''
|
114
|
+
@captured_stderr = ''
|
115
|
+
@powershell.run(script) do |stdout, stderr|
|
116
|
+
@captured_stdout << stdout if stdout
|
117
|
+
@captured_stderr << stderr if stderr
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should print from the pipeline first' do
|
122
|
+
expect(output.stdout).to start_with("output\r\n")
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should write to host last' do
|
126
|
+
expect(output.stdout).to end_with("host\r\n")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe 'it should handle utf-8 characters' do
|
131
|
+
subject(:output) { @powershell.run('echo "✓1234-äöü"') }
|
132
|
+
it { should have_exit_code 0 }
|
133
|
+
it { should have_stdout_match(/✓1234-äöü/) }
|
134
|
+
end
|
135
|
+
|
136
|
+
describe 'output exceeds a single fragment' do
|
137
|
+
subject(:output) { @powershell.run('Write-Output $("a"*600000)') }
|
138
|
+
it { should have_exit_code 0 }
|
139
|
+
it 'has assebled the output' do
|
140
|
+
expect(output.stdout).to eq('a' * 600000 + "\r\n")
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe 'command exceeds a single fragment' do
|
145
|
+
subject(:output) { @powershell.run("$var='#{'a' * 600000}';Write-Output 'long var'") }
|
146
|
+
it { should have_exit_code 0 }
|
147
|
+
it 'has sent the output' do
|
148
|
+
expect(output.stdout).to eq("long var\r\n")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe 'reading pipeline messages' do
|
153
|
+
subject(:messages) { @powershell.send_pipeline_command('ipconfig') }
|
154
|
+
|
155
|
+
it 'returns multiple messages' do
|
156
|
+
expect(messages.length).to be > 1
|
157
|
+
end
|
158
|
+
it 'first message is pipeline output' do
|
159
|
+
expect(messages.first.type).to eq(WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_output])
|
160
|
+
end
|
161
|
+
it 'last message is pipeline state' do
|
162
|
+
expect(messages.last.type).to eq(WinRM::PSRP::Message::MESSAGE_TYPES[:pipeline_state])
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|