knife-winops 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.rspec +3 -0
- data/.travis.yml +30 -0
- data/CHANGELOG.md +147 -0
- data/DOC_CHANGES.md +22 -0
- data/Gemfile +13 -0
- data/LICENSE +201 -0
- data/README.md +430 -0
- data/RELEASE_NOTES.md +17 -0
- data/Rakefile +21 -0
- data/appveyor.yml +36 -0
- data/ci.gemfile +15 -0
- data/knife-winops.gemspec +26 -0
- data/lib/chef/knife/bootstrap/Chef_bootstrap.erb +44 -0
- data/lib/chef/knife/bootstrap/bootstrap.ps1 +134 -0
- data/lib/chef/knife/bootstrap/tail.cmd +15 -0
- data/lib/chef/knife/bootstrap/windows-chef-client-msi.erb +302 -0
- data/lib/chef/knife/bootstrap_windows_base.rb +473 -0
- data/lib/chef/knife/bootstrap_windows_ssh.rb +115 -0
- data/lib/chef/knife/bootstrap_windows_winrm.rb +102 -0
- data/lib/chef/knife/core/windows_bootstrap_context.rb +356 -0
- data/lib/chef/knife/knife_windows_base.rb +33 -0
- data/lib/chef/knife/windows_cert_generate.rb +155 -0
- data/lib/chef/knife/windows_cert_install.rb +68 -0
- data/lib/chef/knife/windows_helper.rb +36 -0
- data/lib/chef/knife/windows_listener_create.rb +107 -0
- data/lib/chef/knife/winrm.rb +127 -0
- data/lib/chef/knife/winrm_base.rb +128 -0
- data/lib/chef/knife/winrm_knife_base.rb +315 -0
- data/lib/chef/knife/winrm_session.rb +101 -0
- data/lib/chef/knife/winrm_shared_options.rb +54 -0
- data/lib/chef/knife/wsman_endpoint.rb +44 -0
- data/lib/chef/knife/wsman_test.rb +118 -0
- data/lib/knife-winops/path_helper.rb +242 -0
- data/lib/knife-winops/version.rb +6 -0
- data/spec/assets/fake_trusted_certs/excluded.txt +2 -0
- data/spec/assets/fake_trusted_certs/github.pem +42 -0
- data/spec/assets/fake_trusted_certs/google.crt +41 -0
- data/spec/assets/win_fake_trusted_cert_script.txt +89 -0
- data/spec/dummy_winrm_connection.rb +21 -0
- data/spec/functional/bootstrap_download_spec.rb +229 -0
- data/spec/spec_helper.rb +93 -0
- data/spec/unit/knife/bootstrap_options_spec.rb +164 -0
- data/spec/unit/knife/bootstrap_template_spec.rb +98 -0
- data/spec/unit/knife/bootstrap_windows_winrm_spec.rb +410 -0
- data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +292 -0
- data/spec/unit/knife/windows_cert_generate_spec.rb +90 -0
- data/spec/unit/knife/windows_cert_install_spec.rb +51 -0
- data/spec/unit/knife/windows_listener_create_spec.rb +76 -0
- data/spec/unit/knife/winrm_session_spec.rb +101 -0
- data/spec/unit/knife/winrm_spec.rb +494 -0
- data/spec/unit/knife/wsman_test_spec.rb +209 -0
- metadata +157 -0
@@ -0,0 +1,209 @@
|
|
1
|
+
#
|
2
|
+
# Original knife-windows author:: Steven Murawski (<smurawski@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2015-2016 Chef Software, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
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
|
+
|
19
|
+
require 'spec_helper'
|
20
|
+
|
21
|
+
describe Chef::Knife::WsmanTest do
|
22
|
+
let(:http_client_mock) { HTTPClient.new }
|
23
|
+
let(:ssl_policy) { double('DefaultSSLPolicy', :set_custom_certs => nil) }
|
24
|
+
|
25
|
+
before(:all) do
|
26
|
+
Chef::Config.reset
|
27
|
+
end
|
28
|
+
|
29
|
+
before(:each) do
|
30
|
+
response_body = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header/><s:Body><wsmid:IdentifyResponse xmlns:wsmid="http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd"><wsmid:ProtocolVersion>http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd</wsmid:ProtocolVersion><wsmid:ProductVendor>Microsoft Corporation</wsmid:ProductVendor><wsmid:ProductVersion>OS: 0.0.0 SP: 0.0 Stack: 2.0</wsmid:ProductVersion></wsmid:IdentifyResponse></s:Body></s:Envelope>'
|
31
|
+
http_response_mock = HTTP::Message.new_response(response_body)
|
32
|
+
allow(http_client_mock).to receive(:post).and_return(http_response_mock)
|
33
|
+
allow(HTTPClient).to receive(:new).and_return(http_client_mock)
|
34
|
+
subject.config[:verbosity] = 0
|
35
|
+
allow(subject.ui).to receive(:ask).and_return('prompted_password')
|
36
|
+
allow(Chef::HTTP::DefaultSSLPolicy).to receive(:new)
|
37
|
+
.with(http_client_mock.ssl_config)
|
38
|
+
.and_return(ssl_policy)
|
39
|
+
end
|
40
|
+
|
41
|
+
subject { Chef::Knife::WsmanTest.new(['-m', 'localhost']) }
|
42
|
+
|
43
|
+
it 'sets the ssl policy' do
|
44
|
+
expect(ssl_policy).to receive(:set_custom_certs).twice
|
45
|
+
subject.run
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when testing the WSMAN endpoint' do
|
49
|
+
context 'and the service responds' do
|
50
|
+
context 'successfully' do
|
51
|
+
it 'writes a message about a successful connection' do
|
52
|
+
expect(subject.ui).to receive(:msg)
|
53
|
+
subject.run
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'with an invalid body' do
|
58
|
+
it 'warns for a failed connection and exit with a status of 1' do
|
59
|
+
response_body = 'I am invalid'
|
60
|
+
http_response_mock = HTTP::Message.new_response(response_body)
|
61
|
+
allow(http_client_mock).to receive(:post).and_return(http_response_mock)
|
62
|
+
expect(subject.ui).to receive(:warn)
|
63
|
+
expect(subject.ui).to receive(:error)
|
64
|
+
expect(subject).to receive(:exit).with(1)
|
65
|
+
subject.run
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'with a non-200 code' do
|
70
|
+
it 'warns for a failed connection and exits with a status of 1' do
|
71
|
+
http_response_mock = HTTP::Message.new_response('<resp></resp>')
|
72
|
+
http_response_mock.status = 404
|
73
|
+
allow(http_client_mock).to receive(:post).and_return(http_response_mock)
|
74
|
+
expect(subject.ui).to receive(:warn)
|
75
|
+
expect(subject.ui).to receive(:error)
|
76
|
+
expect(subject).to receive(:exit).with(1)
|
77
|
+
subject.run
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'and the service does not respond' do
|
83
|
+
error_message = 'A connection attempt failed because the connected party did not properly respond after a period of time.'
|
84
|
+
|
85
|
+
before(:each) do
|
86
|
+
allow(http_client_mock).to receive(:post).and_raise(Exception.new(error_message))
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'exits with a status code of 1' do
|
90
|
+
expect(subject).to receive(:exit).with(1)
|
91
|
+
subject.run
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'writes a warning message for each node it fails to connect to' do
|
95
|
+
expect(subject.ui).to receive(:warn)
|
96
|
+
expect(subject).to receive(:exit).with(1)
|
97
|
+
subject.run
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'writes an error message if it fails to connect to any nodes' do
|
101
|
+
expect(subject.ui).to receive(:error)
|
102
|
+
expect(subject).to receive(:exit).with(1)
|
103
|
+
subject.run
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'when not validating ssl cert' do
|
109
|
+
before(:each) do
|
110
|
+
expect(subject.ui).to receive(:msg)
|
111
|
+
subject.config[:winrm_ssl_verify_mode] = :verify_none
|
112
|
+
subject.config[:winrm_transport] = :ssl
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'sets verify_mode to verify_none' do
|
116
|
+
subject.run
|
117
|
+
expect(http_client_mock.ssl_config.verify_mode).to eq(OpenSSL::SSL::VERIFY_NONE)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'when testing the WSMAN endpoint with verbose output' do
|
122
|
+
before(:each) do
|
123
|
+
subject.config[:verbosity] = 1
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'and the service does not respond' do
|
127
|
+
it 'returns an object with an error message' do
|
128
|
+
error_message = 'A connection attempt failed because the connected party did not properly respond after a period of time.'
|
129
|
+
allow(http_client_mock).to receive(:post).and_raise(Exception.new(error_message))
|
130
|
+
expect(subject).to receive(:exit).with(1)
|
131
|
+
expect(subject).to receive(:output) do |output|
|
132
|
+
expect(output.error_message).to match(/#{error_message}/)
|
133
|
+
end
|
134
|
+
subject.run
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'with an invalid body' do
|
139
|
+
it 'includes invalid body in error message' do
|
140
|
+
response_body = 'I am invalid'
|
141
|
+
http_response_mock = HTTP::Message.new_response(response_body)
|
142
|
+
allow(http_client_mock).to receive(:post).and_return(http_response_mock)
|
143
|
+
expect(subject).to receive(:exit).with(1)
|
144
|
+
expect(subject).to receive(:output) do |output|
|
145
|
+
expect(output.error_message).to match(/#{response_body}/)
|
146
|
+
end
|
147
|
+
subject.run
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context 'and the target node is Windows Server 2008 R2' do
|
152
|
+
before(:each) do
|
153
|
+
ws2008r2_response_body = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header/><s:Body><wsmid:IdentifyResponse xmlns:wsmid="http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd"><wsmid:ProtocolVersion>http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd</wsmid:ProtocolVersion><wsmid:ProductVendor>Microsoft Corporation</wsmid:ProductVendor><wsmid:ProductVersion>OS: 0.0.0 SP: 0.0 Stack: 2.0</wsmid:ProductVersion></wsmid:IdentifyResponse></s:Body></s:Envelope>'
|
154
|
+
http_response_mock = HTTP::Message.new_response(ws2008r2_response_body)
|
155
|
+
allow(http_client_mock).to receive(:post).and_return(http_response_mock)
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'identifies the stack of the product version as 2.0 ' do
|
159
|
+
expect(subject).to receive(:output) do |output|
|
160
|
+
expect(output.product_version).to eq 'OS: 0.0.0 SP: 0.0 Stack: 2.0'
|
161
|
+
end
|
162
|
+
subject.run
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'identifies the protocol version as the current DMTF standard' do
|
166
|
+
expect(subject).to receive(:output) do |output|
|
167
|
+
expect(output.protocol_version).to eq 'http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd'
|
168
|
+
end
|
169
|
+
subject.run
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'identifies the vendor as the Microsoft Corporation' do
|
173
|
+
expect(subject).to receive(:output) do |output|
|
174
|
+
expect(output.product_vendor).to eq 'Microsoft Corporation'
|
175
|
+
end
|
176
|
+
subject.run
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
context 'and the target node is Windows Server 2012 R2' do
|
181
|
+
before(:each) do
|
182
|
+
ws2012_response_body = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header/><s:Body><wsmid:IdentifyResponse xmlns:wsmid="http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd"><wsmid:ProtocolVersion>http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd</wsmid:ProtocolVersion><wsmid:ProductVendor>Microsoft Corporation</wsmid:ProductVendor><wsmid:ProductVersion>OS: 0.0.0 SP: 0.0 Stack: 3.0</wsmid:ProductVersion></wsmid:IdentifyResponse></s:Body></s:Envelope>'
|
183
|
+
http_response_mock = HTTP::Message.new_response(ws2012_response_body)
|
184
|
+
allow(http_client_mock).to receive(:post).and_return(http_response_mock)
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'identifies the stack of the product version as 3.0 ' do
|
188
|
+
expect(subject).to receive(:output) do |output|
|
189
|
+
expect(output.product_version).to eq 'OS: 0.0.0 SP: 0.0 Stack: 3.0'
|
190
|
+
end
|
191
|
+
subject.run
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'identifies the protocol version as the current DMTF standard' do
|
195
|
+
expect(subject).to receive(:output) do |output|
|
196
|
+
expect(output.protocol_version).to eq 'http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd'
|
197
|
+
end
|
198
|
+
subject.run
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'identifies the vendor as the Microsoft Corporation' do
|
202
|
+
expect(subject).to receive(:output) do |output|
|
203
|
+
expect(output.product_vendor).to eq 'Microsoft Corporation'
|
204
|
+
end
|
205
|
+
subject.run
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-winops
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robbert-Jan Sperna Weiland
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: winrm
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: winrm-elevated
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Plugin that adds functionality to Chef's Knife CLI for configuring/interacting
|
56
|
+
with nodes running Microsoft Windows
|
57
|
+
email:
|
58
|
+
- rspernaweiland@schubergphilis.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- CHANGELOG.md
|
67
|
+
- DOC_CHANGES.md
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE
|
70
|
+
- README.md
|
71
|
+
- RELEASE_NOTES.md
|
72
|
+
- Rakefile
|
73
|
+
- appveyor.yml
|
74
|
+
- ci.gemfile
|
75
|
+
- knife-winops.gemspec
|
76
|
+
- lib/chef/knife/bootstrap/Chef_bootstrap.erb
|
77
|
+
- lib/chef/knife/bootstrap/bootstrap.ps1
|
78
|
+
- lib/chef/knife/bootstrap/tail.cmd
|
79
|
+
- lib/chef/knife/bootstrap/windows-chef-client-msi.erb
|
80
|
+
- lib/chef/knife/bootstrap_windows_base.rb
|
81
|
+
- lib/chef/knife/bootstrap_windows_ssh.rb
|
82
|
+
- lib/chef/knife/bootstrap_windows_winrm.rb
|
83
|
+
- lib/chef/knife/core/windows_bootstrap_context.rb
|
84
|
+
- lib/chef/knife/knife_windows_base.rb
|
85
|
+
- lib/chef/knife/windows_cert_generate.rb
|
86
|
+
- lib/chef/knife/windows_cert_install.rb
|
87
|
+
- lib/chef/knife/windows_helper.rb
|
88
|
+
- lib/chef/knife/windows_listener_create.rb
|
89
|
+
- lib/chef/knife/winrm.rb
|
90
|
+
- lib/chef/knife/winrm_base.rb
|
91
|
+
- lib/chef/knife/winrm_knife_base.rb
|
92
|
+
- lib/chef/knife/winrm_session.rb
|
93
|
+
- lib/chef/knife/winrm_shared_options.rb
|
94
|
+
- lib/chef/knife/wsman_endpoint.rb
|
95
|
+
- lib/chef/knife/wsman_test.rb
|
96
|
+
- lib/knife-winops/path_helper.rb
|
97
|
+
- lib/knife-winops/version.rb
|
98
|
+
- spec/assets/fake_trusted_certs/excluded.txt
|
99
|
+
- spec/assets/fake_trusted_certs/github.pem
|
100
|
+
- spec/assets/fake_trusted_certs/google.crt
|
101
|
+
- spec/assets/win_fake_trusted_cert_script.txt
|
102
|
+
- spec/dummy_winrm_connection.rb
|
103
|
+
- spec/functional/bootstrap_download_spec.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
- spec/unit/knife/bootstrap_options_spec.rb
|
106
|
+
- spec/unit/knife/bootstrap_template_spec.rb
|
107
|
+
- spec/unit/knife/bootstrap_windows_winrm_spec.rb
|
108
|
+
- spec/unit/knife/core/windows_bootstrap_context_spec.rb
|
109
|
+
- spec/unit/knife/windows_cert_generate_spec.rb
|
110
|
+
- spec/unit/knife/windows_cert_install_spec.rb
|
111
|
+
- spec/unit/knife/windows_listener_create_spec.rb
|
112
|
+
- spec/unit/knife/winrm_session_spec.rb
|
113
|
+
- spec/unit/knife/winrm_spec.rb
|
114
|
+
- spec/unit/knife/wsman_test_spec.rb
|
115
|
+
homepage: https://github.com/RobbertJanSW/knife-winops
|
116
|
+
licenses:
|
117
|
+
- Apache-2.0
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: 1.9.1
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.6.13
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: Plugin that adds functionality to Chef's Knife CLI for configuring/interacting
|
139
|
+
with nodes running Microsoft Windows
|
140
|
+
test_files:
|
141
|
+
- spec/assets/fake_trusted_certs/excluded.txt
|
142
|
+
- spec/assets/fake_trusted_certs/github.pem
|
143
|
+
- spec/assets/fake_trusted_certs/google.crt
|
144
|
+
- spec/assets/win_fake_trusted_cert_script.txt
|
145
|
+
- spec/dummy_winrm_connection.rb
|
146
|
+
- spec/functional/bootstrap_download_spec.rb
|
147
|
+
- spec/spec_helper.rb
|
148
|
+
- spec/unit/knife/bootstrap_options_spec.rb
|
149
|
+
- spec/unit/knife/bootstrap_template_spec.rb
|
150
|
+
- spec/unit/knife/bootstrap_windows_winrm_spec.rb
|
151
|
+
- spec/unit/knife/core/windows_bootstrap_context_spec.rb
|
152
|
+
- spec/unit/knife/windows_cert_generate_spec.rb
|
153
|
+
- spec/unit/knife/windows_cert_install_spec.rb
|
154
|
+
- spec/unit/knife/windows_listener_create_spec.rb
|
155
|
+
- spec/unit/knife/winrm_session_spec.rb
|
156
|
+
- spec/unit/knife/winrm_spec.rb
|
157
|
+
- spec/unit/knife/wsman_test_spec.rb
|