knife-windows 1.3.0 → 1.4.0

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 +26 -26
  4. data/CHANGELOG.md +112 -108
  5. data/DOC_CHANGES.md +14 -14
  6. data/Gemfile +12 -12
  7. data/LICENSE +201 -201
  8. data/README.md +391 -385
  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 +25 -25
  16. data/lib/chef/knife/bootstrap/windows-chef-client-msi.erb +233 -247
  17. data/lib/chef/knife/bootstrap_windows_base.rb +449 -415
  18. data/lib/chef/knife/bootstrap_windows_ssh.rb +115 -115
  19. data/lib/chef/knife/bootstrap_windows_winrm.rb +95 -95
  20. data/lib/chef/knife/core/windows_bootstrap_context.rb +372 -366
  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 -122
  27. data/lib/chef/knife/winrm_base.rb +117 -117
  28. data/lib/chef/knife/winrm_knife_base.rb +305 -303
  29. data/lib/chef/knife/winrm_session.rb +88 -87
  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 +117 -117
  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 +241 -234
  41. data/spec/spec_helper.rb +94 -93
  42. data/spec/unit/knife/bootstrap_options_spec.rb +155 -155
  43. data/spec/unit/knife/bootstrap_template_spec.rb +98 -92
  44. data/spec/unit/knife/bootstrap_windows_winrm_spec.rb +341 -295
  45. data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +177 -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 +65 -65
  50. data/spec/unit/knife/winrm_spec.rb +516 -516
  51. data/spec/unit/knife/wsman_test_spec.rb +202 -202
  52. metadata +23 -4
