winrm 1.7.1 → 1.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -10
  3. data/.rspec +3 -3
  4. data/.rubocop.yml +12 -12
  5. data/.travis.yml +12 -12
  6. data/Gemfile +9 -9
  7. data/LICENSE +202 -202
  8. data/README.md +194 -194
  9. data/Rakefile +36 -36
  10. data/Vagrantfile +9 -9
  11. data/appveyor.yml +42 -42
  12. data/bin/rwinrm +97 -97
  13. data/changelog.md +77 -74
  14. data/lib/winrm.rb +42 -42
  15. data/lib/winrm/command_executor.rb +224 -224
  16. data/lib/winrm/command_output_decoder.rb +53 -0
  17. data/lib/winrm/exceptions/exceptions.rb +57 -57
  18. data/lib/winrm/helpers/iso8601_duration.rb +58 -58
  19. data/lib/winrm/helpers/powershell_script.rb +42 -42
  20. data/lib/winrm/http/response_handler.rb +82 -82
  21. data/lib/winrm/http/transport.rb +421 -421
  22. data/lib/winrm/output.rb +43 -43
  23. data/lib/winrm/soap_provider.rb +39 -39
  24. data/lib/winrm/version.rb +7 -7
  25. data/lib/winrm/winrm_service.rb +547 -556
  26. data/preamble +17 -17
  27. data/spec/auth_timeout_spec.rb +16 -16
  28. data/spec/cmd_spec.rb +102 -102
  29. data/spec/command_executor_spec.rb +429 -429
  30. data/spec/command_output_decoder_spec.rb +37 -0
  31. data/spec/config-example.yml +19 -19
  32. data/spec/exception_spec.rb +50 -50
  33. data/spec/issue_184_spec.rb +67 -67
  34. data/spec/issue_59_spec.rb +23 -23
  35. data/spec/matchers.rb +74 -74
  36. data/spec/output_spec.rb +110 -110
  37. data/spec/powershell_spec.rb +97 -97
  38. data/spec/response_handler_spec.rb +59 -59
  39. data/spec/spec_helper.rb +73 -73
  40. data/spec/stubs/responses/get_command_output_response.xml.erb +13 -13
  41. data/spec/stubs/responses/open_shell_v1.xml +19 -19
  42. data/spec/stubs/responses/open_shell_v2.xml +20 -20
  43. data/spec/stubs/responses/soap_fault_v1.xml +36 -36
  44. data/spec/stubs/responses/soap_fault_v2.xml +42 -42
  45. data/spec/stubs/responses/wmi_error_v2.xml +41 -41
  46. data/spec/transport_spec.rb +124 -124
  47. data/spec/winrm_options_spec.rb +76 -76
  48. data/spec/winrm_primitives_spec.rb +51 -51
  49. data/spec/wql_spec.rb +14 -14
  50. data/winrm.gemspec +40 -40
  51. metadata +5 -3
