2019-02-04 22:19:05 +00:00
|
|
|
require 'functional/helper'
|
2019-02-04 22:38:20 +00:00
|
|
|
require 'tmpdir'
|
|
|
|
require 'yaml'
|
2019-02-04 22:19:05 +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-02-04 22:38:20 +00:00
|
|
|
describe 'when the license has not been accepted' do
|
2019-02-04 22:19:05 +00:00
|
|
|
describe 'when the user passes the --accept-license flag' do
|
2019-02-04 22:38:20 +00:00
|
|
|
it 'should silently work normally' do
|
2019-02-15 15:50:59 +00:00
|
|
|
Dir.mktmpdir do |tmp_home|
|
|
|
|
run_result = run_inspec_process('shell -c platform.family --accept-license', env: { 'HOME' => tmp_home })
|
2019-02-04 22:38:20 +00:00
|
|
|
run_result.stdout.wont_include 'Chef License Acceptance' # --accept-license should not mention accepting the license
|
|
|
|
run_result.stderr.must_equal ''
|
|
|
|
run_result.exit_status.must_equal 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should write a YAML file' do
|
2019-02-15 15:50:59 +00:00
|
|
|
Dir.mktmpdir do |tmp_home|
|
|
|
|
license_persist_path = File.join(tmp_home, '.chef', 'accepted_licenses', 'inspec')
|
|
|
|
|
2019-02-04 22:38:20 +00:00
|
|
|
File.exist?(license_persist_path).must_equal false # Sanity check
|
2019-02-15 15:50:59 +00:00
|
|
|
run_result = run_inspec_process('shell -c platform.family --accept-license', env: { 'HOME' => tmp_home })
|
2019-02-04 22:38:20 +00:00
|
|
|
File.exist?(license_persist_path).must_equal true
|
2019-02-15 15:50:59 +00:00
|
|
|
|
2019-02-04 22:38:20 +00:00
|
|
|
license_persist_contents = YAML.load(File.read(license_persist_path))
|
|
|
|
license_persist_contents.keys.must_include 'accepting_product'
|
|
|
|
license_persist_contents['accepting_product'].must_equal 'inspec'
|
|
|
|
end
|
|
|
|
end
|
2019-02-04 22:19:05 +00:00
|
|
|
end
|
|
|
|
|
2019-02-04 23:05:29 +00:00
|
|
|
# TODO: find a 'yes yes | ' equivalent in powershell
|
2019-02-04 22:55:42 +00:00
|
|
|
unless windows?
|
|
|
|
describe 'when the user answers yes to the interactive challenge' do
|
|
|
|
it 'should silently work normally' do
|
2019-02-15 15:50:59 +00:00
|
|
|
Dir.mktmpdir do |tmp_home|
|
|
|
|
run_result = run_inspec_process('shell -c platform.family', env: { 'HOME' => tmp_home }, prefix: 'yes yes | ')
|
2019-02-04 22:55:42 +00:00
|
|
|
run_result.stdout.must_include 'Chef License Acceptance'
|
|
|
|
run_result.stderr.must_equal ''
|
|
|
|
run_result.exit_status.must_equal 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should write a YAML file' do
|
2019-02-15 15:50:59 +00:00
|
|
|
Dir.mktmpdir do |tmp_home|
|
|
|
|
license_persist_path = File.join(tmp_home, '.chef', 'accepted_licenses', 'inspec')
|
|
|
|
|
2019-02-04 22:55:42 +00:00
|
|
|
File.exist?(license_persist_path).must_equal false # Sanity check
|
2019-02-15 15:50:59 +00:00
|
|
|
run_result = run_inspec_process('shell -c platform.family', env: { 'HOME' => tmp_home }, prefix: 'yes yes | ')
|
2019-02-04 22:55:42 +00:00
|
|
|
File.exist?(license_persist_path).must_equal true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'Should not prompt on subsequent runs' do
|
2019-02-15 15:50:59 +00:00
|
|
|
Dir.mktmpdir do |tmp_home|
|
|
|
|
run_result = run_inspec_process('shell -c platform.family', env: { 'HOME' => tmp_home }, prefix: 'yes yes | ')
|
|
|
|
second_run_result = run_inspec_process('shell -c platform.family', env: { 'HOME' => tmp_home })
|
2019-02-04 22:55:42 +00:00
|
|
|
|
|
|
|
second_run_result.stdout.wont_include 'Chef License Acceptance'
|
|
|
|
second_run_result.stderr.must_equal ''
|
|
|
|
second_run_result.exit_status.must_equal 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-02-04 22:19:05 +00:00
|
|
|
end
|
|
|
|
|
2019-02-04 23:05:29 +00:00
|
|
|
# TODO: find a 'yes no | ' equivalent in powershell
|
|
|
|
unless windows?
|
|
|
|
describe 'when the user answers no to the interactive challenge' do
|
|
|
|
it 'should prompt twice and fail with a special code' do
|
2019-02-15 15:50:59 +00:00
|
|
|
Dir.mktmpdir do |tmp_home|
|
|
|
|
run_result = run_inspec_process('shell -c platform.family', env: { 'HOME' => tmp_home }, prefix: 'yes no | ')
|
|
|
|
|
2019-02-04 23:05:29 +00:00
|
|
|
run_result.stdout.must_include 'Chef License Acceptance'
|
2019-02-15 15:50:59 +00:00
|
|
|
run_result.stdout.must_include 'License that need accepting' # From first challenge
|
|
|
|
run_result.stdout.must_include 'If you do not accept this license' # From second challenge
|
|
|
|
run_result.stdout.must_include 'ERROR' # From failure message
|
2019-03-06 17:50:52 +00:00
|
|
|
run_result.exit_status.must_equal 172
|
2019-02-04 23:05:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-02-04 22:19:05 +00:00
|
|
|
end
|
|
|
|
|
2019-02-04 23:10:40 +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-02-15 16:05:49 +00:00
|
|
|
'-h', '--help', 'help', '', # Empty invocation is treated as `inspec help`
|
2019-02-15 15:55:52 +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|
|
|
|
|
run_result = run_inspec_process(ungated_invocation, env: { 'HOME' => tmp_home })
|
2019-02-04 23:10:40 +00:00
|
|
|
run_result.stdout.wont_include 'Chef License Acceptance'
|
|
|
|
run_result.stderr.must_equal ''
|
|
|
|
run_result.exit_status.must_equal 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-02-04 22:38:20 +00:00
|
|
|
end
|
2019-02-04 22:19:05 +00:00
|
|
|
|
|
|
|
describe 'when the license has already been accepted' do
|
|
|
|
describe 'when the license was accepted by touching a blank file' do
|
2019-02-04 22:47:04 +00:00
|
|
|
it 'should silently work normally' do
|
2019-02-15 15:50:59 +00:00
|
|
|
Dir.mktmpdir do |tmp_home|
|
|
|
|
license_persist_dir = File.join(tmp_home, '.chef', 'accepted_licenses')
|
|
|
|
license_persist_path = File.join(tmp_home, '.chef', 'accepted_licenses', 'inspec')
|
|
|
|
|
2019-02-04 22:47:04 +00:00
|
|
|
File.exist?(license_persist_path).must_equal false # Sanity check
|
|
|
|
FileUtils.mkdir_p(license_persist_dir)
|
|
|
|
FileUtils.touch(license_persist_path)
|
|
|
|
File.exist?(license_persist_path).must_equal true # Sanity check
|
|
|
|
|
2019-02-15 15:50:59 +00:00
|
|
|
run_result = run_inspec_process('shell -c platform.family', env: { 'HOME' => tmp_home })
|
2019-02-04 22:47:04 +00:00
|
|
|
run_result.stdout.wont_include 'Chef License Acceptance'
|
|
|
|
run_result.stderr.must_equal ''
|
|
|
|
run_result.exit_status.must_equal 0
|
|
|
|
end
|
|
|
|
end
|
2019-02-04 22:19:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when the license persistance file is a YAML file' do
|
2019-02-04 22:47:04 +00:00
|
|
|
it 'should silently work normally' do
|
2019-02-15 15:50:59 +00:00
|
|
|
Dir.mktmpdir do |tmp_home|
|
|
|
|
license_persist_dir = File.join(tmp_home, '.chef', 'accepted_licenses')
|
|
|
|
license_persist_path = File.join(tmp_home, '.chef', 'accepted_licenses', 'inspec')
|
|
|
|
|
2019-02-04 22:47:04 +00:00
|
|
|
File.exist?(license_persist_path).must_equal false # Sanity check
|
|
|
|
FileUtils.mkdir_p(license_persist_dir)
|
|
|
|
File.write(license_persist_path, <<~EOY)
|
|
|
|
---
|
|
|
|
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
|
|
|
|
EOY
|
|
|
|
File.exist?(license_persist_path).must_equal true # Sanity check
|
|
|
|
|
2019-02-15 15:50:59 +00:00
|
|
|
run_result = run_inspec_process('shell -c platform.family', env: { 'HOME' => tmp_home })
|
2019-02-04 22:47:04 +00:00
|
|
|
run_result.stdout.wont_include 'Chef License Acceptance'
|
|
|
|
run_result.stderr.must_equal ''
|
|
|
|
run_result.exit_status.must_equal 0
|
|
|
|
end
|
|
|
|
end
|
2019-02-04 22:19:05 +00:00
|
|
|
end
|
|
|
|
end
|
2019-02-04 22:38:20 +00:00
|
|
|
end
|