@@ -1,177 +1,177 @@
1
- #
2
- # Author:: Bryan McLellan <btm@loftninjas.org>
3
- # Copyright:: Copyright (c) 2014 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::Core::WindowsBootstrapContext do
22
- let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new({ }, nil, { :knife => {} }) }
23
-
24
- before do
25
- allow(Chef::Knife::Core::WindowsBootstrapContext).to receive(:new).and_return(mock_bootstrap_context)
26
- end
27
-
28
- describe "fips" do
29
- before do
30
- Chef::Config[:fips] = fips_mode
31
- end
32
-
33
- after do
34
- Chef::Config.reset!
35
- end
36
-
37
- context "when fips is set" do
38
- let(:fips_mode) { true }
39
-
40
- it "sets fips mode in the client.rb" do
41
- expect(mock_bootstrap_context.config_content).to match(/fips true/)
42
- end
43
- end
44
-
45
- context "when fips is not set" do
46
- let(:fips_mode) { false }
47
-
48
- it "sets fips mode in the client.rb" do
49
- expect(mock_bootstrap_context.config_content).not_to match(/fips true/)
50
- end
51
- end
52
- end
53
-
54
- describe "validation_key", :chef_gte_12_only do
55
- before do
56
- mock_bootstrap_context.instance_variable_set(:@config, Mash.new(:validation_key => "C:\\chef\\key.pem"))
57
- end
58
-
59
- it "should return false if validation_key does not exist" do
60
- allow(::File).to receive(:expand_path)
61
- allow(::File).to receive(:exist?).and_return(false)
62
- expect(mock_bootstrap_context.validation_key).to eq(false)
63
- end
64
- end
65
-
66
- describe "latest_current_windows_chef_version_query" do
67
- it "returns the major version of the current version of Chef" do
68
- stub_const("Chef::VERSION", '11.1.2')
69
- expect(mock_bootstrap_context.latest_current_windows_chef_version_query).to eq("&v=11")
70
- end
71
-
72
- it "does not add prerelease if the version of Chef installed is a prerelease" do
73
- stub_const("Chef::VERSION", '42.0.1.alpha.1')
74
- expect(mock_bootstrap_context.latest_current_windows_chef_version_query).not_to match(/&prerelease=true/)
75
- end
76
-
77
- it "does add prerelease if the version specified to be installed is a prerelease" do
78
- allow(mock_bootstrap_context).to receive(:knife_config).and_return(Mash.new(:bootstrap_version => "12.0.0.alpha.1"))
79
- expect(mock_bootstrap_context.latest_current_windows_chef_version_query).to eq("&v=12.0.0.alpha.1&prerelease=true")
80
- end
81
-
82
- context "when the prerelease config option is set" do
83
- before do
84
- mock_bootstrap_context.instance_variable_set(:@config, Mash.new(:prerelease => true))
85
- end
86
-
87
- it "sets prerelease to true in the returned string" do
88
- expect(mock_bootstrap_context.latest_current_windows_chef_version_query).to eq("&prerelease=true")
89
- end
90
- end
91
- end
92
-
93
- describe "msi_url" do
94
- context "when config option is not set" do
95
- before do
96
- expect(mock_bootstrap_context).to receive(:latest_current_windows_chef_version_query).and_return("&v=something")
97
- end
98
-
99
- it "returns a chef.io msi url with minimal url parameters" do
100
- reference_url = "https://www.chef.io/chef/download?p=windows&v=something"
101
- expect(mock_bootstrap_context.msi_url).to eq(reference_url)
102
- end
103
-
104
- it "returns a chef.io msi url with provided url parameters substituted" do
105
- reference_url = "https://www.chef.io/chef/download?p=windows&pv=machine&m=arch&DownloadContext=ctx&v=something"
106
- expect(mock_bootstrap_context.msi_url('machine', 'arch', 'ctx')).to eq(reference_url)
107
- end
108
- end
109
-
110
- context "when msi_url config option is set" do
111
- let(:custom_url) { "file://something" }
112
-
113
- before do
114
- mock_bootstrap_context.instance_variable_set(:@config, Mash.new(:msi_url => custom_url))
115
- end
116
-
117
- it "returns the overriden url" do
118
- expect(mock_bootstrap_context.msi_url).to eq(custom_url)
119
- end
120
-
121
- it "doesn't introduce any unnecessary query parameters if provided by the template" do
122
- expect(mock_bootstrap_context.msi_url('machine', 'arch', 'ctx')).to eq(custom_url)
123
- end
124
- end
125
- end
126
-
127
- describe "bootstrap_install_command for bootstrap through WinRM" do
128
- context "when bootstrap_install_command option is passed on CLI" do
129
- let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new(['--bootstrap-install-command', 'chef-client']) }
130
- before do
131
- bootstrap.config[:bootstrap_install_command] = "chef-client"
132
- end
133
-
134
- it "sets the bootstrap_install_command option under Chef::Config::Knife object" do
135
- expect(Chef::Config[:knife][:bootstrap_install_command]).to eq("chef-client")
136
- end
137
-
138
- after do
139
- bootstrap.config.delete(:bootstrap_install_command)
140
- Chef::Config[:knife].delete(:bootstrap_install_command)
141
- end
142
- end
143
-
144
- context "when bootstrap_install_command option is not passed on CLI" do
145
- let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new([]) }
146
- it "does not set the bootstrap_install_command option under Chef::Config::Knife object" do
147
- expect(Chef::Config[:knife][:bootstrap_install_command]). to eq(nil)
148
- end
149
- end
150
- end
151
-
152
- describe "bootstrap_install_command for bootstrap through SSH" do
153
- context "when bootstrap_install_command option is passed on CLI" do
154
- let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new(['--bootstrap-install-command', 'chef-client']) }
155
- before do
156
- bootstrap.config[:bootstrap_install_command] = "chef-client"
157
- end
158
-
159
- it "sets the bootstrap_install_command option under Chef::Config::Knife object" do
160
- expect(Chef::Config[:knife][:bootstrap_install_command]).to eq("chef-client")
161
- end
162
-
163
- after do
164
- bootstrap.config.delete(:bootstrap_install_command)
165
- Chef::Config[:knife].delete(:bootstrap_install_command)
166
- end
167
- end
168
-
169
- context "when bootstrap_install_command option is not passed on CLI" do
170
- let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new([]) }
171
- it "does not set the bootstrap_install_command option under Chef::Config::Knife object" do
172
- expect(Chef::Config[:knife][:bootstrap_install_command]). to eq(nil)
173
- end
174
- end
175
- end
176
-
177
- end
1
+ #
2
+ # Author:: Bryan McLellan <btm@loftninjas.org>
3
+ # Copyright:: Copyright (c) 2014-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::Core::WindowsBootstrapContext do
22
+ let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new({ }, nil, { :knife => {} }) }
23
+
24
+ before do
25
+ allow(Chef::Knife::Core::WindowsBootstrapContext).to receive(:new).and_return(mock_bootstrap_context)
26
+ end
27
+
28
+ describe "fips" do
29
+ before do
30
+ Chef::Config[:fips] = fips_mode
31
+ end
32
+
33
+ after do
34
+ Chef::Config.reset!
35
+ end
36
+
37
+ context "when fips is set" do
38
+ let(:fips_mode) { true }
39
+
40
+ it "sets fips mode in the client.rb" do
41
+ expect(mock_bootstrap_context.config_content).to match(/fips true/)
42
+ end
43
+ end
44
+
45
+ context "when fips is not set" do
46
+ let(:fips_mode) { false }
47
+
48
+ it "sets fips mode in the client.rb" do
49
+ expect(mock_bootstrap_context.config_content).not_to match(/fips true/)
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "validation_key", :chef_gte_12_only do
55
+ before do
56
+ mock_bootstrap_context.instance_variable_set(:@config, Mash.new(:validation_key => "C:\\chef\\key.pem"))
57
+ end
58
+
59
+ it "should return false if validation_key does not exist" do
60
+ allow(::File).to receive(:expand_path)
61
+ allow(::File).to receive(:exist?).and_return(false)
62
+ expect(mock_bootstrap_context.validation_key).to eq(false)
63
+ end
64
+ end
65
+
66
+ describe "latest_current_windows_chef_version_query" do
67
+ it "returns the major version of the current version of Chef" do
68
+ stub_const("Chef::VERSION", '11.1.2')
69
+ expect(mock_bootstrap_context.latest_current_windows_chef_version_query).to eq("&v=11")
70
+ end
71
+
72
+ it "does not add prerelease if the version of Chef installed is a prerelease" do
73
+ stub_const("Chef::VERSION", '42.0.1.alpha.1')
74
+ expect(mock_bootstrap_context.latest_current_windows_chef_version_query).not_to match(/&prerelease=true/)
75
+ end
76
+
77
+ it "does add prerelease if the version specified to be installed is a prerelease" do
78
+ allow(mock_bootstrap_context).to receive(:knife_config).and_return(Mash.new(:bootstrap_version => "12.0.0.alpha.1"))
79
+ expect(mock_bootstrap_context.latest_current_windows_chef_version_query).to eq("&v=12.0.0.alpha.1&prerelease=true")
80
+ end
81
+
82
+ context "when the prerelease config option is set" do
83
+ before do
84
+ mock_bootstrap_context.instance_variable_set(:@config, Mash.new(:prerelease => true))
85
+ end
86
+
87
+ it "sets prerelease to true in the returned string" do
88
+ expect(mock_bootstrap_context.latest_current_windows_chef_version_query).to eq("&prerelease=true")
89
+ end
90
+ end
91
+ end
92
+
93
+ describe "msi_url" do
94
+ context "when config option is not set" do
95
+ before do
96
+ expect(mock_bootstrap_context).to receive(:latest_current_windows_chef_version_query).and_return("&v=something")
97
+ end
98
+
99
+ it "returns a chef.io msi url with minimal url parameters" do
100
+ reference_url = "https://www.chef.io/chef/download?p=windows&v=something"
101
+ expect(mock_bootstrap_context.msi_url).to eq(reference_url)
102
+ end
103
+
104
+ it "returns a chef.io msi url with provided url parameters substituted" do
105
+ reference_url = "https://www.chef.io/chef/download?p=windows&pv=machine&m=arch&DownloadContext=ctx&v=something"
106
+ expect(mock_bootstrap_context.msi_url('machine', 'arch', 'ctx')).to eq(reference_url)
107
+ end
108
+ end
109
+
110
+ context "when msi_url config option is set" do
111
+ let(:custom_url) { "file://something" }
112
+
113
+ before do
114
+ mock_bootstrap_context.instance_variable_set(:@config, Mash.new(:msi_url => custom_url))
115
+ end
116
+
117
+ it "returns the overriden url" do
118
+ expect(mock_bootstrap_context.msi_url).to eq(custom_url)
119
+ end
120
+
121
+ it "doesn't introduce any unnecessary query parameters if provided by the template" do
122
+ expect(mock_bootstrap_context.msi_url('machine', 'arch', 'ctx')).to eq(custom_url)
123
+ end
124
+ end
125
+ end
126
+
127
+ describe "bootstrap_install_command for bootstrap through WinRM" do
128
+ context "when bootstrap_install_command option is passed on CLI" do
129
+ let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new(['--bootstrap-install-command', 'chef-client']) }
130
+ before do
131
+ bootstrap.config[:bootstrap_install_command] = "chef-client"
132
+ end
133
+
134
+ it "sets the bootstrap_install_command option under Chef::Config::Knife object" do
135
+ expect(Chef::Config[:knife][:bootstrap_install_command]).to eq("chef-client")
136
+ end
137
+
138
+ after do
139
+ bootstrap.config.delete(:bootstrap_install_command)
140
+ Chef::Config[:knife].delete(:bootstrap_install_command)
141
+ end
142
+ end
143
+
144
+ context "when bootstrap_install_command option is not passed on CLI" do
145
+ let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new([]) }
146
+ it "does not set the bootstrap_install_command option under Chef::Config::Knife object" do
147
+ expect(Chef::Config[:knife][:bootstrap_install_command]). to eq(nil)
148
+ end
149
+ end
150
+ end
151
+
152
+ describe "bootstrap_install_command for bootstrap through SSH" do
153
+ context "when bootstrap_install_command option is passed on CLI" do
154
+ let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new(['--bootstrap-install-command', 'chef-client']) }
155
+ before do
156
+ bootstrap.config[:bootstrap_install_command] = "chef-client"
157
+ end
158
+
159
+ it "sets the bootstrap_install_command option under Chef::Config::Knife object" do
160
+ expect(Chef::Config[:knife][:bootstrap_install_command]).to eq("chef-client")
161
+ end
162
+
163
+ after do
164
+ bootstrap.config.delete(:bootstrap_install_command)
165
+ Chef::Config[:knife].delete(:bootstrap_install_command)
166
+ end
167
+ end
168
+
169
+ context "when bootstrap_install_command option is not passed on CLI" do
170
+ let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new([]) }
171
+ it "does not set the bootstrap_install_command option under Chef::Config::Knife object" do
172
+ expect(Chef::Config[:knife][:bootstrap_install_command]). to eq(nil)
173
+ end
174
+ end
175
+ end
176
+
177
+ end
@@ -1,90 +1,90 @@
1
- #
2
- # Author:: Mukta Aphale <mukta.aphale@clogeny.com>
3
- # Copyright:: Copyright (c) 2014 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 implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require 'spec_helper'
20
- require 'chef/knife/windows_cert_generate'
21
- require 'openssl'
22
-
23
- describe Chef::Knife::WindowsCertGenerate do
24
- before(:all) do
25
- @certgen = Chef::Knife::WindowsCertGenerate.new(["-H","something.mydomain.com"])
26
- end
27
-
28
- it "generates RSA key pair" do
29
- @certgen.config[:key_length] = 2048
30
- key = @certgen.generate_keypair
31
- expect(key).to be_instance_of OpenSSL::PKey::RSA
32
- end
33
-
34
- it "generates X509 certificate" do
35
- @certgen.config[:domain] = "test.com"
36
- @certgen.config[:cert_validity] = "24"
37
- key = @certgen.generate_keypair
38
- certificate = @certgen.generate_certificate key
39
- expect(certificate).to be_instance_of OpenSSL::X509::Certificate
40
- end
41
-
42
- it "writes certificate to file" do
43
- expect(File).to receive(:open).exactly(3).times
44
- cert = double(OpenSSL::X509::Certificate.new)
45
- key = double(OpenSSL::PKey::RSA.new)
46
- @certgen.config[:cert_passphrase] = "password"
47
- expect(OpenSSL::PKCS12).to receive(:create).with("password", "winrmcert", key, cert)
48
- @certgen.write_certificate_to_file cert, "test", key
49
- end
50
-
51
- context "when creating certificate files" do
52
- before do
53
- @certgen.thumbprint = "TEST_THUMBPRINT"
54
- allow(Dir).to receive(:glob).and_return([])
55
- allow(@certgen).to receive(:generate_keypair)
56
- allow(@certgen).to receive(:generate_certificate)
57
- expect(@certgen.ui).to receive(:info).with("Generated Certificates:")
58
- expect(@certgen.ui).to receive(:info).with("- winrmcert.pfx - PKCS12 format key pair. Contains public and private keys, can be used with an SSL server.")
59
- expect(@certgen.ui).to receive(:info).with("- winrmcert.b64 - Base64 encoded PKCS12 key pair. Contains public and private keys, used by some cloud provider API's to configure SSL servers.")
60
- expect(@certgen.ui).to receive(:info).with("- winrmcert.pem - Base64 encoded public certificate only. Required by the client to connect to the server.")
61
- expect(@certgen.ui).to receive(:info).with("Certificate Thumbprint: TEST_THUMBPRINT")
62
- end
63
-
64
- it "writes out certificates" do
65
- @certgen.config[:output_file] = 'winrmcert'
66
-
67
- expect(@certgen).to receive(:certificates_already_exist?).and_return(false)
68
- expect(@certgen).to receive(:write_certificate_to_file)
69
- @certgen.run
70
- end
71
-
72
- it "prompts when certificates already exist" do
73
- file_path = 'winrmcert'
74
- @certgen.config[:output_file] = file_path
75
-
76
- allow(Dir).to receive(:glob).and_return([file_path])
77
- expect(@certgen).to receive(:confirm).with("Do you really want to overwrite existing certificates")
78
- expect(@certgen).to receive(:write_certificate_to_file)
79
- @certgen.run
80
- end
81
-
82
- it "creates certificate on specified file path" do
83
- file_path = "/tmp/winrmcert"
84
- @certgen.name_args = [file_path]
85
-
86
- expect(@certgen).to receive(:write_certificate_to_file) # FIXME: this should be testing that we get /tmp/winrmcert as the filename
87
- @certgen.run
88
- end
89
- end
90
- end
1
+ #
2
+ # Author:: Mukta Aphale <mukta.aphale@clogeny.com>
3
+ # Copyright:: Copyright (c) 2014-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
+ require 'chef/knife/windows_cert_generate'
21
+ require 'openssl'
22
+
23
+ describe Chef::Knife::WindowsCertGenerate do
24
+ before(:all) do
25
+ @certgen = Chef::Knife::WindowsCertGenerate.new(["-H","something.mydomain.com"])
26
+ end
27
+
28
+ it "generates RSA key pair" do
29
+ @certgen.config[:key_length] = 2048
30
+ key = @certgen.generate_keypair
31
+ expect(key).to be_instance_of OpenSSL::PKey::RSA
32
+ end
33
+
34
+ it "generates X509 certificate" do
35
+ @certgen.config[:domain] = "test.com"
36
+ @certgen.config[:cert_validity] = "24"
37
+ key = @certgen.generate_keypair
38
+ certificate = @certgen.generate_certificate key
39
+ expect(certificate).to be_instance_of OpenSSL::X509::Certificate
40
+ end
41
+
42
+ it "writes certificate to file" do
43
+ expect(File).to receive(:open).exactly(3).times
44
+ cert = double(OpenSSL::X509::Certificate.new)
45
+ key = double(OpenSSL::PKey::RSA.new)
46
+ @certgen.config[:cert_passphrase] = "password"
47
+ expect(OpenSSL::PKCS12).to receive(:create).with("password", "winrmcert", key, cert)
48
+ @certgen.write_certificate_to_file cert, "test", key
49
+ end
50
+
51
+ context "when creating certificate files" do
52
+ before do
53
+ @certgen.thumbprint = "TEST_THUMBPRINT"
54
+ allow(Dir).to receive(:glob).and_return([])
55
+ allow(@certgen).to receive(:generate_keypair)
56
+ allow(@certgen).to receive(:generate_certificate)
57
+ expect(@certgen.ui).to receive(:info).with("Generated Certificates:")
58
+ expect(@certgen.ui).to receive(:info).with("- winrmcert.pfx - PKCS12 format key pair. Contains public and private keys, can be used with an SSL server.")
59
+ expect(@certgen.ui).to receive(:info).with("- winrmcert.b64 - Base64 encoded PKCS12 key pair. Contains public and private keys, used by some cloud provider API's to configure SSL servers.")
60
+ expect(@certgen.ui).to receive(:info).with("- winrmcert.pem - Base64 encoded public certificate only. Required by the client to connect to the server.")
61
+ expect(@certgen.ui).to receive(:info).with("Certificate Thumbprint: TEST_THUMBPRINT")
62
+ end
63
+
64
+ it "writes out certificates" do
65
+ @certgen.config[:output_file] = 'winrmcert'
66
+
67
+ expect(@certgen).to receive(:certificates_already_exist?).and_return(false)
68
+ expect(@certgen).to receive(:write_certificate_to_file)
69
+ @certgen.run
70
+ end
71
+
72
+ it "prompts when certificates already exist" do
73
+ file_path = 'winrmcert'
74
+ @certgen.config[:output_file] = file_path
75
+
76
+ allow(Dir).to receive(:glob).and_return([file_path])
77
+ expect(@certgen).to receive(:confirm).with("Do you really want to overwrite existing certificates")
78
+ expect(@certgen).to receive(:write_certificate_to_file)
79
+ @certgen.run
80
+ end
81
+
82
+ it "creates certificate on specified file path" do
83
+ file_path = "/tmp/winrmcert"
84
+ @certgen.name_args = [file_path]
85
+
86
+ expect(@certgen).to receive(:write_certificate_to_file) # FIXME: this should be testing that we get /tmp/winrmcert as the filename
87
+ @certgen.run
88
+ end
89
+ end
90
+ end
@@ -1,51 +1,51 @@
1
- #
2
- # Author:: Mukta Aphale <mukta.aphale@clogeny.com>
3
- # Copyright:: Copyright (c) 2014 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 implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require 'spec_helper'
20
- require 'chef/knife/windows_cert_install'
21
-
22
- describe Chef::Knife::WindowsCertInstall do
23
- context "on Windows" do
24
- before do
25
- allow(Chef::Platform).to receive(:windows?).and_return(true)
26
- @certinstall = Chef::Knife::WindowsCertInstall.new
27
- end
28
-
29
- it "installs certificate" do
30
- @certinstall.name_args = ["test-path"]
31
- @certinstall.config[:cert_passphrase] = "your-secret!"
32
- allow(Chef::Platform).to receive(:windows?).and_return(true)
33
- expect(@certinstall).to receive(:`).with("powershell.exe -Command \" 'your-secret!' | certutil -importPFX 'test-path' AT_KEYEXCHANGE\"")
34
- expect(@certinstall.ui).to receive(:info).with("Certificate added to Certificate Store")
35
- expect(@certinstall.ui).to receive(:info).with("Adding certificate to the Windows Certificate Store...")
36
- @certinstall.run
37
- end
38
- end
39
-
40
- context "not on Windows" do
41
- before do
42
- allow(Chef::Platform).to receive(:windows?).and_return(false)
43
- @listener = Chef::Knife::WindowsListenerCreate.new
44
- end
45
-
46
- it "exits with an error" do
47
- expect(@listener.ui).to receive(:error)
48
- expect { @listener.run }.to raise_error(SystemExit)
49
- end
50
- end
51
- end
1
+ #
2
+ # Author:: Mukta Aphale <mukta.aphale@clogeny.com>
3
+ # Copyright:: Copyright (c) 2014-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
+ require 'chef/knife/windows_cert_install'
21
+
22
+ describe Chef::Knife::WindowsCertInstall do
23
+ context "on Windows" do
24
+ before do
25
+ allow(Chef::Platform).to receive(:windows?).and_return(true)
26
+ @certinstall = Chef::Knife::WindowsCertInstall.new
27
+ end
28
+
29
+ it "installs certificate" do
30
+ @certinstall.name_args = ["test-path"]
31
+ @certinstall.config[:cert_passphrase] = "your-secret!"
32
+ allow(Chef::Platform).to receive(:windows?).and_return(true)
33
+ expect(@certinstall).to receive(:`).with("powershell.exe -Command \" 'your-secret!' | certutil -importPFX 'test-path' AT_KEYEXCHANGE\"")
34
+ expect(@certinstall.ui).to receive(:info).with("Certificate added to Certificate Store")
35
+ expect(@certinstall.ui).to receive(:info).with("Adding certificate to the Windows Certificate Store...")
36
+ @certinstall.run
37
+ end
38
+ end
39
+
40
+ context "not on Windows" do
41
+ before do
42
+ allow(Chef::Platform).to receive(:windows?).and_return(false)
43
+ @listener = Chef::Knife::WindowsListenerCreate.new
44
+ end
45
+
46
+ it "exits with an error" do
47
+ expect(@listener.ui).to receive(:error)
48
+ expect { @listener.run }.to raise_error(SystemExit)
49
+ end
50
+ end
51
+ end