data/Vagrantfile CHANGED
@@ -1,9 +1,9 @@
1
- # encoding: UTF-8
2
- # -*- mode: ruby -*-
3
- # vi: set ft=ruby :
4
-
5
- VAGRANTFILE_API_VERSION = '2'
6
-
7
- Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8
- config.vm.box = 'mwrock/Windows2012R2'
9
- end
1
+ # encoding: UTF-8
2
+ # -*- mode: ruby -*-
3
+ # vi: set ft=ruby :
4
+
5
+ VAGRANTFILE_API_VERSION = '2'
6
+
7
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8
+ config.vm.box = 'mwrock/Windows2012R2'
9
+ end
data/appveyor.yml CHANGED
@@ -1,42 +1,42 @@
1
- version: "master-{build}"
2
-
3
- os: Windows Server 2012 R2
4
- platform:
5
- - x64
6
-
7
- environment:
8
- winrm_user: test_user
9
- winrm_pass: Pass@word1
10
-
11
- matrix:
12
- - ruby_version: "21"
13
- winrm_endpoint: http://localhost:5985/wsman
14
-
15
- clone_folder: c:\projects\winrm
16
- clone_depth: 1
17
- branches:
18
- only:
19
- - master
20
-
21
- install:
22
- - ps: net user /add $env:winrm_user $env:winrm_pass
23
- - ps: net localgroup administrators $env:winrm_user /add
24
- - ps: $env:winrm_cert = (New-SelfSignedCertificate -DnsName localhost -CertStoreLocation cert:\localmachine\my).Thumbprint
25
- - ps: winrm create winrm/config/Listener?Address=*+Transport=HTTPS "@{Hostname=`"localhost`";CertificateThumbprint=`"$($env:winrm_cert)`"}"
26
- - ps: winrm set winrm/config/client/auth '@{Basic="true"}'
27
- - ps: winrm set winrm/config/service/auth '@{Basic="true"}'
28
- - ps: winrm set winrm/config/service/auth '@{CbtHardeningLevel="Strict"}'
29
- - ps: winrm set winrm/config/service '@{AllowUnencrypted="true"}'
30
- - ps: $env:PATH="C:\Ruby$env:ruby_version\bin;$env:PATH"
31
- - ps: Write-Host $env:PATH
32
- - ps: ruby --version
33
- - ps: gem --version
34
- - ps: gem install bundler --quiet --no-ri --no-rdoc
35
- - ps: bundler --version
36
-
37
- build_script:
38
- - bundle install || bundle install || bundle install
39
-
40
- test_script:
41
- - SET SPEC_OPTS=--format progress
42
- - bundle exec rake integration
1
+ version: "master-{build}"
2
+
3
+ os: Windows Server 2012 R2
4
+ platform:
5
+ - x64
6
+
7
+ environment:
8
+ winrm_user: test_user
9
+ winrm_pass: Pass@word1
10
+
11
+ matrix:
12
+ - ruby_version: "21"
13
+ winrm_endpoint: http://localhost:5985/wsman
14
+
15
+ clone_folder: c:\projects\winrm
16
+ clone_depth: 1
17
+ branches:
18
+ only:
19
+ - master
20
+
21
+ install:
22
+ - ps: net user /add $env:winrm_user $env:winrm_pass
23
+ - ps: net localgroup administrators $env:winrm_user /add
24
+ - ps: $env:winrm_cert = (New-SelfSignedCertificate -DnsName localhost -CertStoreLocation cert:\localmachine\my).Thumbprint
25
+ - ps: winrm create winrm/config/Listener?Address=*+Transport=HTTPS "@{Hostname=`"localhost`";CertificateThumbprint=`"$($env:winrm_cert)`"}"
26
+ - ps: winrm set winrm/config/client/auth '@{Basic="true"}'
27
+ - ps: winrm set winrm/config/service/auth '@{Basic="true"}'
28
+ - ps: winrm set winrm/config/service/auth '@{CbtHardeningLevel="Strict"}'
29
+ - ps: winrm set winrm/config/service '@{AllowUnencrypted="true"}'
30
+ - ps: $env:PATH="C:\Ruby$env:ruby_version\bin;$env:PATH"
31
+ - ps: Write-Host $env:PATH
32
+ - ps: ruby --version
33
+ - ps: gem --version
34
+ - ps: gem install bundler --quiet --no-ri --no-rdoc
35
+ - ps: bundler --version
36
+
37
+ build_script:
38
+ - bundle install || bundle install || bundle install
39
+
40
+ test_script:
41
+ - SET SPEC_OPTS=--format progress
42
+ - bundle exec rake integration
data/bin/rwinrm CHANGED
@@ -1,97 +1,97 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- # Copyright 2014 Shawn Neal <sneal@sneal.net>
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
-
18
- # rubocop:disable all
19
-
20
- $LOAD_PATH.push File.expand_path('../../lib', __FILE__)
21
-
22
- require 'readline'
23
- require 'io/console'
24
- require 'winrm'
25
-
26
- def help_msg
27
- puts 'Usage: rwinrm user@host'
28
- puts ''
29
- end
30
-
31
- def parse_options
32
- options = {}
33
- fail 'Missing required options' unless ARGV.length == 1
34
-
35
- m = /^(?<user>[a-z0-9\.\!\$ _-]+)@{1}(?<host>[a-z0-9\.\-]+)(?<port>:[0-9]+)?/i.match(ARGV[0])
36
- fail "#{ARGV[0]} is an invalid host" unless m
37
- options[:user] = m[:user]
38
- options[:endpoint] = "http://#{m[:host]}#{m[:port] || ':5985'}/wsman"
39
-
40
- # Get the password
41
- print 'Password: '
42
- options[:pass] = STDIN.noecho(&:gets).chomp
43
- puts
44
-
45
- # Set some defaults required by WinRM WS
46
- options[:auth_type] = :plaintext
47
- options[:basic_auth_only] = true
48
-
49
- options
50
- rescue StandardError => e
51
- puts e.message
52
- help_msg
53
- exit 1
54
- end
55
-
56
- def repl(options)
57
- client = WinRM::WinRMWebService.new(
58
- options[:endpoint],
59
- options[:auth_type].to_sym,
60
- options)
61
-
62
- client.set_timeout(3600)
63
- shell_id = client.open_shell
64
- command_id = client.run_command(shell_id, 'cmd', "/K prompt [#{ARGV[0]}]$P$G")
65
-
66
- read_thread = Thread.new do
67
- client.get_command_output(shell_id, command_id) do |stdout, stderr|
68
- STDOUT.write stdout
69
- STDERR.write stderr
70
- end
71
- end
72
- read_thread.abort_on_exception = true
73
-
74
- while (buf = Readline.readline('', true))
75
- if buf =~ /^exit/
76
- read_thread.exit
77
- client.cleanup_command(shell_id, command_id)
78
- client.close_shell(shell_id)
79
- exit 0
80
- else
81
- client.write_stdin(shell_id, command_id, "#{buf}\r\n")
82
- end
83
- end
84
- rescue Interrupt
85
- puts 'exiting'
86
- # ctrl-c
87
- rescue WinRM::WinRMAuthorizationError
88
- puts 'Authentication failed, bad user name or password'
89
- exit 1
90
- rescue StandardError => e
91
- puts e.message
92
- exit 1
93
- end
94
-
95
- repl(parse_options)
96
-
97
- # rubocop:enable all
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # Copyright 2014 Shawn Neal <sneal@sneal.net>
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
+
18
+ # rubocop:disable all
19
+
20
+ $LOAD_PATH.push File.expand_path('../../lib', __FILE__)
21
+
22
+ require 'readline'
23
+ require 'io/console'
24
+ require 'winrm'
25
+
26
+ def help_msg
27
+ puts 'Usage: rwinrm user@host'
28
+ puts ''
29
+ end
30
+
31
+ def parse_options
32
+ options = {}
33
+ fail 'Missing required options' unless ARGV.length == 1
34
+
35
+ m = /^(?<user>[a-z0-9\.\!\$ _-]+)@{1}(?<host>[a-z0-9\.\-]+)(?<port>:[0-9]+)?/i.match(ARGV[0])
36
+ fail "#{ARGV[0]} is an invalid host" unless m
37
+ options[:user] = m[:user]
38
+ options[:endpoint] = "http://#{m[:host]}#{m[:port] || ':5985'}/wsman"
39
+
40
+ # Get the password
41
+ print 'Password: '
42
+ options[:pass] = STDIN.noecho(&:gets).chomp
43
+ puts
44
+
45
+ # Set some defaults required by WinRM WS
46
+ options[:auth_type] = :plaintext
47
+ options[:basic_auth_only] = true
48
+
49
+ options
50
+ rescue StandardError => e
51
+ puts e.message
52
+ help_msg
53
+ exit 1
54
+ end
55
+
56
+ def repl(options)
57
+ client = WinRM::WinRMWebService.new(
58
+ options[:endpoint],
59
+ options[:auth_type].to_sym,
60
+ options)
61
+
62
+ client.set_timeout(3600)
63
+ shell_id = client.open_shell
64
+ command_id = client.run_command(shell_id, 'cmd', "/K prompt [#{ARGV[0]}]$P$G")
65
+
66
+ read_thread = Thread.new do
67
+ client.get_command_output(shell_id, command_id) do |stdout, stderr|
68
+ STDOUT.write stdout
69
+ STDERR.write stderr
70
+ end
71
+ end
72
+ read_thread.abort_on_exception = true
73
+
74
+ while (buf = Readline.readline('', true))
75
+ if buf =~ /^exit/
76
+ read_thread.exit
77
+ client.cleanup_command(shell_id, command_id)
78
+ client.close_shell(shell_id)
79
+ exit 0
80
+ else
81
+ client.write_stdin(shell_id, command_id, "#{buf}\r\n")
82
+ end
83
+ end
84
+ rescue Interrupt
85
+ puts 'exiting'
86
+ # ctrl-c
87
+ rescue WinRM::WinRMAuthorizationError
88
+ puts 'Authentication failed, bad user name or password'
89
+ exit 1
90
+ rescue StandardError => e
91
+ puts e.message
92
+ exit 1
93
+ end
94
+
95
+ repl(parse_options)
96
+
97
+ # rubocop:enable all
data/changelog.md CHANGED
@@ -1,74 +1,77 @@
1
- # WinRM Gem Changelog
2
-
3
- # 1.7.1
4
- - Fix OS version comparisons for Windows 10 using `Gem::Version` instead of strings
5
-
6
- # 1.7.0
7
- - Bump rubyntlm gem to 0.6.0 to get channel binding support for HTTPS fixing connections to endoints with `CbtHardeningLevel` set to `Strict`
8
- - Fix for parsing binary data in command output
9
-
10
- # 1.6.1
11
- - Use codepage 437 by default on os versions older than Windows 7 and Windows Server 2008 R2
12
-
13
- # 1.6.0
14
- - Adding `:negotiate` transport providing NTLM/Negotiate encryption of WinRM requests and responses
15
- - Removed dependency on UUIDTools gem
16
- - Extending accepted error codes for retry behavior to include `Errno::ETIMEDOUT`
17
- - Correct deprecation warning for WinRMWebService.run_powershell_script
18
-
19
- # 1.5.0
20
- - Deprecating `WinRM::WinRMWebService` methods `cmd`, `run_cmd`, `powershell`, and `run_powershell_script` in favor of the `run_cmd` and `run_powershell_script` methods of the `WinRM::CommandExecutor` class. The `CommandExecutor` allows multiple commands to be run from the same WinRM shell providing a significant performance improvement when issuing multiple calls.
21
- - Added an `:ssl_peer_fingerprint` option to be used instead of `:no_ssl_peer_verification` and allows a specific certificate to be verified.
22
- - Opening a winrm shell is retriable with configurable delay and retry limit.
23
- - Logging apends to `stdout` by default and can be replaced with a logger from a consuming application.
24
-
25
- # 1.4.0
26
- - Added WinRM::Version so the gem version is available at runtime for consumers.
27
-
28
- # 1.3.6
29
- - Remove BOM from response (Issue #159) added by Windows 2008R2
30
-
31
- # 1.3.5
32
- - Widen logging version constraints to include 2.0
33
- - Use codepage 65001 (UTF-8)
34
-
35
- # 1.3.4
36
- - Relaxed version pins on dev dependencies
37
-
38
- # 1.3.3
39
- - Fixed issue 133, rwinrm allow hostnames with dashes
40
- - Use duck typing for powershell script read
41
-
42
- # 1.3.2
43
- - Add spec.license attribute to gemspec
44
- - Bump RSpec dependency 3.0 to 3.2
45
-
46
- # 1.3.1
47
- - Fixed issue 129, long running commands could cause a stackoverflow exception
48
- - Fixed use of sub! in run_command results in spurious capture/replacement of \& sequences
49
- - Fixed issue 124 rwinrm won't take '.' characters in username
50
-
51
- # 1.3.0
52
- - Fixed multiple issues with WinRMHTTPTransportError incorrectly being raised
53
- - Refactored and added more unit and integration tests
54
- - Added ability to write to stdin
55
- - Added rwinrm binary to launch remote shell
56
- - Added WINRM_LOG env var to set log level
57
- - Retry Kerberos auth once if 401 response is received
58
- - Remove Savon dependency and use newer versions of underlying dependencies
59
- - Remove Nokogiri dependency and replace with native Ruby XML
60
- - Fixed issue 85, ensure WQL response is not nil
61
- - All WinRM library errors inherit from base class WinRMError
62
- - Integrations tests should now pass on Windows Server 2008+
63
- - Bump Ruby NTLM gem version dependency
64
- - HTTP client receive timeout is now configurable via set_timeout
65
- - Added backwards compatible Output class to make it easier to collect output
66
- - Bumped gssapi dependency from 1.0 to 1.2 and fixed issue 54
67
- - Added Rubocop to build
68
- - Fixed error when commands contain a newline character
69
-
70
- # 1.2.0
71
- - Allow user to disable SSL peer ceritifcate validation #44
72
- - Allow commands with "'" chars on Ruby 2.x, fixes #69
73
- - Fixed uninitialized constant Module::Kconv in Ruby 2.x, fixes #65
74
- - Commands with non-ASCII chars should work, #70
1
+ # WinRM Gem Changelog
2
+
3
+ # 1.7.2
4
+ - Fix regression where BOM appears in 2008R2 output and is not stripped
5
+
6
+ # 1.7.1
7
+ - Fix OS version comparisons for Windows 10 using `Gem::Version` instead of strings
8
+
9
+ # 1.7.0
10
+ - Bump rubyntlm gem to 0.6.0 to get channel binding support for HTTPS fixing connections to endoints with `CbtHardeningLevel` set to `Strict`
11
+ - Fix for parsing binary data in command output
12
+
13
+ # 1.6.1
14
+ - Use codepage 437 by default on os versions older than Windows 7 and Windows Server 2008 R2
15
+
16
+ # 1.6.0
17
+ - Adding `:negotiate` transport providing NTLM/Negotiate encryption of WinRM requests and responses
18
+ - Removed dependency on UUIDTools gem
19
+ - Extending accepted error codes for retry behavior to include `Errno::ETIMEDOUT`
20
+ - Correct deprecation warning for WinRMWebService.run_powershell_script
21
+
22
+ # 1.5.0
23
+ - Deprecating `WinRM::WinRMWebService` methods `cmd`, `run_cmd`, `powershell`, and `run_powershell_script` in favor of the `run_cmd` and `run_powershell_script` methods of the `WinRM::CommandExecutor` class. The `CommandExecutor` allows multiple commands to be run from the same WinRM shell providing a significant performance improvement when issuing multiple calls.
24
+ - Added an `:ssl_peer_fingerprint` option to be used instead of `:no_ssl_peer_verification` and allows a specific certificate to be verified.
25
+ - Opening a winrm shell is retriable with configurable delay and retry limit.
26
+ - Logging apends to `stdout` by default and can be replaced with a logger from a consuming application.
27
+
28
+ # 1.4.0
29
+ - Added WinRM::Version so the gem version is available at runtime for consumers.
30
+
31
+ # 1.3.6
32
+ - Remove BOM from response (Issue #159) added by Windows 2008R2
33
+
34
+ # 1.3.5
35
+ - Widen logging version constraints to include 2.0
36
+ - Use codepage 65001 (UTF-8)
37
+
38
+ # 1.3.4
39
+ - Relaxed version pins on dev dependencies
40
+
41
+ # 1.3.3
42
+ - Fixed issue 133, rwinrm allow hostnames with dashes
43
+ - Use duck typing for powershell script read
44
+
45
+ # 1.3.2
46
+ - Add spec.license attribute to gemspec
47
+ - Bump RSpec dependency 3.0 to 3.2
48
+
49
+ # 1.3.1
50
+ - Fixed issue 129, long running commands could cause a stackoverflow exception
51
+ - Fixed use of sub! in run_command results in spurious capture/replacement of \& sequences
52
+ - Fixed issue 124 rwinrm won't take '.' characters in username
53
+
54
+ # 1.3.0
55
+ - Fixed multiple issues with WinRMHTTPTransportError incorrectly being raised
56
+ - Refactored and added more unit and integration tests
57
+ - Added ability to write to stdin
58
+ - Added rwinrm binary to launch remote shell
59
+ - Added WINRM_LOG env var to set log level
60
+ - Retry Kerberos auth once if 401 response is received
61
+ - Remove Savon dependency and use newer versions of underlying dependencies
62
+ - Remove Nokogiri dependency and replace with native Ruby XML
63
+ - Fixed issue 85, ensure WQL response is not nil
64
+ - All WinRM library errors inherit from base class WinRMError
65
+ - Integrations tests should now pass on Windows Server 2008+
66
+ - Bump Ruby NTLM gem version dependency
67
+ - HTTP client receive timeout is now configurable via set_timeout
68
+ - Added backwards compatible Output class to make it easier to collect output
69
+ - Bumped gssapi dependency from 1.0 to 1.2 and fixed issue 54
70
+ - Added Rubocop to build
71
+ - Fixed error when commands contain a newline character
72
+
73
+ # 1.2.0
74
+ - Allow user to disable SSL peer ceritifcate validation #44
75
+ - Allow commands with "'" chars on Ruby 2.x, fixes #69
76
+ - Fixed uninitialized constant Module::Kconv in Ruby 2.x, fixes #65
77
+ - Commands with non-ASCII chars should work, #70