From ed44d58632c02744ce02bcc6af504e4e3c802f1f Mon Sep 17 00:00:00 2001 From: Jay Mundrawala Date: Wed, 27 Jan 2016 17:44:12 -0800 Subject: Allow use of command line fips switch for knife This somewhat worked before. However, it was just for knife bootstrap. It also didn't support --no-fips in the case where it was in your knife.rb and you decided that you didn't want to use fips for that one call. The assumption here is fips mode you run knife with is the fips mode the node will get. This has the nice property that validatorless bootstraps will talk to the chef server in fips mode if the node is requested to be in fips mode. --- spec/unit/application/knife_spec.rb | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'spec/unit/application') diff --git a/spec/unit/application/knife_spec.rb b/spec/unit/application/knife_spec.rb index 163489110f..c6c3c4d12c 100644 --- a/spec/unit/application/knife_spec.rb +++ b/spec/unit/application/knife_spec.rb @@ -82,6 +82,58 @@ describe Chef::Application::Knife do end end + context "when given fips flags" do + context "when Chef::Config[:fips]=false" do + before do + # This is required because the chef-fips pipeline does + # has a default value of true for fips + Chef::Config[:fips] = false + end + + it "does not initialize fips mode when no flags are passed" do + with_argv(*%w{noop knife command}) do + expect(@knife).to receive(:exit).with(0) + expect(OpenSSL).not_to receive(:'fips_mode=') + @knife.run + expect(Chef::Config[:fips]).to eq(false) + end + end + + it "overwrites the Chef::Config value when passed --fips" do + with_argv(*%w{noop knife command --fips}) do + expect(@knife).to receive(:exit).with(0) + expect(OpenSSL).to receive(:'fips_mode=').with(true) + @knife.run + expect(Chef::Config[:fips]).to eq(true) + end + end + end + + context "when Chef::Config[:fips]=true" do + before do + Chef::Config[:fips] = true + end + + it "initializes fips mode when passed --fips" do + with_argv(*%w{noop knife command --fips}) do + expect(@knife).to receive(:exit).with(0) + expect(OpenSSL).to receive(:'fips_mode=').with(true) + @knife.run + expect(Chef::Config[:fips]).to eq(true) + end + end + + it "overwrites the Chef::Config value when passed --no-fips" do + with_argv(*%w{noop knife command --no-fips}) do + expect(@knife).to receive(:exit).with(0) + expect(OpenSSL).not_to receive(:'fips_mode=') + @knife.run + expect(Chef::Config[:fips]).to eq(false) + end + end + end + end + describe "when given a path to the client key" do it "expands a relative path relative to the CWD" do relative_path = ".chef/client.pem" -- cgit v1.2.1