2016-03-25 00:31:19 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# author: Dominik Richter
|
|
|
|
# author: Christoph Hartmann
|
|
|
|
|
|
|
|
require 'functional/helper'
|
|
|
|
|
|
|
|
describe 'inspec exec' do
|
|
|
|
include FunctionalHelper
|
|
|
|
|
|
|
|
it 'can execute the profile' do
|
2016-09-21 12:09:57 +00:00
|
|
|
out = inspec('exec --no-write-lockfile ' + example_profile)
|
2016-03-25 00:31:19 +00:00
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.exit_status.must_equal 0
|
2016-06-15 17:27:56 +00:00
|
|
|
stdout = out.stdout.force_encoding(Encoding::UTF_8)
|
2016-09-16 21:59:31 +00:00
|
|
|
stdout.must_include "\e[32m ✔ ssh-1: Allow only SSH Protocol 2\e[0m\n"
|
|
|
|
stdout.must_include "\e[32m ✔ tmp-1.0: Create /tmp directory\e[0m\n"
|
2016-06-15 20:17:59 +00:00
|
|
|
stdout.must_include "
|
|
|
|
\e[37m ○ gordon-1.0: Verify the version number of Gordon (1 skipped)\e[0m
|
2016-08-22 15:57:33 +00:00
|
|
|
\e[37m ○ Can't find file \"/tmp/gordon/config.yaml\"\e[0m
|
2016-06-15 20:17:59 +00:00
|
|
|
"
|
2016-09-14 16:20:32 +00:00
|
|
|
stdout.must_include "\nProfile Summary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m, \e[37m1 skipped\e[0m"
|
|
|
|
stdout.must_include "\nTest Summary: \e[32m4 successful\e[0m, \e[31m0 failures\e[0m, \e[37m1 skipped\e[0m\n"
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|
|
|
|
|
2016-06-14 12:41:45 +00:00
|
|
|
it 'executes a minimum metadata-only profile' do
|
2016-09-21 12:09:57 +00:00
|
|
|
out = inspec('exec --no-write-lockfile ' + File.join(profile_path, 'simple-metadata'))
|
2016-03-25 00:31:19 +00:00
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.exit_status.must_equal 0
|
2016-06-14 12:41:45 +00:00
|
|
|
out.stdout.must_equal "
|
2016-08-22 15:57:33 +00:00
|
|
|
|
2016-06-14 12:41:45 +00:00
|
|
|
Profile: yumyum profile
|
|
|
|
Version: unknown
|
2016-06-16 07:19:25 +00:00
|
|
|
Target: local://
|
2016-06-14 12:41:45 +00:00
|
|
|
|
2016-06-15 20:17:59 +00:00
|
|
|
No tests executed.\e[0m
|
2016-06-14 12:41:45 +00:00
|
|
|
|
2016-09-14 16:20:32 +00:00
|
|
|
Test Summary: \e[32m0 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m
|
2016-06-14 12:41:45 +00:00
|
|
|
"
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|
|
|
|
|
2016-06-14 12:41:45 +00:00
|
|
|
it 'executes a metadata-only profile' do
|
2016-09-21 12:09:57 +00:00
|
|
|
out = inspec('exec --no-write-lockfile ' + File.join(profile_path, 'complete-metadata'))
|
2016-03-25 00:31:19 +00:00
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.exit_status.must_equal 0
|
2016-06-14 12:41:45 +00:00
|
|
|
out.stdout.must_equal "
|
2016-08-22 15:57:33 +00:00
|
|
|
|
2016-06-14 12:41:45 +00:00
|
|
|
Profile: title (name)
|
|
|
|
Version: 1.2.3
|
2016-06-16 07:19:25 +00:00
|
|
|
Target: local://
|
2016-06-14 12:41:45 +00:00
|
|
|
|
2016-06-15 20:17:59 +00:00
|
|
|
No tests executed.\e[0m
|
2016-06-14 12:41:45 +00:00
|
|
|
|
2016-09-14 16:20:32 +00:00
|
|
|
Test Summary: \e[32m0 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m
|
2016-06-14 12:41:45 +00:00
|
|
|
"
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|
|
|
|
|
2016-09-06 23:40:07 +00:00
|
|
|
it "executes a profile and reads attributes" do
|
2016-09-21 12:09:57 +00:00
|
|
|
out = inspec("exec --no-write-lockfile #{File.join(examples_path, 'profile-attribute')} --attrs #{File.join(examples_path, "profile-attribute.yml")}")
|
2016-09-06 23:40:07 +00:00
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m"
|
|
|
|
end
|
|
|
|
|
2016-06-14 12:41:45 +00:00
|
|
|
it 'executes a specs-only profile' do
|
2016-09-21 12:09:57 +00:00
|
|
|
out = inspec('exec --no-write-lockfile ' + File.join(profile_path, 'spec_only'))
|
2016-04-11 14:30:35 +00:00
|
|
|
out.stderr.must_equal ''
|
2016-06-14 12:41:45 +00:00
|
|
|
out.exit_status.must_equal 1
|
2016-09-04 16:57:03 +00:00
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "Target: local://"
|
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "working should"
|
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "✔ eq \"working\""
|
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "skippy This"
|
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "○ will be skipped intentionally."
|
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "failing should"
|
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ eq \"as intended\""
|
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[32m1 successful\e[0m, \e[31m1 failures\e[0m, \e[37m1 skipped\e[0m"
|
2016-04-11 14:30:35 +00:00
|
|
|
end
|
|
|
|
|
2016-06-14 12:41:45 +00:00
|
|
|
it 'executes only specified controls' do
|
2016-09-21 12:09:57 +00:00
|
|
|
out = inspec('exec --no-write-lockfile ' + example_profile + ' --controls tmp-1.0')
|
2016-04-11 14:30:35 +00:00
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.exit_status.must_equal 0
|
2016-09-14 16:20:32 +00:00
|
|
|
out.stdout.must_include "\nProfile Summary: \e[32m1 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m\n"
|
2016-04-11 14:30:35 +00:00
|
|
|
end
|
|
|
|
|
2016-06-14 12:41:45 +00:00
|
|
|
it 'can execute a simple file with the default formatter' do
|
2016-09-21 12:09:57 +00:00
|
|
|
out = inspec('exec --no-write-lockfile ' + example_control)
|
2016-06-14 12:41:45 +00:00
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.exit_status.must_equal 0
|
2016-09-14 16:20:32 +00:00
|
|
|
out.stdout.must_include "\nProfile Summary: \e[32m1 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m\n"
|
|
|
|
out.stdout.must_include "\nTest Summary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m"
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|
|
|
|
|
2016-04-05 16:07:00 +00:00
|
|
|
describe 'with a profile that is not supported on this OS/platform' do
|
2016-09-21 12:09:57 +00:00
|
|
|
let(:out) { inspec('exec --no-write-lockfile ' + File.join(profile_path, 'skippy-profile-os')) }
|
2016-04-05 16:07:00 +00:00
|
|
|
let(:json) { JSON.load(out.stdout) }
|
|
|
|
|
2016-04-17 00:04:10 +00:00
|
|
|
it 'exits with an error' do
|
2016-09-07 11:10:35 +00:00
|
|
|
out.stderr.must_match(/^This OS\/platform \(.+\) is not supported by this profile.$/)
|
2016-04-17 00:04:10 +00:00
|
|
|
out.exit_status.must_equal 1
|
2016-04-05 16:07:00 +00:00
|
|
|
end
|
2016-04-17 00:04:10 +00:00
|
|
|
end
|
2016-04-05 16:07:00 +00:00
|
|
|
|
2016-04-16 19:34:23 +00:00
|
|
|
describe 'with a profile that is supported on this version of inspec' do
|
2016-09-21 12:09:57 +00:00
|
|
|
let(:out) { inspec('exec --no-write-lockfile ' + File.join(profile_path, 'supported_inspec')) }
|
2016-04-16 19:34:23 +00:00
|
|
|
|
|
|
|
it 'exits cleanly' do
|
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with a profile that is not supported on this version of inspec' do
|
2016-09-21 12:09:57 +00:00
|
|
|
let(:out) { inspec('exec --no-write-lockfile ' + File.join(profile_path, 'unsupported_inspec')) }
|
2016-04-16 19:34:23 +00:00
|
|
|
|
|
|
|
it 'does not support this profile' do
|
|
|
|
out.exit_status.must_equal 1
|
|
|
|
out.stderr.must_equal "This profile requires InSpec version >= 99.0.0. You are running InSpec v#{Inspec::VERSION}.\n"
|
|
|
|
end
|
|
|
|
end
|
2016-06-03 19:36:16 +00:00
|
|
|
|
|
|
|
describe 'with a profile that loads a library and reference' do
|
2016-09-21 12:09:57 +00:00
|
|
|
let(:out) { inspec('exec --no-write-lockfile ' + File.join(profile_path, 'library')) }
|
2016-06-03 19:36:16 +00:00
|
|
|
|
|
|
|
it 'executes the profile without error' do
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
end
|
|
|
|
end
|
2016-08-22 15:57:33 +00:00
|
|
|
|
|
|
|
describe 'given a profile with controls and anonymous describe blocks' do
|
2016-09-21 12:09:57 +00:00
|
|
|
let(:out) { inspec('exec --no-write-lockfile ' + example_control) }
|
2016-08-22 15:57:33 +00:00
|
|
|
|
|
|
|
it 'prints the control results, then the anonymous describe block results' do
|
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_equal "
|
|
|
|
Target: local://
|
|
|
|
|
|
|
|
\e[32m \xE2\x9C\x94 tmp-1.0: Create /tmp directory\e[0m
|
2016-09-01 12:25:56 +00:00
|
|
|
\e[32m \xE2\x9C\x94 File /tmp should be directory\e[0m
|
2016-08-22 15:57:33 +00:00
|
|
|
|
|
|
|
File /tmp
|
|
|
|
\e[32m \xE2\x9C\x94 should be directory\e[0m
|
|
|
|
|
2016-09-14 16:20:32 +00:00
|
|
|
Profile Summary: \e[32m1 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m
|
|
|
|
Test Summary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m
|
2016-08-22 15:57:33 +00:00
|
|
|
"
|
|
|
|
end
|
|
|
|
end
|
2016-09-01 12:25:56 +00:00
|
|
|
|
|
|
|
describe 'given a profile with an anonymous describe block' do
|
2016-09-21 12:09:57 +00:00
|
|
|
let(:out) { inspec('exec --no-write-lockfile ' + failure_control) }
|
2016-09-01 12:25:56 +00:00
|
|
|
|
|
|
|
it 'prints the exception message when a test has a syntax error' do
|
|
|
|
out.stdout.must_include "undefined method `should_nota' "
|
|
|
|
end
|
|
|
|
end
|
2016-09-01 22:54:03 +00:00
|
|
|
|
|
|
|
describe 'given an inherited profile that has more that one test per control block' do
|
2016-09-21 12:09:57 +00:00
|
|
|
let(:out) { inspec('exec --no-write-lockfile ' + simple_inheritance) }
|
2016-09-01 22:54:03 +00:00
|
|
|
|
|
|
|
it 'should print all the results' do
|
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ tmp-1.0: Create /tmp directory (1 failed)\e[0m"
|
2016-09-04 16:57:03 +00:00
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ should not be directory"
|
2016-09-01 22:54:03 +00:00
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ undefined method `should_nota'"
|
2016-09-19 15:01:18 +00:00
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ should not be directory\n expected `File /tmp.directory?` to return false, got true\e[0m"
|
2016-09-01 22:54:03 +00:00
|
|
|
end
|
|
|
|
end
|
2016-09-02 16:33:21 +00:00
|
|
|
|
|
|
|
describe 'when passing in two profiles given an inherited profile that has more that one test per control block' do
|
2016-09-21 12:09:57 +00:00
|
|
|
let(:out) { inspec('exec --no-write-lockfile ' + File.join(profile_path, 'dependencies', 'profile_d') + ' ' + simple_inheritance) }
|
2016-09-02 16:33:21 +00:00
|
|
|
|
|
|
|
it 'should print all the results' do
|
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ tmp-1.0: Create /tmp directory (1 failed)\e[0m"
|
2016-09-04 16:57:03 +00:00
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ should not be directory"
|
2016-09-02 16:33:21 +00:00
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ undefined method `should_nota'"
|
2016-09-19 15:01:18 +00:00
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ should not be directory\n expected `File /tmp.directory?` to return false, got true\e[0m"
|
2016-09-02 16:33:21 +00:00
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "✔ profiled-1: Create /tmp directory (profile d)"
|
2016-09-15 00:10:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-15 07:54:15 +00:00
|
|
|
describe 'using namespaced resources' do
|
|
|
|
it 'works' do
|
2016-09-21 12:09:57 +00:00
|
|
|
out = inspec('exec --no-write-lockfile ' + File.join(profile_path, 'dependencies', 'resource-namespace'))
|
2016-09-15 07:54:15 +00:00
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[32m5 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m\n"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-15 00:10:06 +00:00
|
|
|
describe "with a 2-level dependency tree" do
|
|
|
|
it 'correctly runs tests from the whole tree' do
|
2016-09-21 12:09:57 +00:00
|
|
|
out = inspec('exec --no-write-lockfile ' + File.join(profile_path, 'dependencies', 'inheritance'))
|
2016-09-15 00:10:06 +00:00
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[32m6 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m\n"
|
2016-09-02 16:33:21 +00:00
|
|
|
end
|
|
|
|
end
|
2016-09-13 10:03:24 +00:00
|
|
|
|
|
|
|
describe 'when using profiles on the supermarket' do
|
|
|
|
it 'can run supermarket profiles directly from the command line' do
|
2016-09-21 12:09:57 +00:00
|
|
|
out = inspec("exec --no-write-lockfile supermarket://nathenharvey/tmp-compliance-profile")
|
2016-09-13 10:03:24 +00:00
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can run supermarket profiles from inspec.yml' do
|
2016-09-21 12:09:57 +00:00
|
|
|
out = inspec("exec --no-write-lockfile #{File.join(profile_path, 'supermarket-dep')}")
|
2016-09-13 10:03:24 +00:00
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m\n"
|
|
|
|
end
|
|
|
|
end
|
2016-09-14 07:41:19 +00:00
|
|
|
|
|
|
|
describe 'when a dependency does not support our backend platform' do
|
|
|
|
it 'skips the controls from that profile' do
|
2016-09-21 12:09:57 +00:00
|
|
|
out = inspec("exec --no-write-lockfile #{File.join(profile_path, 'profile-support-skip')}")
|
2016-09-14 07:41:19 +00:00
|
|
|
out.stdout.force_encoding(Encoding::UTF_8).must_include "Summary: \e[32m0 successful\e[0m, \e[31m0 failures\e[0m, \e[37m2 skipped\e[0m\n"
|
|
|
|
end
|
|
|
|
end
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|