knife-windows 1.7.0 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +26 -26
  3. data/CHANGELOG.md +139 -135
  4. data/DOC_CHANGES.md +22 -22
  5. data/Gemfile +13 -13
  6. data/README.md +404 -404
  7. data/RELEASE_NOTES.md +9 -9
  8. data/appveyor.yml +39 -39
  9. data/ci.gemfile +16 -16
  10. data/knife-windows.gemspec +26 -26
  11. data/lib/chef/knife/bootstrap/windows-chef-client-msi.erb +246 -246
  12. data/lib/chef/knife/bootstrap_windows_base.rb +443 -443
  13. data/lib/chef/knife/bootstrap_windows_ssh.rb +116 -116
  14. data/lib/chef/knife/bootstrap_windows_winrm.rb +102 -102
  15. data/lib/chef/knife/core/windows_bootstrap_context.rb +378 -378
  16. data/lib/chef/knife/knife_windows_base.rb +33 -33
  17. data/lib/chef/knife/windows_cert_generate.rb +155 -155
  18. data/lib/chef/knife/windows_cert_install.rb +68 -68
  19. data/lib/chef/knife/windows_helper.rb +36 -36
  20. data/lib/chef/knife/windows_listener_create.rb +107 -107
  21. data/lib/chef/knife/winrm.rb +122 -122
  22. data/lib/chef/knife/winrm_base.rb +128 -128
  23. data/lib/chef/knife/winrm_knife_base.rb +307 -307
  24. data/lib/chef/knife/winrm_session.rb +98 -98
  25. data/lib/chef/knife/winrm_shared_options.rb +47 -47
  26. data/lib/chef/knife/wsman_endpoint.rb +44 -44
  27. data/lib/chef/knife/wsman_test.rb +118 -118
  28. data/lib/knife-windows/path_helper.rb +242 -234
  29. data/lib/knife-windows/version.rb +6 -6
  30. data/spec/assets/fake_trusted_certs/excluded.txt +2 -0
  31. data/spec/assets/fake_trusted_certs/github.pem +42 -0
  32. data/spec/assets/fake_trusted_certs/google.crt +41 -0
  33. data/spec/assets/win_fake_trusted_cert_script.txt +89 -0
  34. data/spec/assets/win_template_rendered_with_bootstrap_install_command.txt +223 -223
  35. data/spec/assets/win_template_rendered_with_bootstrap_install_command_on_12_5_client.txt +223 -223
  36. data/spec/assets/win_template_rendered_without_bootstrap_install_command.txt +335 -335
  37. data/spec/assets/win_template_rendered_without_bootstrap_install_command_on_12_5_client.txt +335 -335
  38. data/spec/assets/win_template_unrendered.txt +246 -246
  39. data/spec/dummy_winrm_connection.rb +21 -21
  40. data/spec/functional/bootstrap_download_spec.rb +236 -236
  41. data/spec/spec_helper.rb +94 -94
  42. data/spec/unit/knife/bootstrap_options_spec.rb +157 -157
  43. data/spec/unit/knife/bootstrap_template_spec.rb +98 -98
  44. data/spec/unit/knife/bootstrap_windows_winrm_spec.rb +423 -423
  45. data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +213 -177
  46. data/spec/unit/knife/windows_cert_generate_spec.rb +90 -90
  47. data/spec/unit/knife/windows_cert_install_spec.rb +51 -51
  48. data/spec/unit/knife/windows_listener_create_spec.rb +76 -76
  49. data/spec/unit/knife/winrm_session_spec.rb +95 -95
  50. data/spec/unit/knife/winrm_spec.rb +500 -500
  51. data/spec/unit/knife/wsman_test_spec.rb +209 -209
  52. metadata +7 -3
