2019-06-11 22:24:35 +00:00
|
|
|
require "functional/helper"
|
|
|
|
require "tmpdir"
|
|
|
|
require "yaml"
|
2019-02-04 22:19:05 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "The license acceptance mechanism" do
|
2019-02-15 15:50:59 +00:00
|
|
|
include FunctionalHelper
|
2019-02-04 22:19:05 +00:00
|
|
|
|
2019-10-18 09:06:35 +00:00
|
|
|
# TODO/NOTE: do not add parallelize_me! here. Blows up inspec_json_profile_test.rb
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the license has not been accepted" do
|
|
|
|
describe "when the user passes the --chef-license accept flag" do
|
|
|
|
it "should silently work normally" do
|
2019-05-30 18:17:19 +00:00
|
|
|
without_license do
|
|
|
|
Dir.mktmpdir do |tmp_home|
|
2019-06-11 22:24:35 +00:00
|
|
|
run_result = run_inspec_process("shell -c platform.family --chef-license accept", env: { "HOME" => tmp_home })
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(run_result.stdout).wont_include "Chef License Acceptance" # --chef-license should not mention accepting the license
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(run_result.stderr).must_equal ""
|
2019-04-11 18:20:41 +00:00
|
|
|
|
2019-07-23 01:44:43 +00:00
|
|
|
assert_exit_code 0, run_result
|
2019-05-30 18:17:19 +00:00
|
|
|
end
|
2019-02-04 22:38:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "should write a YAML file" do
|
2019-05-30 18:17:19 +00:00
|
|
|
without_license do
|
|
|
|
Dir.mktmpdir do |tmp_home|
|
2019-10-18 09:06:35 +00:00
|
|
|
license_persist_path = "#{tmp_home}/.chef/accepted_licenses/inspec"
|
2019-02-15 15:50:59 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(File.exist?(license_persist_path)).must_equal false # Sanity check
|
2019-05-31 21:59:06 +00:00
|
|
|
run_inspec_process("shell -c platform.family --chef-license accept", env: { "HOME" => tmp_home })
|
2019-08-06 22:39:47 +00:00
|
|
|
|
|
|
|
# depends on if test is run by root or not
|
|
|
|
root_license_path = FunctionalHelper::ROOT_LICENSE_PATH
|
|
|
|
license_persist_path, = Dir[license_persist_path, root_license_path]
|
|
|
|
|
2019-10-18 09:06:35 +00:00
|
|
|
_(license_persist_path).wont_be_nil "can't find license file"
|
2019-09-30 22:31:55 +00:00
|
|
|
_(File.exist?(license_persist_path)).must_equal true
|
2019-02-15 15:50:59 +00:00
|
|
|
|
2019-05-30 18:17:19 +00:00
|
|
|
license_persist_contents = YAML.load(File.read(license_persist_path))
|
2019-09-30 22:31:55 +00:00
|
|
|
_(license_persist_contents.keys).must_include "accepting_product"
|
|
|
|
_(license_persist_contents["accepting_product"]).must_equal "inspec"
|
2019-05-30 18:17:19 +00:00
|
|
|
end
|
2019-02-04 22:38:20 +00:00
|
|
|
end
|
|
|
|
end
|
2019-02-04 22:19:05 +00:00
|
|
|
end
|
|
|
|
|
2019-04-11 17:11:11 +00:00
|
|
|
# Since the license-acceptance library detects TTYs, and changes behavior
|
|
|
|
# if not found, we can't test interactive acceptance anymore
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when no mechanism is used to accept the license and we are non-interactive" do
|
|
|
|
it "should exit ASAP with code 172" do
|
2019-05-30 18:17:19 +00:00
|
|
|
without_license do
|
|
|
|
Dir.mktmpdir do |tmp_home|
|
2019-06-11 22:24:35 +00:00
|
|
|
run_result = run_inspec_process("shell -c platform.family", env: { "HOME" => tmp_home })
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-05-30 18:17:19 +00:00
|
|
|
# [2019-04-11T11:06:00-04:00] ERROR: InSpec cannot execute without accepting the license
|
2019-09-30 22:31:55 +00:00
|
|
|
_(run_result.stdout).must_include "cannot execute"
|
|
|
|
_(run_result.stdout).must_include "the license"
|
|
|
|
_(run_result.stdout).must_include "ERROR" # From failure message
|
2019-07-23 01:44:43 +00:00
|
|
|
|
|
|
|
assert_exit_code 172, run_result
|
2019-05-30 18:17:19 +00:00
|
|
|
end
|
2019-02-04 23:05:29 +00:00
|
|
|
end
|
|
|
|
end
|
2019-02-04 22:19:05 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when a command is used that should not be gated on licensure" do
|
2019-02-15 15:50:59 +00:00
|
|
|
[
|
2019-06-11 22:24:35 +00:00
|
|
|
"-h", "--help", "help", "", # Empty invocation is treated as `inspec help`
|
2019-07-09 00:20:30 +00:00
|
|
|
"-v", "--version", "version"
|
2019-02-15 15:50:59 +00:00
|
|
|
].each do |ungated_invocation|
|
2019-02-04 23:10:40 +00:00
|
|
|
it "should not challenge for a license when running `inspec #{ungated_invocation}`" do
|
2019-02-15 15:50:59 +00:00
|
|
|
Dir.mktmpdir do |tmp_home|
|
2019-06-11 22:24:35 +00:00
|
|
|
run_result = run_inspec_process(ungated_invocation, env: { "HOME" => tmp_home })
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(run_result.stdout).wont_include "Chef License Acceptance"
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(run_result.stderr).must_equal ""
|
2019-07-23 01:44:43 +00:00
|
|
|
|
|
|
|
assert_exit_code 0, run_result
|
2019-02-04 23:10:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-02-04 22:38:20 +00:00
|
|
|
end
|
2019-02-04 22:19:05 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the license has already been accepted" do
|
|
|
|
describe "when the license was accepted by touching a blank file" do
|
|
|
|
it "should silently work normally" do
|
2019-02-15 15:50:59 +00:00
|
|
|
Dir.mktmpdir do |tmp_home|
|
2019-06-11 22:24:35 +00:00
|
|
|
license_persist_dir = File.join(tmp_home, ".chef", "accepted_licenses")
|
|
|
|
license_persist_path = File.join(tmp_home, ".chef", "accepted_licenses", "inspec")
|
2019-02-15 15:50:59 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(File.exist?(license_persist_path)).must_equal false # Sanity check
|
2019-02-04 22:47:04 +00:00
|
|
|
FileUtils.mkdir_p(license_persist_dir)
|
|
|
|
FileUtils.touch(license_persist_path)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(File.exist?(license_persist_path)).must_equal true # Sanity check
|
2019-02-04 22:47:04 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
run_result = run_inspec_process("shell -c platform.family", env: { "HOME" => tmp_home })
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(run_result.stdout).wont_include "Chef License Acceptance"
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(run_result.stderr).must_equal ""
|
2019-07-23 01:44:43 +00:00
|
|
|
|
|
|
|
assert_exit_code 0, run_result
|
2019-02-04 22:47:04 +00:00
|
|
|
end
|
|
|
|
end
|
2019-02-04 22:19:05 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the license persistance file is a YAML file" do
|
|
|
|
it "should silently work normally" do
|
2019-02-15 15:50:59 +00:00
|
|
|
Dir.mktmpdir do |tmp_home|
|
2019-06-11 22:24:35 +00:00
|
|
|
license_persist_dir = File.join(tmp_home, ".chef", "accepted_licenses")
|
|
|
|
license_persist_path = File.join(tmp_home, ".chef", "accepted_licenses", "inspec")
|
2019-02-15 15:50:59 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(File.exist?(license_persist_path)).must_equal false # Sanity check
|
2019-02-04 22:47:04 +00:00
|
|
|
FileUtils.mkdir_p(license_persist_dir)
|
|
|
|
File.write(license_persist_path, <<~EOY)
|
2019-06-11 22:24:35 +00:00
|
|
|
---
|
|
|
|
name: inspec
|
|
|
|
date_accepted: '1979-08-04T16:36:53-05:00'
|
|
|
|
accepting_product: inspec
|
|
|
|
accepting_product_version: 1.2.3
|
|
|
|
user: someone
|
|
|
|
file_format: 1
|
2019-02-04 22:47:04 +00:00
|
|
|
EOY
|
2019-09-30 22:31:55 +00:00
|
|
|
_(File.exist?(license_persist_path)).must_equal true # Sanity check
|
2019-02-04 22:47:04 +00:00
|
|
|
|
2019-10-18 09:06:35 +00:00
|
|
|
skip_windows! # exit code 1
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
run_result = run_inspec_process("shell -c platform.family", env: { "HOME" => tmp_home })
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(run_result.stdout).wont_include "Chef License Acceptance"
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(run_result.stderr).must_equal ""
|
2019-07-23 01:44:43 +00:00
|
|
|
|
|
|
|
assert_exit_code 0, run_result
|
2019-02-04 22:47:04 +00:00
|
|
|
end
|
|
|
|
end
|
2019-02-04 22:19:05 +00:00
|
|
|
end
|
|
|
|
end
|
2019-05-30 18:17:19 +00:00
|
|
|
end
|