diff --git a/lib/inspec/targets/dir.rb b/lib/inspec/targets/dir.rb index 06a689479..8d6e7334d 100644 --- a/lib/inspec/targets/dir.rb +++ b/lib/inspec/targets/dir.rb @@ -11,13 +11,11 @@ module Inspec::Targets # TODO: remove `test` support for InSpec 1.0 class ProfileDir def handles?(paths) + return true if paths.include?('inspec.yml') ( !paths.grep(/^controls/).empty? || !paths.grep(/^test/).empty? - ) && ( - paths.include?('inspec.yml') || - paths.include?('metadata.rb') - ) + ) && paths.include?('metadata.rb') end def get_libraries(paths) diff --git a/test/unit/mock/profiles/complete-metadata/inspec.yml b/test/unit/mock/profiles/complete-metadata/inspec.yml new file mode 100644 index 000000000..c705f9736 --- /dev/null +++ b/test/unit/mock/profiles/complete-metadata/inspec.yml @@ -0,0 +1,7 @@ +name: name +version: 1.2.3 +maintainer: bob +title: title +copyright: left +summary: nothing +supports: linux diff --git a/test/unit/mock/profiles/legacy-metadata/test/.gitkeep b/test/unit/mock/profiles/empty-metadata/inspec.yml similarity index 100% rename from test/unit/mock/profiles/legacy-metadata/test/.gitkeep rename to test/unit/mock/profiles/empty-metadata/inspec.yml diff --git a/test/unit/mock/profiles/legacy-metadata/metadata.rb b/test/unit/mock/profiles/legacy-simple-metadata/metadata.rb similarity index 100% rename from test/unit/mock/profiles/legacy-metadata/metadata.rb rename to test/unit/mock/profiles/legacy-simple-metadata/metadata.rb diff --git a/test/unit/mock/profiles/legacy-simple-metadata/test/.gitkeep b/test/unit/mock/profiles/legacy-simple-metadata/test/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/test/unit/mock/profiles/simple-metadata/inspec.yml b/test/unit/mock/profiles/simple-metadata/inspec.yml new file mode 100644 index 000000000..02cff7e19 --- /dev/null +++ b/test/unit/mock/profiles/simple-metadata/inspec.yml @@ -0,0 +1 @@ +name: yumyum profile diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 113a284d9..a26395b27 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -16,7 +16,19 @@ describe Inspec::Profile do Inspec::Profile.from_path("#{home}/mock/profiles/#{name}", opts) end - describe 'with empty profile (legacy mode)' do + describe 'with an empty profile' do + let(:profile) { load_profile('empty-metadata') } + + it 'has no metadata' do + profile.params[:name].must_be_nil + end + + it 'has no rules' do + profile.params[:rules].must_equal({}) + end + end + + describe 'with an empty profile (legacy mode)' do let(:profile) { load_profile('legacy-empty-metadata') } it 'has no metadata' do @@ -28,8 +40,20 @@ describe Inspec::Profile do end end - describe 'with normal metadata in profile (legacy mode)' do - let(:profile) { load_profile('legacy-metadata') } + describe 'with simple metadata in profile' do + let(:profile) { load_profile('simple-metadata') } + + it 'has metadata' do + profile.params[:name].must_equal 'yumyum profile' + end + + it 'has no rules' do + profile.params[:rules].must_equal({}) + end + end + + describe 'with simple metadata in profile (legacy mode)' do + let(:profile) { load_profile('legacy-simple-metadata') } it 'has metadata' do profile.params[:name].must_equal 'metadata profile' @@ -41,6 +65,24 @@ describe Inspec::Profile do end describe 'when checking' do + describe 'an empty profile' do + let(:profile_id) { 'empty-metadata' } + + it 'prints loads of warnings' do + logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"] + logger.expect :error, nil, ['Missing profile name in inspec.yml'] + logger.expect :error, nil, ['Missing profile version in inspec.yml'] + logger.expect :warn, nil, ['Missing profile title in inspec.yml'] + logger.expect :warn, nil, ['Missing profile summary in inspec.yml'] + logger.expect :warn, nil, ['Missing profile maintainer in inspec.yml'] + logger.expect :warn, nil, ['Missing profile copyright in inspec.yml'] + logger.expect :warn, nil, ['No controls or tests were defined.'] + + load_profile(profile_id, {logger: logger}).check + logger.verify + end + end + describe 'an empty profile (legacy mode)' do let(:profile_id) { 'legacy-empty-metadata' } @@ -60,6 +102,20 @@ describe Inspec::Profile do end end + describe 'a complete metadata profile' do + let(:profile_id) { 'complete-metadata' } + let(:profile) { load_profile(profile_id, {logger: logger}) } + + it 'prints ok messages' do + logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"] + logger.expect :info, nil, ['Metadata OK.'] + logger.expect :warn, nil, ['No controls or tests were defined.'] + + profile.check + logger.verify + end + end + describe 'a complete metadata profile (legacy mode)' do let(:profile_id) { 'legacy-complete-metadata' } let(:profile) { load_profile(profile_id, {logger: logger}) }