2018-09-25 19:53:26 +00:00
|
|
|
# This file tests the audit validation which runs as part of the
|
|
|
|
# chef-client process. This is setup to export to a json file in the .kitchen.yml
|
|
|
|
#
|
|
|
|
# For more info please see docs/dev/integratin_test.md
|
|
|
|
|
|
|
|
control 'Test audit cookbook json exist' do
|
|
|
|
describe file('/tmp/json_export.json') do
|
|
|
|
it { should exist }
|
|
|
|
its('size') { should > 0 }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Grab bundled inspec version. This should be the same as the one
|
|
|
|
# passed for audit cookbook. If its not, you should do a `bundle install`
|
2019-04-30 22:29:56 +00:00
|
|
|
inspec_version = Inspec::VERSION
|
|
|
|
# or: Gem.loaded_specs['inspec'].version.to_s rescue Inspec::VERSION
|
2018-09-25 19:53:26 +00:00
|
|
|
|
|
|
|
control 'Test audit cookbook json output' do
|
|
|
|
describe json('/tmp/json_export.json') do
|
|
|
|
its(['platform', 'name']) { should eq platform.name }
|
|
|
|
its(['statistics', 'duration']) { should > 0 }
|
|
|
|
its('version') { should cmp inspec_version }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# make sure all tests passed
|
|
|
|
file = file('/tmp/json_export.json')
|
|
|
|
if file.exist?
|
|
|
|
json = JSON.parse(file.content)
|
|
|
|
json['profiles'].first['controls'].each do |child_control|
|
|
|
|
child_control['results'].each do |result|
|
|
|
|
control result['code_desc'] do
|
|
|
|
describe json(content: result.to_json) do
|
|
|
|
its('status') { should cmp 'passed' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|