2019-11-19 19:45:10 +00:00
|
|
|
require "functional/helper"
|
|
|
|
|
|
|
|
describe "the fetchers" do
|
|
|
|
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) }
|
2019-12-11 19:40:54 +00:00
|
|
|
let(:fetcher_profiles) { "#{profile_path}/fetcher-failures" }
|
2019-11-19 19:45:10 +00:00
|
|
|
|
|
|
|
# Refs #4726
|
|
|
|
describe "when fetchers fetch a bad dependency" do
|
2019-12-11 19:40:54 +00:00
|
|
|
parallelize_me!
|
2019-11-19 19:45:10 +00:00
|
|
|
|
2019-11-20 18:02:37 +00:00
|
|
|
def assert_fetcher_failed_cleanly(run_result, error_regex, profile_location)
|
|
|
|
_(run_result.stdout).must_be_empty
|
|
|
|
_(run_result.stderr).wont_match looks_like_a_stacktrace
|
|
|
|
_(run_result.stderr).must_match(error_regex)
|
|
|
|
_(run_result.stderr).must_include profile_location
|
|
|
|
assert_exit_code(1, run_result)
|
|
|
|
end
|
|
|
|
|
2019-11-19 19:45:10 +00:00
|
|
|
describe "when using the local fetcher on a bad dep" do
|
|
|
|
let(:path) { "#{fetcher_profiles}/local-bad" }
|
2019-11-25 20:17:33 +00:00
|
|
|
it "should throw an exception not a stacktrace with a local fetcher" do
|
2019-11-20 18:02:37 +00:00
|
|
|
assert_fetcher_failed_cleanly(
|
|
|
|
run_result,
|
|
|
|
/Profile dependency local path .+ does not exist/,
|
|
|
|
"fetcher-failures/nonesuch"
|
|
|
|
)
|
2019-11-19 19:45:10 +00:00
|
|
|
end
|
|
|
|
end
|
2019-11-19 23:16:34 +00:00
|
|
|
|
|
|
|
describe "when using the url fetcher on a bad dep" do
|
|
|
|
let(:path) { "#{fetcher_profiles}/url-bad" }
|
2019-11-25 20:17:33 +00:00
|
|
|
it "should throw an exception not a stacktrace with a url fetcher" do
|
2019-11-20 18:02:37 +00:00
|
|
|
assert_fetcher_failed_cleanly(
|
|
|
|
run_result,
|
|
|
|
/Profile URL dependency .+ could not be fetched:/,
|
2019-11-25 20:17:33 +00:00
|
|
|
"https://localhost.invalid/inspec/inspec-nonesuch/path/to/profile.tgz"
|
2019-11-20 18:02:37 +00:00
|
|
|
)
|
2019-11-19 23:16:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-25 20:17:33 +00:00
|
|
|
describe "when using the git fetcher on a bad dep" do
|
2019-11-20 17:27:55 +00:00
|
|
|
let(:path) { "#{fetcher_profiles}/git-bad" }
|
2019-11-25 20:17:33 +00:00
|
|
|
it "should throw an exception not a stacktrace with a git fetcher" do
|
2019-11-20 18:02:37 +00:00
|
|
|
assert_fetcher_failed_cleanly(
|
|
|
|
run_result,
|
2019-11-25 20:17:33 +00:00
|
|
|
/Profile git dependency failed for .+ Could not resolve host.+/,
|
|
|
|
"http://localhost.invalid/no/such"
|
2019-11-20 18:02:37 +00:00
|
|
|
)
|
2019-11-20 17:27:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-19 19:45:10 +00:00
|
|
|
end
|
2019-12-11 19:40:54 +00:00
|
|
|
|
|
|
|
# Refs #4727
|
|
|
|
describe "when a archive is available of an unfetchable profile with --airgap" do
|
|
|
|
|
2019-12-17 20:34:38 +00:00
|
|
|
let(:invocation) { "archive #{fetcher_profiles}/#{profile_name} --airgap" }
|
2019-12-11 19:40:54 +00:00
|
|
|
|
|
|
|
def teardown
|
2019-12-17 20:34:38 +00:00
|
|
|
FileUtils.rm_rf "#{fetcher_profiles}/#{profile_name}/vendor"
|
2019-12-19 19:21:53 +00:00
|
|
|
FileUtils.rm_f "#{profile_name}-0.1.0.tar.gz"
|
2019-12-11 19:40:54 +00:00
|
|
|
end
|
|
|
|
|
2019-12-17 20:34:38 +00:00
|
|
|
def assert_archive_worked(run_result)
|
2019-12-11 19:40:54 +00:00
|
|
|
_(run_result.stderr).must_be_empty
|
|
|
|
_(run_result.stdout).must_include "Finished archive generation"
|
|
|
|
assert_exit_code(0, run_result)
|
|
|
|
end
|
2019-12-17 20:34:38 +00:00
|
|
|
|
2019-12-19 19:21:53 +00:00
|
|
|
describe "when using a local fetcher" do
|
|
|
|
let(:profile_name) { "local-dep-on-bad-local-archive" }
|
|
|
|
it "should be able to create a new archive wrapping the profile" do
|
|
|
|
assert_archive_worked(run_result)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-17 20:34:38 +00:00
|
|
|
describe "when using a git fetcher" do
|
|
|
|
let(:profile_name) { "local-dep-on-bad-git-archive" }
|
|
|
|
it "should be able to create a new archive wrapping the profile" do
|
|
|
|
assert_archive_worked(run_result)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when using a url fetcher" do
|
|
|
|
let(:profile_name) { "local-dep-on-bad-url-archive" }
|
|
|
|
it "should be able to create a new archive wrapping the profile" do
|
|
|
|
assert_archive_worked(run_result)
|
|
|
|
end
|
|
|
|
end
|
2019-12-20 12:17:48 +00:00
|
|
|
|
|
|
|
# To develop on this test, setup an Automate server, run
|
|
|
|
# `inspec compliance login`, and upload two profiles to the admin account:
|
|
|
|
# test/fixtures/profiles/fetcher-failures/{basic,auto-dep-on-missing}
|
|
|
|
describe "when using a compliance fetcher" do
|
|
|
|
let(:profile_name) { "local-dep-on-bad-auto-archive" }
|
|
|
|
it "should be able to create a new archive wrapping the profile" do
|
|
|
|
assert_archive_worked(run_result)
|
|
|
|
end
|
|
|
|
end
|
2019-12-11 19:40:54 +00:00
|
|
|
end
|
2019-11-19 19:45:10 +00:00
|
|
|
end
|