summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsnehaldwivedi <sdwivedi@msystechnologies.com>2021-10-28 02:18:01 -0700
committersnehaldwivedi <sdwivedi@msystechnologies.com>2021-11-01 23:56:51 -0700
commite677f67853fde238206c2f96b3770fc3af81f4e3 (patch)
treebc54f58f469ede79f2ce5f88274cf5841f388851
parent9110f7e9b1dc6e9d9406cc148fb3becc90d2abd7 (diff)
downloadchef-e677f67853fde238206c2f96b3770fc3af81f4e3.tar.gz
Moved rspec for base.rb and added integration test
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
-rw-r--r--spec/integration/client/client_spec.rb31
-rw-r--r--spec/unit/application/base_spec.rb36
2 files changed, 67 insertions, 0 deletions
diff --git a/spec/integration/client/client_spec.rb b/spec/integration/client/client_spec.rb
index b23935f317..54503a6d67 100644
--- a/spec/integration/client/client_spec.rb
+++ b/spec/integration/client/client_spec.rb
@@ -49,6 +49,37 @@ describe "chef-client" do
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 /etc/chef/ directory" do
+ shell_out!("#{chef_client} -c \"#{path_to("config/client.rb")}\" ", cwd: chef_dir)
+ end
+ end
+
+ context "when validation.pem in current Directory" do
before do
file "mykey.pem", <<~EOM
-----BEGIN RSA PRIVATE KEY-----
diff --git a/spec/unit/application/base_spec.rb b/spec/unit/application/base_spec.rb
new file mode 100644
index 0000000000..a3a794871d
--- /dev/null
+++ b/spec/unit/application/base_spec.rb
@@ -0,0 +1,36 @@
+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 full path for validation_key" do
+ expect(Chef::Config.validation_key).to eql("/etc/chef/validation.pem")
+ end
+ end
+end