From 928cf6f05ef8c55b3529f796ce1cb740555cfc90 Mon Sep 17 00:00:00 2001 From: Clinton Wolfe Date: Wed, 11 Dec 2019 14:40:54 -0500 Subject: [PATCH] Functional test and fixtures for git fetcher fallback Signed-off-by: Clinton Wolfe --- .../git-deps-on-missing-0.1.0.tar.gz | Bin 0 -> 1720 bytes .../controls/dep-on-missing.rb | 5 ++++ .../controls/include-missing.rb | 1 + .../git-deps-on-missing/inspec.yml | 10 ++++++++ .../README.md | 5 ++++ .../controls/include-basic.rb | 1 + .../controls/missing.rb | 5 ++++ .../inspec.yml | 9 +++++++ .../controls/include-git-dep.rb | 1 + .../controls/local-dep.rb | 5 ++++ .../local-dep-on-bad-git-archive/inspec.yml | 9 +++++++ test/functional/fetchers_test.rb | 23 ++++++++++++++++-- 12 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/profiles/fetcher-failures/git-deps-on-missing-0.1.0.tar.gz create mode 100644 test/fixtures/profiles/fetcher-failures/git-deps-on-missing/controls/dep-on-missing.rb create mode 100644 test/fixtures/profiles/fetcher-failures/git-deps-on-missing/controls/include-missing.rb create mode 100644 test/fixtures/profiles/fetcher-failures/git-deps-on-missing/inspec.yml create mode 100644 test/fixtures/profiles/fetcher-failures/inspec-test-profile-missing-moved/README.md create mode 100644 test/fixtures/profiles/fetcher-failures/inspec-test-profile-missing-moved/controls/include-basic.rb create mode 100644 test/fixtures/profiles/fetcher-failures/inspec-test-profile-missing-moved/controls/missing.rb create mode 100644 test/fixtures/profiles/fetcher-failures/inspec-test-profile-missing-moved/inspec.yml create mode 100644 test/fixtures/profiles/fetcher-failures/local-dep-on-bad-git-archive/controls/include-git-dep.rb create mode 100644 test/fixtures/profiles/fetcher-failures/local-dep-on-bad-git-archive/controls/local-dep.rb create mode 100644 test/fixtures/profiles/fetcher-failures/local-dep-on-bad-git-archive/inspec.yml diff --git a/test/fixtures/profiles/fetcher-failures/git-deps-on-missing-0.1.0.tar.gz b/test/fixtures/profiles/fetcher-failures/git-deps-on-missing-0.1.0.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..1b2b0bc9d0075417ad2aee43bd400f5da7dbc45e GIT binary patch literal 1720 zcmV;p21ofHiwFSur0!h+1MFLEZ`(Ey&S(FMgNtG<5X*X3>tGNAh$JA0EkwXR_d_*x90(rfUYCho4%O zKlT5X;{}dq+fHEZn3iK%{tkHCY}8yzAxVKvnT#k+SJYcqzTCNQM54<7U6w^@8Pm>~ z3Bj_VQG^d>!?aA(cik`h-(U8>@0;EZ)G~-q-2au^KhNKT7eBB}G~k%yH<{Kqu!@N665zc&6Y*IAB#$Mu`|uR|*TL;Je_JEql!n7068Dx!jg z6xsxYEU>I90ALdS1u^1f8bdVBuh#evE6^-%slUhWVk0YLhW19vqrbOiV_p0Qfw#>6 z+`wt#zYghiIxXdVHO+rMr-fiV>w(omIKbEyy;cV@GNwIPK?^X}3o3YePUFvlmqkQ- z8XtyC_MqMEz89#s8%=nc(5@g^9P*3qOkefUNvMoQs+Q8B)V03Cm}4= zB`ccK*2W8(^dN8&O8waOed_G_7JcQ0CXLA+iS`0Ja*~+1P8ixgK2h~u5g`OI!ZIm( z@aJC|0o72@EMiosj;$JzkO&r4_HP-HYD`8_=Azf_;+Ihw8WA5a4aZHL2G*@q=$`qm z=e@EB-6N(?y}$~SAPN$TgtqNlX5#F*zL&&qqM!Lv-*y)9KOL`nx4%->#lPp=h=0dv z=Koq`_A2Ac)xpXG*uE=hbF@F0M_K!co@BQP$U7$Ex zXop_ph3Ww|lc|xUu^zSorPrE(3`~DlG>0WD!mee*k_;&fIg+ViM!$@2ff_vt*%bdzkMGWJXS3<;Fv?Tw$ug+e$HZr zc#rLXN0v?FKf1?xfzA29ZJKt&|Lc(Z`oBBNO5SOkaP9t|V=wvNaecGF|2kx`|EK-g zZ2LVm*);y|vtO_-{%v=e|Jld@oA|Fo)@@};CR40X5w3T$vTOSQRnfuaYW&^umcVU< z@2+|O#~z^XT&noL>qhClY}_ON>mnpH{I3St(EoMie?8l3@V^de^1n^~x5@uLUD*`> zw~_z#-5dBH1P%YMMQ+dk&JVCWWCmEPnjZsFCxFl}Eu?-F@sSkKh@DfhtJKVNskO-* zuXScvJr#`*erT*u@8|^vlQ7Y_h>+rpKoM;8VL^q$l~IzWe4?7Ea9A}^Yn&fBgh^#@ z3OJ#u38y-`cX?{*J5En;8vixre;w0p_0+cx}&Sr}%og)iNIbZfY_&t!zi&$TERV O{{sL>{;p*JNB{tLdUsI( literal 0 HcmV?d00001 diff --git a/test/fixtures/profiles/fetcher-failures/git-deps-on-missing/controls/dep-on-missing.rb b/test/fixtures/profiles/fetcher-failures/git-deps-on-missing/controls/dep-on-missing.rb new file mode 100644 index 000000000..7fda9ce58 --- /dev/null +++ b/test/fixtures/profiles/fetcher-failures/git-deps-on-missing/controls/dep-on-missing.rb @@ -0,0 +1,5 @@ +control "dep-on-missing-01" do + describe "a string" do + it { should cmp "a string" } + end +end diff --git a/test/fixtures/profiles/fetcher-failures/git-deps-on-missing/controls/include-missing.rb b/test/fixtures/profiles/fetcher-failures/git-deps-on-missing/controls/include-missing.rb new file mode 100644 index 000000000..808ac1ad7 --- /dev/null +++ b/test/fixtures/profiles/fetcher-failures/git-deps-on-missing/controls/include-missing.rb @@ -0,0 +1 @@ +include_controls('inspec-test-profile-missing') diff --git a/test/fixtures/profiles/fetcher-failures/git-deps-on-missing/inspec.yml b/test/fixtures/profiles/fetcher-failures/git-deps-on-missing/inspec.yml new file mode 100644 index 000000000..d0320b6db --- /dev/null +++ b/test/fixtures/profiles/fetcher-failures/git-deps-on-missing/inspec.yml @@ -0,0 +1,10 @@ +name: git-deps-on-missing +license: Apache-2.0 +summary: An inspec profile that has a git dependency on a profile that was deleted +version: 0.1.0 +supports: + platform: os +depends: + - name: inspec-test-profile-missing + # git requires a leading slash, so rely on ERB to interpolate in the PWD... + git: /<%= Dir.pwd %>/inspec-test-profile-missing diff --git a/test/fixtures/profiles/fetcher-failures/inspec-test-profile-missing-moved/README.md b/test/fixtures/profiles/fetcher-failures/inspec-test-profile-missing-moved/README.md new file mode 100644 index 000000000..c1d35ab4e --- /dev/null +++ b/test/fixtures/profiles/fetcher-failures/inspec-test-profile-missing-moved/README.md @@ -0,0 +1,5 @@ +# inspec-test-profile-missing + +This is a Chef InSpec profile. It is used in the testing of InSpec itself. This profile was inserted into archives, then the name of the repo was changed, so that it would become unfetchable. This allows us to test the fetchers when they cannot resolve a profile. + +This repo is part of the testing material of InSpec itself, and is not intended for public use. No support is provided. diff --git a/test/fixtures/profiles/fetcher-failures/inspec-test-profile-missing-moved/controls/include-basic.rb b/test/fixtures/profiles/fetcher-failures/inspec-test-profile-missing-moved/controls/include-basic.rb new file mode 100644 index 000000000..38c63a0cf --- /dev/null +++ b/test/fixtures/profiles/fetcher-failures/inspec-test-profile-missing-moved/controls/include-basic.rb @@ -0,0 +1 @@ +include_controls('inspec-test-profile-basic') diff --git a/test/fixtures/profiles/fetcher-failures/inspec-test-profile-missing-moved/controls/missing.rb b/test/fixtures/profiles/fetcher-failures/inspec-test-profile-missing-moved/controls/missing.rb new file mode 100644 index 000000000..2f9fe6c6e --- /dev/null +++ b/test/fixtures/profiles/fetcher-failures/inspec-test-profile-missing-moved/controls/missing.rb @@ -0,0 +1,5 @@ +control "missing-01" do + describe "a string" do + it { should cmp "a string" } + end +end diff --git a/test/fixtures/profiles/fetcher-failures/inspec-test-profile-missing-moved/inspec.yml b/test/fixtures/profiles/fetcher-failures/inspec-test-profile-missing-moved/inspec.yml new file mode 100644 index 000000000..93a53952a --- /dev/null +++ b/test/fixtures/profiles/fetcher-failures/inspec-test-profile-missing-moved/inspec.yml @@ -0,0 +1,9 @@ +name: inspec-test-profile-missing +title: InSpec Profile +summary: An InSpec Compliance Profile that will end up unresolvable but archived +version: 0.1.0 +supports: + platform: os +depends: + - name: inspec-test-profile-basic + git: https://github.com/inspec/inspec-test-profile-basic.git diff --git a/test/fixtures/profiles/fetcher-failures/local-dep-on-bad-git-archive/controls/include-git-dep.rb b/test/fixtures/profiles/fetcher-failures/local-dep-on-bad-git-archive/controls/include-git-dep.rb new file mode 100644 index 000000000..7cebbb3eb --- /dev/null +++ b/test/fixtures/profiles/fetcher-failures/local-dep-on-bad-git-archive/controls/include-git-dep.rb @@ -0,0 +1 @@ +include_controls('git-deps-on-missing') diff --git a/test/fixtures/profiles/fetcher-failures/local-dep-on-bad-git-archive/controls/local-dep.rb b/test/fixtures/profiles/fetcher-failures/local-dep-on-bad-git-archive/controls/local-dep.rb new file mode 100644 index 000000000..52a55f5bd --- /dev/null +++ b/test/fixtures/profiles/fetcher-failures/local-dep-on-bad-git-archive/controls/local-dep.rb @@ -0,0 +1,5 @@ +control "local-dep-01" do + describe "a string" do + it { should cmp "a string" } + end +end diff --git a/test/fixtures/profiles/fetcher-failures/local-dep-on-bad-git-archive/inspec.yml b/test/fixtures/profiles/fetcher-failures/local-dep-on-bad-git-archive/inspec.yml new file mode 100644 index 000000000..41f93b00b --- /dev/null +++ b/test/fixtures/profiles/fetcher-failures/local-dep-on-bad-git-archive/inspec.yml @@ -0,0 +1,9 @@ +name: local-dep-on-bad-git-archive +license: Apache-2.0 +summary: A profile that relies on an archive that has an unresolvable git dependency +version: 0.1.0 +supports: + platform: os +depends: + - name: git-deps-on-missing + path: ../git-deps-on-missing-0.1.0.tar.gz diff --git a/test/functional/fetchers_test.rb b/test/functional/fetchers_test.rb index ca618b426..76fe4a6e3 100644 --- a/test/functional/fetchers_test.rb +++ b/test/functional/fetchers_test.rb @@ -1,16 +1,16 @@ require "functional/helper" describe "the fetchers" do - parallelize_me! include FunctionalHelper let(:looks_like_a_stacktrace) { %r{lib/inspec/.+\.rb:\d+:in} } let(:invocation) { "exec #{path} --no-create-lockfile" } let(:run_result) { inspec(invocation) } + let(:fetcher_profiles) { "#{profile_path}/fetcher-failures" } # Refs #4726 describe "when fetchers fetch a bad dependency" do - let(:fetcher_profiles) { "#{profile_path}/fetcher-failures" } + parallelize_me! def assert_fetcher_failed_cleanly(run_result, error_regex, profile_location) _(run_result.stdout).must_be_empty @@ -54,4 +54,23 @@ describe "the fetchers" do end end + + # Refs #4727 + describe "when a archive is available of an unfetchable profile with --airgap" do + + let(:invocation) { "archive #{path} --airgap" } + let(:path) { "#{fetcher_profiles}/local-dep-on-bad-git-archive" } + + def teardown + FileUtils.rm_rf "#{path}/vendor" + FileUtils.rm_rf "#{fetcher_profiles}/local-dep-on-bad-git-archive-0.1.0.tar.gz" + end + + it "should be able to create a new archive wrapping the profile" do + # Cannot be parallelized - must purge cache to test properly + _(run_result.stderr).must_be_empty + _(run_result.stdout).must_include "Finished archive generation" + assert_exit_code(0, run_result) + end + end end