diff --git a/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb b/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb index e14a1223..dcddd717 100644 --- a/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb +++ b/lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb @@ -17,7 +17,17 @@ PuppetLint.new_check(:top_scope_facts) do def check - whitelist = ['trusted', 'facts'] + (PuppetLint.configuration.top_scope_variables || []) + whitelist = ['trusted', 'facts', 'architecture', 'augeasversion', 'bios_release_date', 'bios_vendor', 'bios_version', + 'boardassettag', 'boardmanufacturer', 'boardproductname', 'boardserialnumber', 'chassisassettag', 'chassistype', 'domain', + 'fqdn', 'gid', 'hardwareisa', 'hardwaremodel', 'hostname', 'id', 'ipaddress', 'ipaddress6', 'lsbdistcodename', + 'lsbdistdescription', 'lsbdistid', 'lsbdistrelease', 'lsbmajdistrelease', 'lsbminordistrelease', 'lsbrelease', + 'macaddress', 'macosx_buildversion', 'macosx_productname', 'macosx_productversion', 'macosx_productversion_major', + 'macosx_productversion_minor', 'manufacturer', 'memoryfree', 'memorysize', 'netmask', 'netmask6', 'network', 'network6', + 'operatingsystem', 'operatingsystemmajrelease', 'operatingsystemrelease', 'osfamily', 'physicalprocessorcount', + 'processorcount', 'productname', 'rubyplatform', 'rubysitedir', 'rubyversion', 'selinux', 'selinux_config_mode', + 'selinux_config_policy', 'selinux_current_mode', 'selinux_enforced', 'selinux_policyversion', 'serialnumber', + 'swapencrypted', 'swapfree', 'swapsize', 'system32', 'uptime', 'uptime_days', 'uptime_hours', 'uptime_seconds', + 'uuid', 'xendomains', 'zonename'] + (PuppetLint.configuration.top_scope_variables || []) whitelist = whitelist.join('|') tokens.select { |x| TOP_SCOPE_FACTS_VAR_TYPES.include?(x.type) }.each do |token| next unless %r{^::}.match?(token.value) diff --git a/spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb b/spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb index 43d477ef..a982a7a2 100644 --- a/spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb +++ b/spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb @@ -37,26 +37,10 @@ end context 'fact variable using top scope' do - let(:code) { '$::operatingsystem' } + let(:code) { '$::fqdn' } - it 'onlies detect a single problem' do - expect(problems).to have(1).problem - end - - it 'creates a warning' do - expect(problems).to contain_warning(msg).on_line(1).in_column(1) - end - end - - context 'fact variable using top scope with curly braces in double quote' do - let(:code) { '"${::operatingsystem}"' } - - it 'onlies detect a single problem' do - expect(problems).to have(1).problem - end - - it 'creates a warning' do - expect(problems).to contain_warning(msg).on_line(1).in_column(4) + it 'does not detect a single problem' do + expect(problems).to have(0).problem end end @@ -126,34 +110,6 @@ end end - context 'fact variable using top scope' do - let(:code) { '$::operatingsystem' } - - it 'onlies detect a single problem' do - expect(problems).to have(1).problem - end - - it 'fixes the problem' do - expect(problems).to contain_fixed(msg).on_line(1).in_column(1) - end - - it 'shoulds use the facts hash' do - expect(manifest).to eq("$facts['operatingsystem']") - end - end - - context 'fact variable using top scope with curly braces in double quote' do - let(:code) { '"${::operatingsystem}"' } - - it 'fixes the problem' do - expect(problems).to contain_fixed(msg).on_line(1).in_column(4) - end - - it 'shoulds use the facts hash' do - expect(manifest).to eq('"${facts[\'operatingsystem\']}"') - end - end - context 'with custom top scope fact variables' do before(:each) do PuppetLint.configuration.top_scope_variables = ['location', 'role']