@@ -1,21 +1,21 @@
1
- module Dummy
2
- class WinRMTransport
3
- attr_reader :httpcli
4
-
5
-
6
- def initialize
7
- @httpcli = HTTPClient.new
8
- end
9
- end
10
-
11
- class Connection
12
- attr_reader :transport
13
- attr_accessor :logger
14
-
15
- def initialize
16
- @transport = WinRMTransport.new
17
- end
18
-
19
- def shell; end
20
- end
21
- end
1
+ module Dummy
2
+ class WinRMTransport
3
+ attr_reader :httpcli
4
+
5
+
6
+ def initialize
7
+ @httpcli = HTTPClient.new
8
+ end
9
+ end
10
+
11
+ class Connection
12
+ attr_reader :transport
13
+ attr_accessor :logger
14
+
15
+ def initialize
16
+ @transport = WinRMTransport.new
17
+ end
18
+
19
+ def shell; end
20
+ end
21
+ end
@@ -1,236 +1,236 @@
1
- #
2
- # Author:: Adam Edwards (<adamed@chef.io>)
3
- # Copyright:: Copyright (c) 2012-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
15
- # implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
-
20
- require 'dummy_winrm_connection'
21
- require 'spec_helper'
22
- require 'tmpdir'
23
-
24
- # These test cases exercise the Knife::Windows knife plugin's ability
25
- # to download a bootstrap msi as part of the bootstrap process on
26
- # Windows nodes. The test modifies the Windows batch file generated
27
- # from an erb template in the plugin source in order to enable execution
28
- # of only the download functionality contained in the bootstrap template.
29
- # The test relies on knowledge of the fields of the template itself and
30
- # also on knowledge of the contents and structure of the Windows batch
31
- # file generated by the template.
32
- #
33
- # Note that if the bootstrap template changes substantially, the tests
34
- # should fail and will require re-implementation. If such changes
35
- # occur, the bootstrap code should be refactored to explicitly expose
36
- # the download funcitonality separately from other tasks to make the
37
- # test more robust.
38
- describe 'Knife::Windows::Core msi download functionality for knife Windows winrm bootstrap template' do
39
-
40
- before(:all) do
41
- # Since we're always running 32-bit Ruby, fix the
42
- # PROCESSOR_ARCHITECTURE environment variable.
43
-
44
- if ENV["PROCESSOR_ARCHITEW6432"]
45
- ENV["PROCESSOR_ARCHITECTURE"] = ENV["PROCESSOR_ARCHITEW6432"]
46
- end
47
-
48
- # All file artifacts from this test will be written into this directory
49
- @temp_directory = Dir.mktmpdir("bootstrap_test")
50
-
51
- # Location to which the download script will be modified to write
52
- # the downloaded msi
53
- @local_file_download_destination = "#{@temp_directory}/chef-client-latest.msi"
54
-
55
- source_code_directory = File.dirname(__FILE__)
56
- @template_file_path ="#{source_code_directory}/../../lib/chef/knife/bootstrap/windows-chef-client-msi.erb"
57
- end
58
-
59
- after(:all) do
60
- # Clear the temp directory upon exit
61
- if Dir.exists?(@temp_directory)
62
- FileUtils::remove_dir(@temp_directory)
63
- end
64
- end
65
-
66
- describe "running on any version of the Windows OS", :windows_only do
67
- let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new({ }, nil, { :knife => {} }) }
68
- let(:mock_winrm) { Chef::Knife::Winrm.new }
69
-
70
- before do
71
- # Stub the bootstrap context and prevent config related sections
72
- # from being populated, i.e. chef installation and first chef
73
- # run sections
74
- allow(mock_bootstrap_context).to receive(:validation_key).and_return("echo.validation_key")
75
- allow(mock_bootstrap_context).to receive(:secret).and_return("echo.encrypted_data_bag_secret")
76
- allow(mock_bootstrap_context).to receive(:config_content).and_return("echo.config_content")
77
- allow(mock_bootstrap_context).to receive(:start_chef).and_return("echo.echo start_chef_command")
78
- allow(mock_bootstrap_context).to receive(:run_list).and_return("echo.run_list")
79
- allow(mock_bootstrap_context).to receive(:install_chef).and_return("echo.echo install_chef_command")
80
-
81
- # Change the directories where bootstrap files will be created
82
- allow(mock_bootstrap_context).to receive(:bootstrap_directory).and_return(@temp_directory.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
83
- allow(mock_bootstrap_context).to receive(:local_download_path).and_return(@local_file_download_destination.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
84
-
85
- # Prevent password prompt during bootstrap process
86
- allow(mock_winrm.ui).to receive(:ask).and_return(nil)
87
- allow(Chef::Knife::Winrm).to receive(:new).and_return(mock_winrm)
88
-
89
- allow(Chef::Knife::Core::WindowsBootstrapContext).to receive(:new).and_return(mock_bootstrap_context)
90
- Chef::Config[:knife] = {:winrm_transport => 'plaintext', :chef_node_name => 'foo.example.com', :winrm_authentication_protocol => 'negotiate'}
91
- end
92
-
93
- it "downloads the chef-client MSI from the default location during winrm bootstrap" do
94
- run_download_scenario
95
- end
96
-
97
- context "when provided a custom msi_url to fetch from" do
98
- let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new(
99
- { :msi_url => "file:///C:/Windows/System32/xcopy.exe" }, nil, { :knife => {} }) }
100
- it "downloads the chef-client MSI from a custom path during winrm bootstrap" do
101
- run_download_scenario
102
- end
103
- end
104
-
105
- context "when provided a custom msi_url with space in path to fetch from" do
106
- let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new(
107
- { :msi_url => "file:///C:/Program Files/Windows NT/Accessories/wordpad.exe" }, nil, { :knife => {} }) }
108
- it "downloads the chef-client MSI from a custom path with spaces during winrm bootstrap" do
109
- run_download_scenario
110
- end
111
- end
112
- end
113
-
114
- def download_succeeded?
115
- File.exists?(@local_file_download_destination) && ! File.zero?(@local_file_download_destination)
116
- end
117
-
118
- # Remove file artifacts generated by individual test cases
119
- def clean_test_case
120
- if File.exists?(@local_file_download_destination)
121
- File.delete(@local_file_download_destination)
122
- end
123
- end
124
-
125
- def run_download_scenario
126
- clean_test_case
127
-
128
- winrm_bootstrapper = Chef::Knife::BootstrapWindowsWinrm.new([ "127.0.0.1" ])
129
-
130
- if chef_gte_12?
131
- winrm_bootstrapper.client_builder = instance_double("Chef::Knife::Bootstrap::ClientBuilder", :run => nil, :client_path => nil)
132
- elsif chef_lt_12?
133
- allow(File).to receive(:exist?).with(File.expand_path(Chef::Config[:validation_key])).and_return(true)
134
- end
135
-
136
- allow(WinRM::Connection).to receive(:new).and_return(Dummy::Connection.new)
137
- allow(winrm_bootstrapper).to receive(:wait_for_remote_response)
138
- allow(winrm_bootstrapper).to receive(:validate_options!)
139
- allow(winrm_bootstrapper.ui).to receive(:ask).and_return(nil)
140
- winrm_bootstrapper.config[:template_file] = @template_file_path
141
- winrm_bootstrapper.config[:run_list] = []
142
- # Execute the commands locally that would normally be executed via WinRM
143
- allow(winrm_bootstrapper).to receive(:run_command) do |command|
144
- system(command)
145
- end
146
-
147
- winrm_bootstrapper.run
148
-
149
- # Download should succeed
150
- expect(download_succeeded?).to be true
151
- end
152
- end
153
-
154
- describe "bootstrap_install_command functionality through WinRM protocol", :if_chef_11 => true do
155
- context "bootstrap_install_command option is not specified" do
156
- let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new([]) }
157
- before do
158
- @template_input = sample_data('win_template_unrendered.txt')
159
- @template_output = sample_data('win_template_rendered_without_bootstrap_install_command.txt')
160
- end
161
-
162
- it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil", :chef_lt_12_5_only => true do
163
- expect(bootstrap.send(:render_template,@template_input)).to eq(
164
- @template_output)
165
- end
166
-
167
- context "when running chef-client 12.5.0 or greater", :chef_gte_12_5_only => true do
168
- let(:template_12_5_output) { sample_data('win_template_rendered_without_bootstrap_install_command_on_12_5_client.txt') }
169
- it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil" do
170
- expect(bootstrap.send(:render_template,@template_input)).to eq(
171
- template_12_5_output)
172
- end
173
- end
174
- end
175
-
176
- context "bootstrap_install_command option is specified" do
177
- let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new(['--bootstrap-install-command', 'chef-client -o recipe[cbk1::rec2]']) }
178
- before do
179
- bootstrap.config[:bootstrap_install_command] = "chef-client -o recipe[cbk1::rec2]"
180
- @template_input = sample_data('win_template_unrendered.txt')
181
- @template_output = sample_data('win_template_rendered_with_bootstrap_install_command.txt')
182
- end
183
-
184
- it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template", :chef_lt_12_5_only => true do
185
- expect(bootstrap.send(:render_template,@template_input)).to eq(
186
- @template_output)
187
- end
188
-
189
- context "when running chef-client 12.5.0 or greater", :chef_gte_12_5_only => true do
190
- let(:template_12_5_output) { sample_data('win_template_rendered_with_bootstrap_install_command_on_12_5_client.txt') }
191
- it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template" do
192
- expect(bootstrap.send(:render_template,@template_input)).to eq(
193
- template_12_5_output)
194
- end
195
- end
196
-
197
- after do
198
- bootstrap.config.delete(:bootstrap_install_command)
199
- Chef::Config[:knife].delete(:bootstrap_install_command)
200
- end
201
- end
202
- end
203
-
204
- describe "bootstrap_install_command functionality through SSH protocol", :if_chef_11 => true, :chef_lt_12_5_only => true do
205
- context "bootstrap_install_command option is not specified" do
206
- let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new([]) }
207
- before do
208
- @template_input = sample_data('win_template_unrendered.txt')
209
- @template_output = sample_data('win_template_rendered_without_bootstrap_install_command.txt')
210
- end
211
-
212
- it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil" do
213
- expect(bootstrap.send(:render_template,@template_input)).to eq(
214
- @template_output)
215
- end
216
- end
217
-
218
- context "bootstrap_install_command option is specified" do
219
- let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new(['--bootstrap-install-command', 'chef-client -o recipe[cbk1::rec2]']) }
220
- before do
221
- bootstrap.config[:bootstrap_install_command] = "chef-client -o recipe[cbk1::rec2]"
222
- @template_input = sample_data('win_template_unrendered.txt')
223
- @template_output = sample_data('win_template_rendered_with_bootstrap_install_command.txt')
224
- end
225
-
226
- it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template" do
227
- expect(bootstrap.send(:render_template,@template_input)).to eq(
228
- @template_output)
229
- end
230
-
231
- after do
232
- bootstrap.config.delete(:bootstrap_install_command)
233
- Chef::Config[:knife].delete(:bootstrap_install_command)
234
- end
235
- end
236
- end
1
+ #
2
+ # Author:: Adam Edwards (<adamed@chef.io>)
3
+ # Copyright:: Copyright (c) 2012-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
15
+ # implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require 'dummy_winrm_connection'
21
+ require 'spec_helper'
22
+ require 'tmpdir'
23
+
24
+ # These test cases exercise the Knife::Windows knife plugin's ability
25
+ # to download a bootstrap msi as part of the bootstrap process on
26
+ # Windows nodes. The test modifies the Windows batch file generated
27
+ # from an erb template in the plugin source in order to enable execution
28
+ # of only the download functionality contained in the bootstrap template.
29
+ # The test relies on knowledge of the fields of the template itself and
30
+ # also on knowledge of the contents and structure of the Windows batch
31
+ # file generated by the template.
32
+ #
33
+ # Note that if the bootstrap template changes substantially, the tests
34
+ # should fail and will require re-implementation. If such changes
35
+ # occur, the bootstrap code should be refactored to explicitly expose
36
+ # the download funcitonality separately from other tasks to make the
37
+ # test more robust.
38
+ describe 'Knife::Windows::Core msi download functionality for knife Windows winrm bootstrap template' do
39
+
40
+ before(:all) do
41
+ # Since we're always running 32-bit Ruby, fix the
42
+ # PROCESSOR_ARCHITECTURE environment variable.
43
+
44
+ if ENV["PROCESSOR_ARCHITEW6432"]
45
+ ENV["PROCESSOR_ARCHITECTURE"] = ENV["PROCESSOR_ARCHITEW6432"]
46
+ end
47
+
48
+ # All file artifacts from this test will be written into this directory
49
+ @temp_directory = Dir.mktmpdir("bootstrap_test")
50
+
51
+ # Location to which the download script will be modified to write
52
+ # the downloaded msi
53
+ @local_file_download_destination = "#{@temp_directory}/chef-client-latest.msi"
54
+
55
+ source_code_directory = File.dirname(__FILE__)
56
+ @template_file_path ="#{source_code_directory}/../../lib/chef/knife/bootstrap/windows-chef-client-msi.erb"
57
+ end
58
+
59
+ after(:all) do
60
+ # Clear the temp directory upon exit
61
+ if Dir.exists?(@temp_directory)
62
+ FileUtils::remove_dir(@temp_directory)
63
+ end
64
+ end
65
+
66
+ describe "running on any version of the Windows OS", :windows_only do
67
+ let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new({ }, nil, { :knife => {} }) }
68
+ let(:mock_winrm) { Chef::Knife::Winrm.new }
69
+
70
+ before do
71
+ # Stub the bootstrap context and prevent config related sections
72
+ # from being populated, i.e. chef installation and first chef
73
+ # run sections
74
+ allow(mock_bootstrap_context).to receive(:validation_key).and_return("echo.validation_key")
75
+ allow(mock_bootstrap_context).to receive(:secret).and_return("echo.encrypted_data_bag_secret")
76
+ allow(mock_bootstrap_context).to receive(:config_content).and_return("echo.config_content")
77
+ allow(mock_bootstrap_context).to receive(:start_chef).and_return("echo.echo start_chef_command")
78
+ allow(mock_bootstrap_context).to receive(:run_list).and_return("echo.run_list")
79
+ allow(mock_bootstrap_context).to receive(:install_chef).and_return("echo.echo install_chef_command")
80
+
81
+ # Change the directories where bootstrap files will be created
82
+ allow(mock_bootstrap_context).to receive(:bootstrap_directory).and_return(@temp_directory.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
83
+ allow(mock_bootstrap_context).to receive(:local_download_path).and_return(@local_file_download_destination.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
84
+
85
+ # Prevent password prompt during bootstrap process
86
+ allow(mock_winrm.ui).to receive(:ask).and_return(nil)
87
+ allow(Chef::Knife::Winrm).to receive(:new).and_return(mock_winrm)
88
+
89
+ allow(Chef::Knife::Core::WindowsBootstrapContext).to receive(:new).and_return(mock_bootstrap_context)
90
+ Chef::Config[:knife] = {:winrm_transport => 'plaintext', :chef_node_name => 'foo.example.com', :winrm_authentication_protocol => 'negotiate'}
91
+ end
92
+
93
+ it "downloads the chef-client MSI from the default location during winrm bootstrap" do
94
+ run_download_scenario
95
+ end
96
+
97
+ context "when provided a custom msi_url to fetch from" do
98
+ let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new(
99
+ { :msi_url => "file:///C:/Windows/System32/xcopy.exe" }, nil, { :knife => {} }) }
100
+ it "downloads the chef-client MSI from a custom path during winrm bootstrap" do
101
+ run_download_scenario
102
+ end
103
+ end
104
+
105
+ context "when provided a custom msi_url with space in path to fetch from" do
106
+ let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new(
107
+ { :msi_url => "file:///C:/Program Files/Windows NT/Accessories/wordpad.exe" }, nil, { :knife => {} }) }
108
+ it "downloads the chef-client MSI from a custom path with spaces during winrm bootstrap" do
109
+ run_download_scenario
110
+ end
111
+ end
112
+ end
113
+
114
+ def download_succeeded?
115
+ File.exists?(@local_file_download_destination) && ! File.zero?(@local_file_download_destination)
116
+ end
117
+
118
+ # Remove file artifacts generated by individual test cases
119
+ def clean_test_case
120
+ if File.exists?(@local_file_download_destination)
121
+ File.delete(@local_file_download_destination)
122
+ end
123
+ end
124
+
125
+ def run_download_scenario
126
+ clean_test_case
127
+
128
+ winrm_bootstrapper = Chef::Knife::BootstrapWindowsWinrm.new([ "127.0.0.1" ])
129
+
130
+ if chef_gte_12?
131
+ winrm_bootstrapper.client_builder = instance_double("Chef::Knife::Bootstrap::ClientBuilder", :run => nil, :client_path => nil)
132
+ elsif chef_lt_12?
133
+ allow(File).to receive(:exist?).with(File.expand_path(Chef::Config[:validation_key])).and_return(true)
134
+ end
135
+
136
+ allow(WinRM::Connection).to receive(:new).and_return(Dummy::Connection.new)
137
+ allow(winrm_bootstrapper).to receive(:wait_for_remote_response)
138
+ allow(winrm_bootstrapper).to receive(:validate_options!)
139
+ allow(winrm_bootstrapper.ui).to receive(:ask).and_return(nil)
140
+ winrm_bootstrapper.config[:template_file] = @template_file_path
141
+ winrm_bootstrapper.config[:run_list] = []
142
+ # Execute the commands locally that would normally be executed via WinRM
143
+ allow(winrm_bootstrapper).to receive(:run_command) do |command|
144
+ system(command)
145
+ end
146
+
147
+ winrm_bootstrapper.run
148
+
149
+ # Download should succeed
150
+ expect(download_succeeded?).to be true
151
+ end
152
+ end
153
+
154
+ describe "bootstrap_install_command functionality through WinRM protocol", :if_chef_11 => true do
155
+ context "bootstrap_install_command option is not specified" do
156
+ let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new([]) }
157
+ before do
158
+ @template_input = sample_data('win_template_unrendered.txt')
159
+ @template_output = sample_data('win_template_rendered_without_bootstrap_install_command.txt')
160
+ end
161
+
162
+ it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil", :chef_lt_12_5_only => true do
163
+ expect(bootstrap.send(:render_template,@template_input)).to eq(
164
+ @template_output)
165
+ end
166
+
167
+ context "when running chef-client 12.5.0 or greater", :chef_gte_12_5_only => true do
168
+ let(:template_12_5_output) { sample_data('win_template_rendered_without_bootstrap_install_command_on_12_5_client.txt') }
169
+ it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil" do
170
+ expect(bootstrap.send(:render_template,@template_input)).to eq(
171
+ template_12_5_output)
172
+ end
173
+ end
174
+ end
175
+
176
+ context "bootstrap_install_command option is specified" do
177
+ let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new(['--bootstrap-install-command', 'chef-client -o recipe[cbk1::rec2]']) }
178
+ before do
179
+ bootstrap.config[:bootstrap_install_command] = "chef-client -o recipe[cbk1::rec2]"
180
+ @template_input = sample_data('win_template_unrendered.txt')
181
+ @template_output = sample_data('win_template_rendered_with_bootstrap_install_command.txt')
182
+ end
183
+
184
+ it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template", :chef_lt_12_5_only => true do
185
+ expect(bootstrap.send(:render_template,@template_input)).to eq(
186
+ @template_output)
187
+ end
188
+
189
+ context "when running chef-client 12.5.0 or greater", :chef_gte_12_5_only => true do
190
+ let(:template_12_5_output) { sample_data('win_template_rendered_with_bootstrap_install_command_on_12_5_client.txt') }
191
+ it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template" do
192
+ expect(bootstrap.send(:render_template,@template_input)).to eq(
193
+ template_12_5_output)
194
+ end
195
+ end
196
+
197
+ after do
198
+ bootstrap.config.delete(:bootstrap_install_command)
199
+ Chef::Config[:knife].delete(:bootstrap_install_command)
200
+ end
201
+ end
202
+ end
203
+
204
+ describe "bootstrap_install_command functionality through SSH protocol", :if_chef_11 => true, :chef_lt_12_5_only => true do
205
+ context "bootstrap_install_command option is not specified" do
206
+ let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new([]) }
207
+ before do
208
+ @template_input = sample_data('win_template_unrendered.txt')
209
+ @template_output = sample_data('win_template_rendered_without_bootstrap_install_command.txt')
210
+ end
211
+
212
+ it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil" do
213
+ expect(bootstrap.send(:render_template,@template_input)).to eq(
214
+ @template_output)
215
+ end
216
+ end
217
+
218
+ context "bootstrap_install_command option is specified" do
219
+ let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new(['--bootstrap-install-command', 'chef-client -o recipe[cbk1::rec2]']) }
220
+ before do
221
+ bootstrap.config[:bootstrap_install_command] = "chef-client -o recipe[cbk1::rec2]"
222
+ @template_input = sample_data('win_template_unrendered.txt')
223
+ @template_output = sample_data('win_template_rendered_with_bootstrap_install_command.txt')
224
+ end
225
+
226
+ it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template" do
227
+ expect(bootstrap.send(:render_template,@template_input)).to eq(
228
+ @template_output)
229
+ end
230
+
231
+ after do
232
+ bootstrap.config.delete(:bootstrap_install_command)
233
+ Chef::Config[:knife].delete(:bootstrap_install_command)
234
+ end
235
+ end
236
+ end