2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "inspec/resources/etc_group"
|
2015-09-05 20:25:25 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "Inspec::Resources::EtcGroup" do
|
|
|
|
let(:resource) { load_resource("etc_group") }
|
2015-09-05 20:25:25 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify /etc/group config parsing" do
|
2017-08-30 20:02:45 +00:00
|
|
|
_(resource.gids).must_equal [0, 33, 999]
|
|
|
|
_(resource.groups).must_equal %w{ root www-data GroupWithCaps }
|
2015-09-22 16:33:05 +00:00
|
|
|
_(resource.users).must_equal %w{ www-data root }
|
|
|
|
end
|
2015-09-05 20:25:25 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify group filter with no users" do
|
|
|
|
root_filter = resource.where(name: "root")
|
2015-10-06 12:00:19 +00:00
|
|
|
_(root_filter.gids).must_equal [0]
|
2019-06-11 22:24:35 +00:00
|
|
|
_(root_filter.groups).must_equal ["root"]
|
2015-09-22 16:33:05 +00:00
|
|
|
_(root_filter.users).must_equal []
|
|
|
|
end
|
2015-09-05 20:25:25 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify group filter with users" do
|
|
|
|
www_filter = resource.where(name: "www-data")
|
2015-10-06 12:00:19 +00:00
|
|
|
_(www_filter.gids).must_equal [33]
|
2019-06-11 22:24:35 +00:00
|
|
|
_(www_filter.groups).must_equal ["www-data"]
|
|
|
|
_(www_filter.users).must_equal ["www-data", "root"]
|
2015-09-22 16:33:05 +00:00
|
|
|
end
|
2015-09-05 20:25:25 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify group filter with wrong group" do
|
|
|
|
wrong_filter = resource.where(name: "wrong_group")
|
2015-09-22 16:33:05 +00:00
|
|
|
_(wrong_filter.gids).must_equal []
|
|
|
|
_(wrong_filter.groups).must_equal []
|
|
|
|
_(wrong_filter.users).must_equal []
|
2015-09-05 20:25:25 +00:00
|
|
|
end
|
2017-11-14 04:03:50 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify group filter with gid" do
|
2017-11-14 04:03:50 +00:00
|
|
|
www_filter = resource.where(gid: 33)
|
|
|
|
_(www_filter.gids).must_equal [33]
|
2019-06-11 22:24:35 +00:00
|
|
|
_(www_filter.groups).must_equal ["www-data"]
|
|
|
|
_(www_filter.users).must_equal ["www-data", "root"]
|
2017-11-14 04:03:50 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify group filter with wrong gid" do
|
2017-11-14 04:03:50 +00:00
|
|
|
www_filter = resource.where(group_id: 60)
|
|
|
|
_(www_filter.gids).must_equal []
|
|
|
|
_(www_filter.groups).must_equal []
|
|
|
|
_(www_filter.users).must_equal []
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify group filter with group members" do
|
|
|
|
www_filter = resource.where(users: "www-data,root")
|
2017-11-14 04:03:50 +00:00
|
|
|
_(www_filter.gids).must_equal [33]
|
2019-06-11 22:24:35 +00:00
|
|
|
_(www_filter.groups).must_equal ["www-data"]
|
|
|
|
_(www_filter.users).must_equal ["www-data", "root"]
|
2017-11-14 04:03:50 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify group filter with no group members" do
|
|
|
|
www_filter = resource.where(members: "")
|
2017-11-14 04:03:50 +00:00
|
|
|
_(www_filter.gids).must_equal [0, 999]
|
2019-06-11 22:24:35 +00:00
|
|
|
_(www_filter.groups).must_equal %w{root GroupWithCaps}
|
2017-11-14 04:03:50 +00:00
|
|
|
_(www_filter.users).must_equal []
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify group filter with wrong member" do
|
|
|
|
wrong_filter = resource.where(users: "wrong_member")
|
2017-11-14 04:03:50 +00:00
|
|
|
_(wrong_filter.gids).must_equal []
|
|
|
|
_(wrong_filter.groups).must_equal []
|
|
|
|
_(wrong_filter.users).must_equal []
|
|
|
|
end
|
2015-09-05 20:25:25 +00:00
|
|
|
end
|