diff options
author | Tyler Ball <tball@chef.io> | 2019-05-06 12:46:04 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-06 12:46:04 -0600 |
commit | 3ba19c97144832d44a1e77c3183b8b8c9b46f004 (patch) | |
tree | 4f66fc2517f70e573675128e5e75f1e2a03226ef /spec | |
parent | 12623146e3f64540b81a1a50dfdcf502740c3151 (diff) | |
parent | 0c6e3b9f0b45501d3835537bf8ed95ddd779375f (diff) | |
download | chef-3ba19c97144832d44a1e77c3183b8b8c9b46f004.tar.gz |
Merge pull request #8354 from chef/license_acceptance
Add logic to require acceptannce of the Chef license to run the client
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/application/knife_spec.rb | 6 | ||||
-rw-r--r-- | spec/unit/application_spec.rb | 7 | ||||
-rw-r--r-- | spec/unit/knife/bootstrap_spec.rb | 11 | ||||
-rw-r--r-- | spec/unit/knife/core/windows_bootstrap_context_spec.rb | 6 |
4 files changed, 25 insertions, 5 deletions
diff --git a/spec/unit/application/knife_spec.rb b/spec/unit/application/knife_spec.rb index 8a574b4d0f..f8f5560597 100644 --- a/spec/unit/application/knife_spec.rb +++ b/spec/unit/application/knife_spec.rb @@ -75,11 +75,7 @@ describe Chef::Application::Knife do expect(@knife).to receive(:exit).with(0) @knife.run end - if windows? - expect(Chef::Config[:color]).to be_truthy - else - expect(Chef::Config[:color]).to be_truthy - end + expect(Chef::Config[:color]).to be_truthy end context "when given fips flags" do diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb index e76e21bddc..10dff0e250 100644 --- a/spec/unit/application_spec.rb +++ b/spec/unit/application_spec.rb @@ -87,6 +87,13 @@ describe Chef::Application do @app.run end + describe "when enforce_license is set to true" do + it "should check the license acceptance" do + expect(@app).to receive(:check_license_acceptance) + @app.run(enforce_license: true) + end + end + it "should run the actual application" do expect(@app).to receive(:run_application).and_return(true) @app.run diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index 4261a3a166..948fc5b574 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -40,6 +40,7 @@ describe Chef::Knife::Bootstrap do let(:knife) do Chef::Log.logger = Logger.new(StringIO.new) Chef::Config[:knife][:bootstrap_template] = bootstrap_template unless bootstrap_template.nil? + expect(LicenseAcceptance::Acceptor).to receive(:check_and_persist!) k = Chef::Knife::Bootstrap.new(bootstrap_cli_options) allow(k.ui).to receive(:stderr).and_return(stderr) @@ -49,6 +50,15 @@ describe Chef::Knife::Bootstrap do k end + it "purposefully fails to prevent Chef Infra from promoting unstable -> current" do + expect(0).to eq(1) + end + + it "fails when LicenseAcceptance fails" do + expect(LicenseAcceptance::Acceptor).to receive(:check_and_persist!).and_raise("foo") + expect { k = Chef::Knife::Bootstrap.new(bootstrap_cli_options) }.to raise_error("foo") + end + context "#bootstrap_template" do it "should default to chef-full" do expect(knife.bootstrap_template).to be_a_kind_of(String) @@ -323,6 +333,7 @@ describe Chef::Knife::Bootstrap do describe "specifying no_proxy with various entries" do subject(:knife) do + expect(LicenseAcceptance::Acceptor).to receive(:check_and_persist!) k = described_class.new Chef::Config[:knife][:bootstrap_template] = template_file allow(k).to receive(:connection).and_return connection diff --git a/spec/unit/knife/core/windows_bootstrap_context_spec.rb b/spec/unit/knife/core/windows_bootstrap_context_spec.rb index 7bc73c113a..561e43eefc 100644 --- a/spec/unit/knife/core/windows_bootstrap_context_spec.rb +++ b/spec/unit/knife/core/windows_bootstrap_context_spec.rb @@ -221,6 +221,8 @@ describe Chef::Knife::Core::WindowsBootstrapContext do let(:bootstrap) { Chef::Knife::Bootstrap.new(["--bootstrap-install-command", "chef-client"]) } before do bootstrap.config[:bootstrap_install_command] = "chef-client" + @old_env = ENV["CHEF_LICENSE"] + ENV["CHEF_LICENSE"] = "accept" end it "sets the bootstrap_install_command option under Chef::Config::Knife object" do @@ -230,6 +232,7 @@ describe Chef::Knife::Core::WindowsBootstrapContext do after do bootstrap.config.delete(:bootstrap_install_command) Chef::Config[:knife].delete(:bootstrap_install_command) + ENV["CHEF_LICENSE"] = @old_env end end @@ -246,6 +249,8 @@ describe Chef::Knife::Core::WindowsBootstrapContext do let(:bootstrap) { Chef::Knife::Bootstrap.new(["--bootstrap-install-command", "chef-client"]) } before do bootstrap.config[:bootstrap_install_command] = "chef-client" + @old_env = ENV["CHEF_LICENSE"] + ENV["CHEF_LICENSE"] = "accept" end it "sets the bootstrap_install_command option under Chef::Config::Knife object" do @@ -255,6 +260,7 @@ describe Chef::Knife::Core::WindowsBootstrapContext do after do bootstrap.config.delete(:bootstrap_install_command) Chef::Config[:knife].delete(:bootstrap_install_command) + ENV["CHEF_LICENSE"] = @old_env end end |