ensure metadata release entry is a string, even if yml thinks it is a float

Signed-off-by: Christoph Hartmann <chris@lollyrock.com>
This commit is contained in:
Christoph Hartmann 2016-11-20 11:38:27 -07:00 committed by Dominik Richter
parent bc7d176624
commit e3347f0ef0
2 changed files with 22 additions and 2 deletions

View file

@ -68,6 +68,7 @@ module Inspec
os.method(family_check).call
)
# ensure we do have a string if we have a non-nil value eg. 16.06
release_ok = release.nil? || os[:release] == release
# we want to make sure that all matchers are true
@ -143,7 +144,9 @@ module Inspec
def self.finalize_supports_elem(elem, logger)
case x = elem
when Hash then x
when Hash
x[:release] = x[:release].to_s if x[:release]
x
when Array
logger.warn(
'Failed to read supports entry that is an array. Please use '\
@ -162,7 +165,7 @@ module Inspec
def self.finalize_supports(supports, logger)
case x = supports
when Hash then [x]
when Hash then [finalize_supports_elem(x, logger)]
when Array then x.map { |e| finalize_supports_elem(e, logger) }.compact
when nil then []
else

View file

@ -43,6 +43,18 @@ describe 'metadata with supported operating systems' do
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_transport?(backend).must_equal true
@ -99,6 +111,11 @@ describe 'metadata with supported operating systems' do
m.supports_transport?(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_transport?(backend).must_equal true
end
it 'reject unsupported os' do
m = supports_meta({ 'os-name' => 'windows' })
m.supports_transport?(backend).must_equal false