2015-10-26 21:51:21 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# author: Christoph Hartmann
|
|
|
|
# author: Dominik Richter
|
|
|
|
|
|
|
|
require 'helper'
|
2016-01-16 07:00:52 +00:00
|
|
|
require 'inspec/profile_context'
|
|
|
|
require 'inspec/runner'
|
2016-01-16 13:53:51 +00:00
|
|
|
require 'inspec/runner_mock'
|
2015-10-26 21:51:21 +00:00
|
|
|
|
|
|
|
describe Inspec::Profile do
|
2015-12-22 14:18:09 +00:00
|
|
|
let(:logger) { Minitest::Mock.new }
|
|
|
|
let(:home) { File.dirname(__FILE__) }
|
|
|
|
|
|
|
|
def load_profile(name, opts = {})
|
2016-01-16 13:53:51 +00:00
|
|
|
opts[:test_collector] = Inspec::RunnerMock.new
|
2015-12-22 14:18:09 +00:00
|
|
|
Inspec::Profile.from_path("#{home}/mock/profiles/#{name}", opts)
|
|
|
|
end
|
|
|
|
|
2016-01-16 14:33:07 +00:00
|
|
|
describe 'with empty profile (legacy mode)' do
|
|
|
|
let(:profile) { load_profile('legacy-empty-metadata') }
|
2015-10-26 21:51:21 +00:00
|
|
|
|
|
|
|
it 'has no metadata' do
|
|
|
|
profile.params[:name].must_be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has no rules' do
|
|
|
|
profile.params[:rules].must_equal({})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-16 14:33:07 +00:00
|
|
|
describe 'with normal metadata in profile (legacy mode)' do
|
|
|
|
let(:profile) { load_profile('legacy-metadata') }
|
2015-10-26 21:51:21 +00:00
|
|
|
|
|
|
|
it 'has metadata' do
|
|
|
|
profile.params[:name].must_equal 'metadata profile'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has no rules' do
|
|
|
|
profile.params[:rules].must_equal({})
|
|
|
|
end
|
|
|
|
end
|
2015-12-22 14:18:09 +00:00
|
|
|
|
|
|
|
describe 'when checking' do
|
2016-01-16 14:33:07 +00:00
|
|
|
describe 'an empty profile (legacy mode)' do
|
|
|
|
let(:profile_id) { 'legacy-empty-metadata' }
|
2015-12-22 14:18:09 +00:00
|
|
|
|
|
|
|
it 'prints loads of warnings' do
|
2016-01-16 14:33:07 +00:00
|
|
|
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"]
|
2015-12-28 12:30:42 +00:00
|
|
|
logger.expect :warn, nil, ['The use of `metadata.rb` is deprecated. Use `inspec.yml`.']
|
2015-12-22 14:18:09 +00:00
|
|
|
logger.expect :error, nil, ['Missing profile name in metadata.rb']
|
|
|
|
logger.expect :error, nil, ['Missing profile version in metadata.rb']
|
|
|
|
logger.expect :warn, nil, ['Missing profile title in metadata.rb']
|
|
|
|
logger.expect :warn, nil, ['Missing profile summary in metadata.rb']
|
|
|
|
logger.expect :warn, nil, ['Missing profile maintainer in metadata.rb']
|
|
|
|
logger.expect :warn, nil, ['Missing profile copyright in metadata.rb']
|
|
|
|
logger.expect :warn, nil, ['No controls or tests were defined.']
|
|
|
|
|
2016-01-16 14:33:07 +00:00
|
|
|
load_profile(profile_id, {logger: logger}).check
|
2015-12-22 14:18:09 +00:00
|
|
|
logger.verify
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-15 17:45:05 +00:00
|
|
|
describe 'a complete metadata profile (legacy mode)' do
|
2016-01-16 14:33:07 +00:00
|
|
|
let(:profile_id) { 'legacy-complete-metadata' }
|
|
|
|
let(:profile) { load_profile(profile_id, {logger: logger}) }
|
2015-12-22 14:18:09 +00:00
|
|
|
|
|
|
|
it 'prints ok messages' do
|
2016-01-16 14:33:07 +00:00
|
|
|
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"]
|
2015-12-28 12:30:42 +00:00
|
|
|
logger.expect :warn, nil, ['The use of `metadata.rb` is deprecated. Use `inspec.yml`.']
|
2015-12-22 14:18:09 +00:00
|
|
|
logger.expect :info, nil, ['Metadata OK.']
|
2016-01-15 17:45:05 +00:00
|
|
|
logger.expect :warn, nil, ["Profile uses deprecated `test` directory, rename it to `controls`."]
|
2015-12-22 14:18:09 +00:00
|
|
|
logger.expect :warn, nil, ['No controls or tests were defined.']
|
|
|
|
|
|
|
|
profile.check
|
|
|
|
logger.verify
|
|
|
|
end
|
2016-01-15 17:45:05 +00:00
|
|
|
|
|
|
|
it 'doesnt have constraints on supported systems' do
|
|
|
|
profile.metadata.params.wont_include(:supports)
|
|
|
|
end
|
2015-12-22 14:18:09 +00:00
|
|
|
end
|
2016-01-07 23:16:07 +00:00
|
|
|
|
|
|
|
describe 'a complete metadata profile with controls' do
|
2016-01-16 14:33:07 +00:00
|
|
|
let(:profile_id) { 'complete-profile' }
|
2016-01-11 04:59:57 +00:00
|
|
|
|
|
|
|
it 'prints ok messages and counts the rules' do
|
2016-01-16 14:33:07 +00:00
|
|
|
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"]
|
2016-01-11 04:59:57 +00:00
|
|
|
logger.expect :info, nil, ['Metadata OK.']
|
2016-01-16 13:53:51 +00:00
|
|
|
logger.expect :info, nil, ['Found 1 rules.']
|
2016-01-16 14:33:07 +00:00
|
|
|
logger.expect :debug, nil, ["Verify all rules in #{home}/mock/profiles/#{profile_id}/controls/filesystem_spec.rb"]
|
2016-01-16 13:53:51 +00:00
|
|
|
logger.expect :info, nil, ['Rule definitions OK.']
|
2016-01-11 04:59:57 +00:00
|
|
|
|
2016-01-16 14:33:07 +00:00
|
|
|
load_profile(profile_id, {logger: logger, ignore_supports: true}).check
|
2016-01-11 04:59:57 +00:00
|
|
|
logger.verify
|
|
|
|
end
|
2016-01-07 23:16:07 +00:00
|
|
|
end
|
2015-12-22 14:18:09 +00:00
|
|
|
end
|
2015-10-26 21:51:21 +00:00
|
|
|
end
|