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