2016-03-25 00:31:19 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# author: Dominik Richter
|
|
|
|
# author: Christoph Hartmann
|
|
|
|
require 'functional/helper'
|
|
|
|
|
|
|
|
describe 'example inheritance profile' do
|
|
|
|
include FunctionalHelper
|
|
|
|
let(:path) { File.join(examples_path, 'inheritance') }
|
2019-02-12 23:02:54 +00:00
|
|
|
let(:input_file) { File.join(examples_path, 'profile-attribute.yml') } # TODO rename attributes in examples
|
2016-03-25 00:31:19 +00:00
|
|
|
|
|
|
|
it 'check succeeds with --profiles-path' do
|
|
|
|
out = inspec('check ' + path + ' --profiles-path ' + examples_path)
|
|
|
|
out.stderr.must_equal ''
|
2016-09-07 11:10:35 +00:00
|
|
|
out.stdout.must_match(/Valid.*true/)
|
2016-03-25 00:31:19 +00:00
|
|
|
out.exit_status.must_equal 0
|
|
|
|
end
|
|
|
|
|
2016-08-11 15:34:27 +00:00
|
|
|
it 'check succeeds without --profiles-path using inspec.yml' do
|
2018-11-02 16:52:54 +00:00
|
|
|
prepare_examples('inheritance') do |dir|
|
|
|
|
out = inspec('vendor ' + dir)
|
|
|
|
out = inspec('check ' + dir)
|
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.stdout.must_match(/Valid.*true/)
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
end
|
2016-08-11 15:34:27 +00:00
|
|
|
end
|
|
|
|
|
2016-03-25 00:31:19 +00:00
|
|
|
it 'archive is successful with --profiles-path' do
|
2018-11-02 16:52:54 +00:00
|
|
|
prepare_examples('inheritance') do |dir|
|
|
|
|
out = inspec('archive ' + dir + ' --output ' + dst.path + ' --profiles-path ' + examples_path)
|
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.stdout.must_include 'Generate archive '+ dst.path
|
|
|
|
out.stdout.must_include 'Finished archive generation.'
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
File.exist?(dst.path).must_equal true
|
|
|
|
end
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|
|
|
|
|
2016-08-11 15:34:27 +00:00
|
|
|
it 'archive is successful without --profiles-path using inspec.yml' do
|
2018-11-02 16:52:54 +00:00
|
|
|
prepare_examples('inheritance') do |dir|
|
|
|
|
out = inspec('archive ' + dir + ' --output ' + dst.path)
|
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.stdout.must_include 'Generate archive ' + dst.path
|
|
|
|
out.stdout.must_include 'Finished archive generation.'
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
File.exist?(dst.path).must_equal true
|
|
|
|
end
|
2016-08-11 15:34:27 +00:00
|
|
|
end
|
|
|
|
|
2016-03-25 00:31:19 +00:00
|
|
|
it 'read the profile json with --profiles-path' do
|
|
|
|
out = inspec('json ' + path + ' --profiles-path '+examples_path)
|
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
s = out.stdout
|
|
|
|
hm = JSON.load(s)
|
|
|
|
hm['name'].must_equal 'inheritance'
|
2016-11-04 17:01:17 +00:00
|
|
|
hm['controls'].length.must_equal 5
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|
2016-08-11 15:34:27 +00:00
|
|
|
|
|
|
|
it 'read the profile json without --profiles-path using inspec.yml' do
|
|
|
|
out = inspec('json ' + path)
|
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
s = out.stdout
|
|
|
|
hm = JSON.load(s)
|
|
|
|
hm['name'].must_equal 'inheritance'
|
2016-11-04 17:01:17 +00:00
|
|
|
hm['controls'].length.must_equal 5
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can execute a profile inheritance' do
|
2019-02-12 23:02:54 +00:00
|
|
|
out = inspec('exec ' + path + ' --reporter json --no-create-lockfile --input-file ' + input_file)
|
2016-11-04 17:01:17 +00:00
|
|
|
out.stderr.must_equal ''
|
2018-02-14 16:54:20 +00:00
|
|
|
out.exit_status.must_equal 101
|
2016-11-04 17:01:17 +00:00
|
|
|
JSON.load(out.stdout).must_be_kind_of Hash
|
2016-08-11 15:34:27 +00:00
|
|
|
end
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|