knife-windows 1.0.0.rc.1 → 1.0.0.rc.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -5
- data/.travis.yml +20 -20
- data/CHANGELOG.md +75 -74
- data/DOC_CHANGES.md +323 -323
- data/Gemfile +12 -12
- data/LICENSE +201 -201
- data/README.md +393 -292
- data/RELEASE_NOTES.md +79 -74
- data/Rakefile +21 -16
- data/appveyor.yml +42 -42
- data/ci.gemfile +15 -15
- data/features/knife_help.feature +20 -20
- data/features/support/env.rb +5 -5
- data/knife-windows.gemspec +28 -28
- data/lib/chef/knife/bootstrap/windows-chef-client-msi.erb +247 -241
- data/lib/chef/knife/bootstrap_windows_base.rb +388 -368
- data/lib/chef/knife/bootstrap_windows_ssh.rb +110 -110
- data/lib/chef/knife/bootstrap_windows_winrm.rb +102 -113
- data/lib/chef/knife/core/windows_bootstrap_context.rb +361 -362
- data/lib/chef/knife/knife_windows_base.rb +33 -0
- data/lib/chef/knife/windows_cert_generate.rb +155 -155
- data/lib/chef/knife/windows_cert_install.rb +68 -68
- data/lib/chef/knife/windows_helper.rb +36 -36
- data/lib/chef/knife/windows_listener_create.rb +107 -107
- data/lib/chef/knife/winrm.rb +212 -191
- data/lib/chef/knife/winrm_base.rb +118 -125
- data/lib/chef/knife/winrm_knife_base.rb +218 -201
- data/lib/chef/knife/winrm_session.rb +80 -71
- data/lib/chef/knife/winrm_shared_options.rb +47 -47
- data/lib/chef/knife/wsman_endpoint.rb +44 -44
- data/lib/chef/knife/wsman_test.rb +96 -96
- data/lib/knife-windows/path_helper.rb +234 -234
- data/lib/knife-windows/version.rb +6 -6
- data/spec/assets/win_template_rendered_with_bootstrap_install_command.txt +217 -0
- data/spec/assets/win_template_rendered_without_bootstrap_install_command.txt +329 -0
- data/spec/assets/win_template_unrendered.txt +246 -0
- data/spec/functional/bootstrap_download_spec.rb +216 -140
- data/spec/spec_helper.rb +87 -72
- data/spec/unit/knife/bootstrap_options_spec.rb +146 -146
- data/spec/unit/knife/bootstrap_template_spec.rb +92 -92
- data/spec/unit/knife/bootstrap_windows_winrm_spec.rb +240 -161
- data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +151 -101
- data/spec/unit/knife/windows_cert_generate_spec.rb +90 -90
- data/spec/unit/knife/windows_cert_install_spec.rb +51 -51
- data/spec/unit/knife/windows_listener_create_spec.rb +76 -76
- data/spec/unit/knife/winrm_session_spec.rb +55 -46
- data/spec/unit/knife/winrm_spec.rb +504 -376
- data/spec/unit/knife/wsman_test_spec.rb +175 -175
- metadata +28 -8
@@ -1,101 +1,151 @@
|
|
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 "validation_key", :chef_gte_12_only do
|
29
|
-
before do
|
30
|
-
mock_bootstrap_context.instance_variable_set(:@config, Mash.new(:validation_key => "C:\\chef\\key.pem"))
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should return false if validation_key does not exist" do
|
34
|
-
allow(::File).to receive(:expand_path)
|
35
|
-
allow(::File).to receive(:exist?).and_return(false)
|
36
|
-
expect(mock_bootstrap_context.validation_key).to eq(false)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "latest_current_windows_chef_version_query" do
|
41
|
-
it "returns the major version of the current version of Chef" do
|
42
|
-
stub_const("Chef::VERSION", '11.1.2')
|
43
|
-
expect(mock_bootstrap_context.latest_current_windows_chef_version_query).to eq("&v=11")
|
44
|
-
end
|
45
|
-
|
46
|
-
it "does not add prerelease if the version of Chef installed is a prerelease" do
|
47
|
-
stub_const("Chef::VERSION", '42.0.1.alpha.1')
|
48
|
-
expect(mock_bootstrap_context.latest_current_windows_chef_version_query).not_to match(/&prerelease=true/)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "does add prerelease if the version specified to be installed is a prerelease" do
|
52
|
-
allow(mock_bootstrap_context).to receive(:knife_config).and_return(Mash.new(:bootstrap_version => "12.0.0.alpha.1"))
|
53
|
-
expect(mock_bootstrap_context.latest_current_windows_chef_version_query).to eq("&v=12.0.0.alpha.1&prerelease=true")
|
54
|
-
end
|
55
|
-
|
56
|
-
context "when the prerelease config option is set" do
|
57
|
-
before do
|
58
|
-
mock_bootstrap_context.instance_variable_set(:@config, Mash.new(:prerelease => true))
|
59
|
-
end
|
60
|
-
|
61
|
-
it "sets prerelease to true in the returned string" do
|
62
|
-
expect(mock_bootstrap_context.latest_current_windows_chef_version_query).to eq("&prerelease=true")
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe "msi_url" do
|
68
|
-
context "when config option is not set" do
|
69
|
-
before do
|
70
|
-
expect(mock_bootstrap_context).to receive(:latest_current_windows_chef_version_query).and_return("&v=something")
|
71
|
-
end
|
72
|
-
|
73
|
-
it "returns a chef.io msi url with minimal url parameters" do
|
74
|
-
reference_url = "https://www.chef.io/chef/download?p=windows&v=something"
|
75
|
-
expect(mock_bootstrap_context.msi_url).to eq(reference_url)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "returns a chef.io msi url with provided url parameters substituted" do
|
79
|
-
reference_url = "https://www.chef.io/chef/download?p=windows&pv=machine&m=arch&DownloadContext=ctx&v=something"
|
80
|
-
expect(mock_bootstrap_context.msi_url('machine', 'arch', 'ctx')).to eq(reference_url)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context "when msi_url config option is set" do
|
85
|
-
let(:custom_url) { "file://something" }
|
86
|
-
|
87
|
-
before do
|
88
|
-
mock_bootstrap_context.instance_variable_set(:@config, Mash.new(:msi_url => custom_url))
|
89
|
-
end
|
90
|
-
|
91
|
-
it "returns the overriden url" do
|
92
|
-
expect(mock_bootstrap_context.msi_url).to eq(custom_url)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "doesn't introduce any unnecessary query parameters if provided by the template" do
|
96
|
-
expect(mock_bootstrap_context.msi_url('machine', 'arch', 'ctx')).to eq(custom_url)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
|
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 "validation_key", :chef_gte_12_only do
|
29
|
+
before do
|
30
|
+
mock_bootstrap_context.instance_variable_set(:@config, Mash.new(:validation_key => "C:\\chef\\key.pem"))
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return false if validation_key does not exist" do
|
34
|
+
allow(::File).to receive(:expand_path)
|
35
|
+
allow(::File).to receive(:exist?).and_return(false)
|
36
|
+
expect(mock_bootstrap_context.validation_key).to eq(false)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "latest_current_windows_chef_version_query" do
|
41
|
+
it "returns the major version of the current version of Chef" do
|
42
|
+
stub_const("Chef::VERSION", '11.1.2')
|
43
|
+
expect(mock_bootstrap_context.latest_current_windows_chef_version_query).to eq("&v=11")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "does not add prerelease if the version of Chef installed is a prerelease" do
|
47
|
+
stub_const("Chef::VERSION", '42.0.1.alpha.1')
|
48
|
+
expect(mock_bootstrap_context.latest_current_windows_chef_version_query).not_to match(/&prerelease=true/)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "does add prerelease if the version specified to be installed is a prerelease" do
|
52
|
+
allow(mock_bootstrap_context).to receive(:knife_config).and_return(Mash.new(:bootstrap_version => "12.0.0.alpha.1"))
|
53
|
+
expect(mock_bootstrap_context.latest_current_windows_chef_version_query).to eq("&v=12.0.0.alpha.1&prerelease=true")
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when the prerelease config option is set" do
|
57
|
+
before do
|
58
|
+
mock_bootstrap_context.instance_variable_set(:@config, Mash.new(:prerelease => true))
|
59
|
+
end
|
60
|
+
|
61
|
+
it "sets prerelease to true in the returned string" do
|
62
|
+
expect(mock_bootstrap_context.latest_current_windows_chef_version_query).to eq("&prerelease=true")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "msi_url" do
|
68
|
+
context "when config option is not set" do
|
69
|
+
before do
|
70
|
+
expect(mock_bootstrap_context).to receive(:latest_current_windows_chef_version_query).and_return("&v=something")
|
71
|
+
end
|
72
|
+
|
73
|
+
it "returns a chef.io msi url with minimal url parameters" do
|
74
|
+
reference_url = "https://www.chef.io/chef/download?p=windows&v=something"
|
75
|
+
expect(mock_bootstrap_context.msi_url).to eq(reference_url)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "returns a chef.io msi url with provided url parameters substituted" do
|
79
|
+
reference_url = "https://www.chef.io/chef/download?p=windows&pv=machine&m=arch&DownloadContext=ctx&v=something"
|
80
|
+
expect(mock_bootstrap_context.msi_url('machine', 'arch', 'ctx')).to eq(reference_url)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "when msi_url config option is set" do
|
85
|
+
let(:custom_url) { "file://something" }
|
86
|
+
|
87
|
+
before do
|
88
|
+
mock_bootstrap_context.instance_variable_set(:@config, Mash.new(:msi_url => custom_url))
|
89
|
+
end
|
90
|
+
|
91
|
+
it "returns the overriden url" do
|
92
|
+
expect(mock_bootstrap_context.msi_url).to eq(custom_url)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "doesn't introduce any unnecessary query parameters if provided by the template" do
|
96
|
+
expect(mock_bootstrap_context.msi_url('machine', 'arch', 'ctx')).to eq(custom_url)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "bootstrap_install_command for bootstrap through WinRM" do
|
102
|
+
context "when bootstrap_install_command option is passed on CLI" do
|
103
|
+
let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new(['--bootstrap-install-command', 'chef-client']) }
|
104
|
+
before do
|
105
|
+
bootstrap.config[:bootstrap_install_command] = "chef-client"
|
106
|
+
end
|
107
|
+
|
108
|
+
it "sets the bootstrap_install_command option under Chef::Config::Knife object" do
|
109
|
+
expect(Chef::Config[:knife][:bootstrap_install_command]).to eq("chef-client")
|
110
|
+
end
|
111
|
+
|
112
|
+
after do
|
113
|
+
bootstrap.config.delete(:bootstrap_install_command)
|
114
|
+
Chef::Config[:knife].delete(:bootstrap_install_command)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "when bootstrap_install_command option is not passed on CLI" do
|
119
|
+
let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new([]) }
|
120
|
+
it "does not set the bootstrap_install_command option under Chef::Config::Knife object" do
|
121
|
+
expect(Chef::Config[:knife][:bootstrap_install_command]). to eq(nil)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "bootstrap_install_command for bootstrap through SSH" do
|
127
|
+
context "when bootstrap_install_command option is passed on CLI" do
|
128
|
+
let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new(['--bootstrap-install-command', 'chef-client']) }
|
129
|
+
before do
|
130
|
+
bootstrap.config[:bootstrap_install_command] = "chef-client"
|
131
|
+
end
|
132
|
+
|
133
|
+
it "sets the bootstrap_install_command option under Chef::Config::Knife object" do
|
134
|
+
expect(Chef::Config[:knife][:bootstrap_install_command]).to eq("chef-client")
|
135
|
+
end
|
136
|
+
|
137
|
+
after do
|
138
|
+
bootstrap.config.delete(:bootstrap_install_command)
|
139
|
+
Chef::Config[:knife].delete(:bootstrap_install_command)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context "when bootstrap_install_command option is not passed on CLI" do
|
144
|
+
let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new([]) }
|
145
|
+
it "does not set the bootstrap_install_command option under Chef::Config::Knife object" do
|
146
|
+
expect(Chef::Config[:knife][:bootstrap_install_command]). to eq(nil)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
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 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,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 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
|