diff --git a/inspec.gemspec b/inspec.gemspec index df77e3e16..49ffc4a65 100644 --- a/inspec.gemspec +++ b/inspec.gemspec @@ -26,7 +26,7 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 2.3' - spec.add_dependency 'train', '~> 0.31', '>= 0.31.1' + spec.add_dependency 'train', '~> 0.32' spec.add_dependency 'thor', '~> 0.19' spec.add_dependency 'json', '>= 1.8', '< 3.0' spec.add_dependency 'method_source', '~> 0.8' diff --git a/lib/resources/os.rb b/lib/resources/os.rb index 68d2d021d..408ef5ef4 100644 --- a/lib/resources/os.rb +++ b/lib/resources/os.rb @@ -32,7 +32,7 @@ module Inspec::Resources # helper to collect a hash object easily def params { - name: @platform[:name], + name: name, family: @platform[:family], release: @platform[:release], arch: @platform[:arch], diff --git a/lib/resources/platform.rb b/lib/resources/platform.rb index bb41b42f8..970fd9ba9 100644 --- a/lib/resources/platform.rb +++ b/lib/resources/platform.rb @@ -19,16 +19,36 @@ module Inspec::Resources end # add helper methods for easy access of properties - %w{name family release arch}.each do |property| + %w{family release arch}.each do |property| define_method(property.to_sym) do @platform.send(property) end end - def [](name) + # This is a string override for platform.name. + # TODO: removed in inspec 2.0 + class NameCleaned < String + def ==(other) + if other =~ /[A-Z ]/ + cleaned = other.downcase.tr(' ', '_') + Inspec::Log.warn "[DEPRECATED] Platform names will become lowercase in InSpec 2.0. Please match on '#{cleaned}' instead of '#{other}'" + super(cleaned) + else + super(other) + end + end + end + + def name + NameCleaned.new(@platform.name) + end + + def [](key) # convert string to symbol - name = name.to_sym if name.is_a? String - @platform[name] + key = key.to_sym if key.is_a? String + return name if key == :name + + @platform[key] end def platform?(name) diff --git a/test/unit/resources/platform_test.rb b/test/unit/resources/platform_test.rb index f002a5442..f698479da 100644 --- a/test/unit/resources/platform_test.rb +++ b/test/unit/resources/platform_test.rb @@ -6,6 +6,25 @@ require 'inspec/resource' describe 'Inspec::Resources::Platform' do let(:resource) { resource = MockLoader.new(:ubuntu1504).load_resource('platform') } + describe 'NamedCleaned' do + let(:cleaner) { Inspec::Resources::PlatformResource::NameCleaned } + + it 'verify name cleaned with uppercase' do + name = cleaner.new('upper_case_with_spaces') + _(name == 'Upper Case with Spaces').must_equal true + end + + it 'verify name cleaned with uppercase fail' do + name = cleaner.new('upper_case_with_spaces') + _(name == 'Upper Case withFAIL Spaces').must_equal false + end + + it 'verify name cleaned with lowercase' do + name = cleaner.new('lower_case_with_underscore') + _(name == 'lower_case_with_underscore').must_equal true + end + end + it 'verify platform parsing on Ubuntu' do _(resource.name).must_equal 'ubuntu' _(resource.family).must_equal 'debian'