2017-08-31 13:51:39 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
require 'helper'
|
|
|
|
require 'inspec/resource'
|
|
|
|
|
|
|
|
describe 'Inspec::Resources::EtcHosts' do
|
|
|
|
let(:resource) { load_resource('etc_hosts') }
|
2018-03-22 16:58:22 +00:00
|
|
|
|
|
|
|
let(:all_v4_hosts) do
|
|
|
|
%W{localhost localhost.localdomain localhost4 localhost4.localdomain4}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:all_v6_hosts) do
|
|
|
|
%W{localhost localhost.localdomain localhost6 localhost6.localdomain6}
|
|
|
|
end
|
|
|
|
|
2017-08-31 13:51:39 +00:00
|
|
|
it 'Verify etc_hosts filtering by `ip_address`' do
|
|
|
|
entries = resource.where { ip_address == '127.0.0.1' }
|
|
|
|
_(entries.primary_name).must_equal ['localhost']
|
2018-03-22 16:58:22 +00:00
|
|
|
_(entries.all_host_names).must_equal [all_v4_hosts]
|
2017-08-31 13:51:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'Verify etc_hosts filtering by `canonical_hostname`' do
|
|
|
|
entries = resource.where { primary_name == 'localhost' }
|
|
|
|
_(entries.ip_address).must_equal ['127.0.0.1', '::1']
|
2018-03-22 16:58:22 +00:00
|
|
|
_(entries.all_host_names).must_equal [all_v4_hosts, all_v6_hosts]
|
2017-08-31 13:51:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'Verify etc_hosts filtering by `all_host_names`' do
|
2018-03-22 16:58:22 +00:00
|
|
|
# direct reference all_v4_hosts fail in filter scope
|
|
|
|
expected_hosts = all_v4_hosts
|
|
|
|
|
|
|
|
entries = resource.where { all_host_names == expected_hosts }
|
2017-08-31 13:51:39 +00:00
|
|
|
_(entries.ip_address).must_equal ['127.0.0.1']
|
|
|
|
_(entries.primary_name).must_equal ['localhost']
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'Verify etc_hosts with no `all_host_names`' do
|
|
|
|
entries = resource.where { ip_address == '127.0.0.5'}
|
|
|
|
_(entries.primary_name).must_equal ['randomhost']
|
|
|
|
_(entries.all_host_names).must_equal [['randomhost']]
|
|
|
|
end
|
|
|
|
end
|