2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "inspec/resources/xinetd_conf"
|
|
|
|
|
|
|
|
describe "Inspec::Resources::XinetdConf" do
|
|
|
|
let(:resource) { load_resource("xinetd_conf") }
|
|
|
|
it "reads default params" do
|
|
|
|
d = resource.params["defaults"]
|
2016-02-26 12:19:16 +00:00
|
|
|
_(d).must_be_kind_of SimpleConfig
|
2019-06-11 22:24:35 +00:00
|
|
|
_(d.params["instances"]).must_equal "50"
|
|
|
|
_(d.params["log_type"]).must_equal "SYSLOG daemon info"
|
2016-02-26 12:19:16 +00:00
|
|
|
_(d.params.length).must_equal 2
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "with services from child configs" do
|
|
|
|
it "has one service name" do
|
2017-01-31 12:37:43 +00:00
|
|
|
_(resource.services.uniq).must_equal %w{chargen echo}
|
2016-02-26 12:19:16 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "has multiple service definitions" do
|
2017-01-31 12:37:43 +00:00
|
|
|
_(resource.ids).must_equal %w{chargen-stream chargen-dgram echo-stream echo-dgram}
|
2016-02-26 12:19:16 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "can filter by name" do
|
|
|
|
_(resource.services("not here").services).must_be_empty
|
2016-02-26 12:19:16 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "can chain filters" do
|
|
|
|
one = resource.services("chargen").socket_types("dgram")
|
2016-03-12 20:43:38 +00:00
|
|
|
_(one.services.length).must_equal 1
|
2016-02-26 12:19:16 +00:00
|
|
|
_(one.ids).must_equal %w{chargen-dgram}
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "get all protocols for echo" do
|
|
|
|
one = resource.services("echo")
|
2017-01-31 12:37:43 +00:00
|
|
|
_(one.protocols).must_equal %w{tcp udp}
|
|
|
|
_(one.ids).must_equal %w{echo-stream echo-dgram}
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "get all protocols for chargen, including derived from socket_type" do
|
|
|
|
one = resource.services("chargen")
|
2017-02-01 11:15:52 +00:00
|
|
|
_(one.protocols).must_equal %w{tcp udp}
|
|
|
|
_(one.ids).must_equal %w{chargen-stream chargen-dgram}
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "params has only the protocols parsed from the config files" do
|
|
|
|
one = resource.params["services"]["chargen"].map { |x| x.params["protocol"] }
|
2017-02-01 11:15:52 +00:00
|
|
|
# in this example(CentOS), protocol is not defined in the config
|
|
|
|
_(one).must_equal [nil, nil]
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "can filter by protocols" do
|
|
|
|
one = resource.services("echo")
|
2017-01-31 12:37:43 +00:00
|
|
|
_(one.protocols(/tcp.*/).ids).must_equal %w{echo-stream}
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "checks if all are disabled on one disabled service" do
|
|
|
|
one = resource.ids("chargen-stream")
|
2016-02-26 12:19:16 +00:00
|
|
|
_(one.disabled?).must_equal true
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "checks if all are disabled on multiple mixed" do
|
2016-02-26 12:19:16 +00:00
|
|
|
_(resource.disabled?).must_equal false
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "checks if all are enabled on one enabled service" do
|
2016-02-26 12:29:45 +00:00
|
|
|
one = resource.ids(/dgram$/)
|
2016-02-26 12:19:16 +00:00
|
|
|
_(one.enabled?).must_equal true
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "checks if all are enabled on one enabled service" do
|
2016-02-26 12:29:45 +00:00
|
|
|
one = resource.ids(/stream$/)
|
|
|
|
_(one.enabled?).must_equal false
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "checks if all are enabled on multiple mixed" do
|
2016-02-26 12:19:16 +00:00
|
|
|
_(resource.enabled?).must_equal false
|
|
|
|
end
|
|
|
|
end
|
2016-07-27 11:49:45 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "with single services and no child configs" do
|
2019-05-31 21:59:06 +00:00
|
|
|
let(:resource) { load_resource("xinetd_conf", "/etc/xinetd.d/chargen-stream") }
|
2016-07-27 11:49:45 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "checks if all are disabled on one disabled service" do
|
|
|
|
one = resource.ids("chargen-stream")
|
2016-07-27 11:49:45 +00:00
|
|
|
_(one.disabled?).must_equal true
|
|
|
|
end
|
|
|
|
end
|
2016-02-26 12:19:16 +00:00
|
|
|
end
|