summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/application/base.rb2
-rw-r--r--spec/integration/client/client_spec.rb31
-rw-r--r--spec/unit/application/base_spec.rb40
3 files changed, 72 insertions, 1 deletions
diff --git a/lib/chef/application/base.rb b/lib/chef/application/base.rb
index fc8511a04b..770b06e9d0 100644
--- a/lib/chef/application/base.rb
+++ b/lib/chef/application/base.rb
@@ -254,7 +254,7 @@ class Chef::Application::Base < Chef::Application
short: "-K KEY_FILE",
long: "--validation_key KEY_FILE",
description: "Set the validation key file location, used for registering new clients.",
- proc: nil
+ proc: lambda { |argument| File.expand_path(argument) }
option :client_key,
short: "-k KEY_FILE",
diff --git a/spec/integration/client/client_spec.rb b/spec/integration/client/client_spec.rb
index ecd8ec5bb5..adcffec715 100644
--- a/spec/integration/client/client_spec.rb
+++ b/spec/integration/client/client_spec.rb
@@ -48,6 +48,37 @@ describe "chef-client" do
let(:chef_client) { "bundle exec #{ChefUtils::Dist::Infra::CLIENT} --minimal-ohai" }
let(:chef_solo) { "bundle exec #{ChefUtils::Dist::Solo::EXEC} --legacy-mode --minimal-ohai" }
+ context "when validation.pem in current Directory" do
+ let(:validation_path) { "" }
+
+ before do
+ tempfile = Tempfile.new(validation_path)
+ tempfile.write "string"
+ tempfile.close
+ @path = tempfile.path
+ Chef::Config.validation_key = @path
+
+ file "config/client.rb", <<~EOM
+ local_mode true
+ cookbook_path "#{path_to("cookbooks")}"
+ EOM
+ end
+
+ it "should find validation.pem successfully in current dir" do
+ validation_path = "validation.pem"
+ shell_out!("#{chef_client} -c \"#{path_to("config/client.rb")}\" -K #{@path} ", cwd: chef_dir)
+ end
+
+ it "should find validation.pem successfully in current dir" do
+ validation_path = "/tmp/validation.pem"
+ shell_out!("#{chef_client} -c \"#{path_to("config/client.rb")}\" -K #{@path} ", cwd: chef_dir)
+ end
+
+ it "should find validation.pem successfully in default directory" do
+ shell_out!("#{chef_client} -c \"#{path_to("config/client.rb")}\" ", cwd: chef_dir)
+ end
+ end
+
when_the_repository "has a cookbook with a no-op recipe" do
before { file "cookbooks/x/recipes/default.rb", "" }
diff --git a/spec/unit/application/base_spec.rb b/spec/unit/application/base_spec.rb
new file mode 100644
index 0000000000..ce90464603
--- /dev/null
+++ b/spec/unit/application/base_spec.rb
@@ -0,0 +1,40 @@
+require "spec_helper"
+
+describe Chef::Application::Base, "setup_application" do
+ let(:validation_path) { "" }
+
+ context "when validation key is supplied" do
+ before do
+ @app = Chef::Application::Base.new
+ tempfile = Tempfile.new(validation_path)
+ tempfile.write "string"
+ tempfile.close
+ @path = tempfile.path
+ Chef::Config.validation_key = @path
+ end
+
+ context "when key is in current directory" do
+ it "should find with full path of validation_key" do
+ validation_path = "validation.pem"
+ expect(Chef::Config.validation_key).to eql(@path)
+ end
+ end
+
+ context "when path is given" do
+ validation_path = "/tmp/validation.pem"
+ it "should find validation_key" do
+ expect(Chef::Config.validation_key).to eql(@path)
+ end
+ end
+ end
+
+ context "when validation key is not supplied" do
+ it "should return default path for validation_key" do
+ if windows?
+ expect(Chef::Config.validation_key).to eql("C:\\chef\\validation.pem")
+ else
+ expect(Chef::Config.validation_key).to eql("/etc/chef/validation.pem")
+ end
+ end
+ end
+end