From 924349b88ba17d2d2bb8d0df35e40208ec3b5f59 Mon Sep 17 00:00:00 2001 From: Jared Quick Date: Thu, 31 May 2018 13:53:14 -0400 Subject: [PATCH] Fix the git fetcher to vendor correctly (#3097) Signed-off-by: Jared Quick --- lib/fetchers/git.rb | 2 +- test/functional/inspec_vendor_test.rb | 19 +++++++++++++++++++ test/unit/fetchers/git_test.rb | 2 +- .../unit/mock/profiles/git-depends/inspec.yml | 10 ++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 test/unit/mock/profiles/git-depends/inspec.yml diff --git a/lib/fetchers/git.rb b/lib/fetchers/git.rb index ae7fdf31d..c3b539f26 100644 --- a/lib/fetchers/git.rb +++ b/lib/fetchers/git.rb @@ -50,7 +50,7 @@ module Fetchers Dir.mktmpdir do |tmpdir| checkout(tmpdir) Inspec::Log.debug("Checkout of #{resolved_ref} successful. Moving checkout to #{dir}") - FileUtils.cp_r(tmpdir, @repo_directory) + FileUtils.cp_r(tmpdir + '/.', @repo_directory) end end @repo_directory diff --git a/test/functional/inspec_vendor_test.rb b/test/functional/inspec_vendor_test.rb index bedf08149..09d3bd2e0 100644 --- a/test/functional/inspec_vendor_test.rb +++ b/test/functional/inspec_vendor_test.rb @@ -34,6 +34,25 @@ describe 'example inheritance profile' do end end + it 'can vendor profile dependencies from git' do + git_depends_path = File.join(profile_path, 'git-depends') + + Dir.mktmpdir do |tmpdir| + FileUtils.cp_r(git_depends_path + '/.', tmpdir) + File.exist?(File.join(tmpdir, 'vendor')).must_equal false + + out = inspec('vendor ' + tmpdir + ' --overwrite') + out.stderr.must_equal '' + out.exit_status.must_equal 0 + + out.stdout.must_include "Dependencies for profile #{tmpdir} successfully vendored to #{tmpdir}/vendor" + + File.exist?(File.join(tmpdir, 'vendor')).must_equal true + File.exist?(File.join(tmpdir, 'inspec.lock')).must_equal true + File.exist?(File.join(tmpdir, 'vendor', 'accb84911787830f5b973f3e49de78bbff931946', 'README.md')).must_equal true + end + end + it 'ensure nothing is loaded from external source if vendored profile is used' do prepare_examples('meta-profile') do |dir| out = inspec('vendor ' + dir + ' --overwrite') diff --git a/test/unit/fetchers/git_test.rb b/test/unit/fetchers/git_test.rb index c180d1333..199fcca2a 100644 --- a/test/unit/fetchers/git_test.rb +++ b/test/unit/fetchers/git_test.rb @@ -70,7 +70,7 @@ a7729ce65636d6d8b80159dd5dd7a40fdb6f2501\trefs/tags/anothertag^{}\n") end def expect_mv_into_place - FileUtils.expects(:cp_r).with('test-tmp-dir', 'fetchpath') + FileUtils.expects(:cp_r).with('test-tmp-dir/.', 'fetchpath') end it "resolves to the revision of master by default" do diff --git a/test/unit/mock/profiles/git-depends/inspec.yml b/test/unit/mock/profiles/git-depends/inspec.yml new file mode 100644 index 000000000..ecc7b6359 --- /dev/null +++ b/test/unit/mock/profiles/git-depends/inspec.yml @@ -0,0 +1,10 @@ +name: git depends +title: InSpec example simple inheritance +maintainer: Chef Software, Inc. +copyright: Chef Software, Inc. +copyright_email: support@chef.io +license: Apache 2 license +version: 1.0.0 +depends: + - name: ssh + git: https://github.com/dev-sec/ssh-baseline.git