mirror of
https://github.com/inspec/inspec
synced 2024-11-24 05:33:17 +00:00
2bbcdbde9b
* Remove deprecated yumrepo. (#3435) * Remove deprecations for cli `--format` and metadata.rb (#3452) * Remove deprecated database_helpers stderr/stdout methods. Update deprecation text for processes/apache. * Remove deprecations for `--format` and metadata.rb Remove deprecated `format` code. Remove deprecated code test and change json-config format test to use reporter. Remove deprecated metadata.rb code Remove deprecation notice for old supports syntax. Deprecate metadata.rb from source_reader Remove rubocop disables as they are no longer required for this code block. Remove deprecated legacy metadata.rb mock profiles. Remove deprecated metadata.rb profile tests. Remove deprecated yumrepo test. * Allow inspec-3.0 branch to be tested. * Allow appveyor to test inspec-3.0 branch * Change runner tests to use reporter rather than format. Remove deprecated `supports: linux` tests. * Remove skip from inherited profiles from showing up in reporting (breaking change) (#3332) * Skip loading dependency profiles if they are unsupported on the current platform. Skip loading dependencies if they are unsupported on the current platform. Wrap our log and next in a conditional checking if the platform is supported. Change a `if !` into a `unless` Check if the backend is a Train Mock Connection and if so say that the profile does support the platform. While iterating through tests being loaded skip when the platform is unsupported. We now log a WARN when a profile is skipped due to unsupported platform, so lets check that. Modified existing test to log that there are 0 skipped tests, instead of 2. Add functional test that loads profile-support-skip with a json reporter to check that our controls are not loaded and that stderr contains our warning. * Rather than iterating through each test return before recursion if the platform is unsupported. * Resolve tests using a supported platform different from testing platform Add a control to `test/unit/mock/profiles/complete-profile` that would work on any OS with a Internet connection. This allows the profile to execute on any OS with success. `filesystem_spec.rb` was a control that would only work on Linux and some BSD's. We want profile tests to consistently work across development and testing platforms, and not get 'skipped' in some cases. Travis-CI tests on Linux, Inspec Dev team uses Linux and MacOS, Appveyor tests on Windows Also Updated `file_provider_test.rb` for `complete-profile` content changes. If you `MockLoader.load_profile` on a unsupported platform you might not hit the usual skip. Lets handle situations where the tests array in Profile#load_checks_params could be nil. * Use safe navigation rather than checking if tests is nil. Update tests to point to unsupported_inspec and account for WARN changes. Make unsupported_inspec profile support os-family 'unsupported_inspec' * Fix skip bug when using include/require controls. (#3487) * Fix skip bug when using include/require controls. * fix test and feedback. * Remove need for UUID detection for Automate report (#3507) * Add json metadata for skipped profiles (#3495) * Add skip metadata to json reports * Unify skip messages. * Update with status field. * Add testing. * Fix tests. * lint * Add skip exit codes for profile skips. * Update website for 3.0 launch Add `plugins` to sidebar. Change 2.0 -> 3.0 in slim files. Update 3.0 features list. * Fix comments * Update float to numeric. * Change Float to numeric. * updated feature list and impact doc * Change "What's new in InSpec 3.0" -> "Announcing InSpec 3.0" * Bump VERSION to 3.0.0 (#3511) * Remove 3.0 testing checks. * Fix azure link.
250 lines
8.7 KiB
Ruby
250 lines
8.7 KiB
Ruby
# encoding: utf-8
|
|
# author: Dominik Richter
|
|
# author: Christoph Hartmann
|
|
|
|
require 'helper'
|
|
require 'inspec/metadata'
|
|
|
|
describe 'metadata with supported operating systems' do
|
|
let(:logger) { Minitest::Mock.new }
|
|
let(:empty_options) { {} }
|
|
|
|
def supports_meta(params)
|
|
res = Inspec::Metadata.from_yaml('mock', "---", nil, logger)
|
|
# manually inject supported parameters
|
|
res.params[:supports] = params
|
|
Inspec::Metadata.finalize(res, 'mock', empty_options, logger)
|
|
res
|
|
end
|
|
|
|
describe 'running on ubuntu 14.04' do
|
|
let (:backend) { MockLoader.new(:ubuntu1404).backend }
|
|
|
|
it 'provides all metadata content' do
|
|
s = "---\nname: hello #{rand}"
|
|
res = Inspec::Metadata.from_yaml('mock', s, nil)
|
|
Inspec::Metadata.finalize(res, 'mock', empty_options)
|
|
res.content.must_equal(s)
|
|
end
|
|
|
|
it 'renders a YAML containing ERB' do
|
|
data = <<EOF
|
|
name: dummy
|
|
title: InSpec Profile
|
|
maintainer: The Authors
|
|
copyright: The Authors
|
|
copyright_email: you@example.com
|
|
license: Apache-2.0
|
|
summary: An InSpec Compliance Profile
|
|
version: 0.1.0
|
|
depends:
|
|
- name: inherit
|
|
url: "https://artifactory.com/artifactory/example-repo-local/inspec/0.4.1.tar.gz"
|
|
username: <%= ENV['USERNAME'] %>
|
|
password: <%= ENV['API_KEY'] %>
|
|
EOF
|
|
ENV['USERNAME'] = 'dummy_user'
|
|
ENV['API_KEY'] = 'dummy_pass'
|
|
res = Inspec::Metadata.from_yaml('mock', data, nil)
|
|
Inspec::Metadata.finalize(res, 'mock', empty_options)
|
|
res.params[:name].must_equal 'mock'
|
|
res.params[:depends][0][:name].must_equal 'inherit'
|
|
res.params[:depends][0][:url].must_equal 'https://artifactory.com/artifactory/example-repo-local/inspec/0.4.1.tar.gz'
|
|
res.params[:depends][0][:username].must_equal 'dummy_user'
|
|
res.params[:depends][0][:password].must_equal 'dummy_pass'
|
|
end
|
|
|
|
it 'finalizes a loaded metadata via Profile ID' do
|
|
res = Inspec::Metadata.from_yaml('mock', '---', nil)
|
|
Inspec::Metadata.finalize(res, 'mock', empty_options)
|
|
res.params[:name].must_equal('mock')
|
|
end
|
|
|
|
it 'finalizes a loaded metadata via Profile ID and overwrites the ID' do
|
|
res = Inspec::Metadata.from_yaml('mock', "---\nname: hello", nil)
|
|
Inspec::Metadata.finalize(res, 'mock', empty_options)
|
|
res.params[:name].must_equal('mock')
|
|
end
|
|
|
|
it 'reads the version from metadata' do
|
|
res = Inspec::Metadata.from_yaml('mock', "---\nversion: '1.1.0'", nil)
|
|
Inspec::Metadata.finalize(res, 'mock', empty_options)
|
|
res.params[:version].must_equal('1.1.0')
|
|
res.valid_version?(res.params[:version]).must_equal(true)
|
|
end
|
|
|
|
it 'does not accept invalid version from metadata' do
|
|
res = Inspec::Metadata.from_yaml('mock', "---\nversion: '1.1.0.1'", nil)
|
|
Inspec::Metadata.finalize(res, 'mock', empty_options)
|
|
res.params[:version].must_equal('1.1.0.1')
|
|
res.valid_version?(res.params[:version]).must_equal(false)
|
|
end
|
|
|
|
it 'finalizes a loaded metadata by turning strings into symbols' do
|
|
res = Inspec::Metadata.from_yaml('mock', "---\nauthor: world", nil)
|
|
Inspec::Metadata.finalize(res, 'mock', empty_options)
|
|
res.params[:author].must_equal('world')
|
|
end
|
|
|
|
it 'sets a default name with the original target if there is no name, title, or profile_id' do
|
|
res = Inspec::Metadata.from_yaml('mock', '---', nil, logger)
|
|
options = { target: '/path/to/tests' }
|
|
Inspec::Metadata.finalize(res, nil, options, logger)
|
|
res.params[:name].must_equal('tests from .path.to.tests')
|
|
end
|
|
|
|
it 'does not overwrite an existing name when name exists and profile_id is nil' do
|
|
res = Inspec::Metadata.from_yaml('mock', "\nname: my_name", nil)
|
|
options = { target: '/path/to/tests' }
|
|
Inspec::Metadata.finalize(res, nil, options, logger)
|
|
res.params[:name].must_equal('my_name')
|
|
end
|
|
|
|
it 'does not set a default name if a title is provided and profile_id is nil' do
|
|
res = Inspec::Metadata.from_yaml('mock', "\ntitle: my_title", nil)
|
|
options = { target: '/path/to/tests' }
|
|
Inspec::Metadata.finalize(res, nil, options, logger)
|
|
res.params[:title].must_equal('my_title')
|
|
res.params[:name].must_be_nil
|
|
end
|
|
|
|
it 'loads the support field from metadata' do
|
|
res = Inspec::Metadata.from_yaml('mock',
|
|
"---\nsupports:\n - os: ubuntu", nil)
|
|
res.params[:supports].must_equal([{ os: 'ubuntu' }])
|
|
end
|
|
|
|
it 'makes sure the supports release field is a string' do
|
|
res = Inspec::Metadata.from_yaml('mock',
|
|
"---\nsupports:\n - release: 12.02", nil)
|
|
res.params[:supports].must_equal([{ release: '12.02' }])
|
|
end
|
|
|
|
it 'makes sure the supports release field is nil if not configured' do
|
|
res = Inspec::Metadata.from_yaml('mock',
|
|
"---\nsupports:\n - release: ", nil)
|
|
res.params[:supports].must_equal([{ release: nil }])
|
|
end
|
|
|
|
it 'load a profile with empty supports clause' do
|
|
m = supports_meta(nil)
|
|
m.supports_platform?(backend).must_equal true
|
|
end
|
|
|
|
it 'loads a profile which supports os ubuntu' do
|
|
m = supports_meta({ 'os' => 'ubuntu' })
|
|
m.supports_platform?(backend).must_equal true
|
|
end
|
|
|
|
it 'loads a profile which supports os name ubuntu' do
|
|
m = supports_meta({ 'os-name' => 'ubuntu' })
|
|
m.supports_platform?(backend).must_equal true
|
|
end
|
|
|
|
it 'loads a profile which supports os family linux' do
|
|
m = supports_meta({ 'os-family' => 'linux' })
|
|
m.supports_platform?(backend).must_equal true
|
|
end
|
|
|
|
it 'loads a profile which supports release 14.04' do
|
|
m = supports_meta({ 'release' => '14.04' })
|
|
m.supports_platform?(backend).must_equal true
|
|
end
|
|
|
|
it 'rejects a profile which supports release 12.04' do
|
|
m = supports_meta({ 'release' => '12.04' })
|
|
m.supports_platform?(backend).must_equal false
|
|
end
|
|
|
|
it 'loads a profile which supports ubuntu 14.04' do
|
|
m = supports_meta({ 'os-name' => 'ubuntu', 'release' => '14.04' })
|
|
m.supports_platform?(backend).must_equal true
|
|
end
|
|
|
|
it 'loads a profile which supports ubuntu 14.*' do
|
|
m = supports_meta({ 'os-name' => 'ubuntu', 'release' => '14.*' })
|
|
m.supports_platform?(backend).must_equal true
|
|
end
|
|
|
|
it 'rejects a profile which supports ubuntu 12.04' do
|
|
m = supports_meta({ 'os-name' => 'ubuntu', 'release' => '12.04' })
|
|
m.supports_platform?(backend).must_equal false
|
|
end
|
|
|
|
it 'rejects a profile which supports ubuntu 12.*' do
|
|
m = supports_meta({ 'os-name' => 'ubuntu', 'release' => '12.*' })
|
|
m.supports_platform?(backend).must_equal false
|
|
end
|
|
|
|
it 'loads a profile which supports ubuntu float 14.04 as parsed by yml' do
|
|
m = supports_meta({ 'os-name' => 'ubuntu', 'release' => 14.04 })
|
|
m.supports_platform?(backend).must_equal true
|
|
end
|
|
|
|
it 'reject unsupported os' do
|
|
m = supports_meta({ 'os-name' => 'windows' })
|
|
m.supports_platform?(backend).must_equal false
|
|
end
|
|
|
|
it 'loads a profile which supports multiple families' do
|
|
m = supports_meta([
|
|
{ 'os-family' => 'windows' },
|
|
{ 'os-family' => 'unix' }
|
|
])
|
|
m.supports_platform?(backend).must_equal true
|
|
end
|
|
|
|
it 'loads a profile which supports multiple names' do
|
|
m = supports_meta([
|
|
{ 'os-family' => 'windows', 'os-name' => 'windows_2000'},
|
|
{ 'os-family' => 'unix', 'os-name' => 'ubuntu' }
|
|
])
|
|
m.supports_platform?(backend).must_equal true
|
|
end
|
|
|
|
it 'reject a profile which supports multiple families' do
|
|
m = supports_meta([
|
|
{ 'os-family' => 'windows' },
|
|
{ 'os-family' => 'redhat' }
|
|
])
|
|
m.supports_platform?(backend).must_equal false
|
|
end
|
|
end
|
|
|
|
describe 'testing the supported runtime' do
|
|
let(:current_version) { Inspec::VERSION }
|
|
let(:next_version) { Gem::Version.new(current_version).bump.to_s }
|
|
|
|
def version_meta(params)
|
|
res = Inspec::Metadata.from_yaml('mock', "---", nil, logger)
|
|
res.params[:inspec_version] = params
|
|
Inspec::Metadata.finalize(res, 'mock', empty_options, logger)
|
|
res
|
|
end
|
|
|
|
it 'returns true on testing the current version' do
|
|
m = version_meta(current_version)
|
|
m.supports_runtime?.must_equal true
|
|
end
|
|
|
|
it 'returns true on testing the current version' do
|
|
m = version_meta('= ' + current_version)
|
|
m.supports_runtime?.must_equal true
|
|
end
|
|
|
|
it 'returns true on testing >= current version' do
|
|
m = version_meta('>= ' + current_version)
|
|
m.supports_runtime?.must_equal true
|
|
end
|
|
|
|
it 'returns false on testing >= the next version' do
|
|
m = version_meta('>= ' + next_version)
|
|
m.supports_runtime?.must_equal false
|
|
end
|
|
|
|
it 'returns false on testing > the next version' do
|
|
m = version_meta('> ' + next_version)
|
|
m.supports_runtime?.must_equal false
|
|
end
|
|
end
|
|
end
|