2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "inspec/resources/etc_hosts_allow_deny"
|
2017-09-25 17:49:04 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "Inspec::Resources::EtcHostsAllow" do
|
|
|
|
describe "EtcHostsAllow Paramaters" do
|
|
|
|
resource = load_resource("etc_hosts_allow")
|
|
|
|
it "Verify etc_hosts_allow filtering by `daemon`" do
|
|
|
|
entries = resource.where { daemon == "ALL" }
|
|
|
|
_(entries.client_list).must_include ["127.0.0.1", "[::1]"]
|
2017-09-25 17:49:04 +00:00
|
|
|
_(entries.options).must_equal [[]]
|
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
it "Verify etc_hosts_allow filtering by `client_list`" do
|
|
|
|
entries = resource.where { client_list == ["127.0.1.154", "[:fff:fAb0::]"] }
|
|
|
|
_(entries.daemon).must_equal %w{vsftpd sshd}
|
|
|
|
_(entries.options).must_include ["deny", "/etc/bin/"]
|
2017-09-25 17:49:04 +00:00
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
it "Verify etc_hosts_allow filtering by `options`" do
|
|
|
|
entries = resource.where { options == ["deny", "/etc/bin/"] }
|
|
|
|
_(entries.daemon).must_equal %w{vsftpd sshd}
|
|
|
|
_(entries.client_list).must_include ["127.0.1.154", "[:fff:fAb0::]"]
|
2017-09-25 17:49:04 +00:00
|
|
|
end
|
2019-10-24 19:07:26 +00:00
|
|
|
it "has a to_s" do
|
|
|
|
_(resource.to_s).must_equal "hosts.allow Configuration"
|
|
|
|
end
|
2017-09-25 17:49:04 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#parse_line" do
|
|
|
|
resource = load_resource("etc_hosts_allow")
|
|
|
|
it "parses a line with multiple clients" do
|
|
|
|
line = "foo: client1, client2 : some_option"
|
2019-02-12 23:02:54 +00:00
|
|
|
entry_properties = resource.send(:parse_line, line)
|
2019-06-11 22:24:35 +00:00
|
|
|
_(entry_properties["daemon"]).must_equal "foo"
|
|
|
|
_(entry_properties["client_list"]).must_equal %w{client1 client2}
|
2017-09-25 17:49:04 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "parses a line with one option" do
|
|
|
|
line = "foo: client1, client2 : some_option"
|
2019-02-12 23:02:54 +00:00
|
|
|
entry_properties = resource.send(:parse_line, line)
|
2019-06-11 22:24:35 +00:00
|
|
|
_(entry_properties["daemon"]).must_equal "foo"
|
|
|
|
_(entry_properties["client_list"]).must_equal %w{client1 client2}
|
|
|
|
_(entry_properties["options"]).must_equal ["some_option"]
|
2017-09-25 17:49:04 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "parses a line with multiple options" do
|
|
|
|
line = "foo: client1, client2 : some_option : other_option"
|
2019-02-12 23:02:54 +00:00
|
|
|
entry_properties = resource.send(:parse_line, line)
|
2019-06-11 22:24:35 +00:00
|
|
|
_(entry_properties["daemon"]).must_equal "foo"
|
|
|
|
_(entry_properties["client_list"]).must_equal %w{client1 client2}
|
|
|
|
_(entry_properties["options"]).must_equal %w{some_option other_option}
|
2017-09-25 17:49:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "Inspec::Resources::EtcHostsDeny" do
|
2021-08-30 23:49:46 +00:00
|
|
|
describe "EtcHostsDeny Parameters" do
|
2019-06-11 22:24:35 +00:00
|
|
|
resource = load_resource("etc_hosts_deny")
|
|
|
|
it "Verify etc_hosts_deny filtering by `daemon`" do
|
|
|
|
entries = resource.where { daemon == "ALL" }
|
|
|
|
_(entries.client_list).must_include ["127.0.0.1", "[::1]"]
|
2017-09-25 17:49:04 +00:00
|
|
|
_(entries.options).must_equal [[]]
|
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
it "Verify etc_hosts_deny filtering by `client_list`" do
|
|
|
|
entries = resource.where { client_list == ["127.0.1.154", "[:fff:fAb0::]"] }
|
|
|
|
_(entries.daemon).must_equal %w{vsftpd sshd}
|
|
|
|
_(entries.options).must_include ["deny", "/etc/bin/"]
|
2017-09-25 17:49:04 +00:00
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
it "Verify etc_hosts_deny filtering by `options`" do
|
|
|
|
entries = resource.where { options == ["deny", "/etc/bin/"] }
|
|
|
|
_(entries.daemon).must_equal %w{vsftpd sshd}
|
|
|
|
_(entries.client_list).must_include ["127.0.1.154", "[:fff:fAb0::]"]
|
2017-09-25 17:49:04 +00:00
|
|
|
end
|
2019-10-24 19:07:26 +00:00
|
|
|
it "has a to_s" do
|
|
|
|
_(resource.to_s).must_equal "hosts.deny Configuration"
|
|
|
|
end
|
2017-09-25 17:49:04 +00:00
|
|
|
end
|
|
|
|
end
|