2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "inspec/resources/groups"
|
2018-10-18 20:48:30 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "groups resource on unix platform" do
|
|
|
|
let(:resource) { MockLoader.new(:ubuntu1404).load_resource("groups") }
|
2018-10-18 20:48:30 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "no arguments" do
|
|
|
|
it "finds all group names" do
|
2021-04-19 13:10:34 +00:00
|
|
|
_(resource.names.count).must_equal 4
|
|
|
|
_(resource.names).must_equal %w{root www-data GroupWithCaps sftpusers}
|
2018-10-18 20:48:30 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "finds all group gids" do
|
2021-04-19 13:10:34 +00:00
|
|
|
_(resource.gids.count).must_equal 4
|
|
|
|
_(resource.gids).must_equal [0, 33, 999, 1000]
|
2018-10-18 20:48:30 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "finds no group domains" do
|
2021-04-19 13:10:34 +00:00
|
|
|
_(resource.domains.count).must_equal 4
|
|
|
|
_(resource.domains).must_equal [nil, nil, nil, nil]
|
2018-10-18 20:48:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "where method" do
|
|
|
|
it "retrieves entries via gid" do
|
|
|
|
_(resource.where { gid == 33 }.entries.length).must_equal 1
|
2018-10-18 20:48:30 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "retrieves entries via name" do
|
|
|
|
_(resource.where { name == "www-data" }.entries.length).must_equal 1
|
2018-10-18 20:48:30 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "retrieves members via name" do
|
|
|
|
_(resource.where { name == "www-data" }.members).must_equal ["www-data,root"]
|
2018-10-18 20:48:30 +00:00
|
|
|
end
|
|
|
|
|
2021-04-23 08:17:55 +00:00
|
|
|
it "retrieves members_array via name" do
|
|
|
|
_(resource.where { name == "www-data" }.members_array).must_equal %w{www-data root}
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "retrieves entries via members regexp" do
|
|
|
|
_(resource.where { members =~ /root/ }.members).must_equal ["www-data,root"]
|
|
|
|
_(resource.where { members =~ /root/ }.exist?).must_equal true
|
2018-10-18 20:48:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "groups resource on windows platform" do
|
|
|
|
let(:resource) { MockLoader.new(:windows).load_resource("groups") }
|
2018-10-18 20:48:30 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "no arguments" do
|
|
|
|
it "finds all group names" do
|
2018-10-18 20:48:30 +00:00
|
|
|
_(resource.names.count).must_equal 4
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.names).must_equal ["Administrators", "Guests", "Power Users", "Users"]
|
2018-10-18 20:48:30 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "finds all group gids" do
|
2018-10-18 20:48:30 +00:00
|
|
|
_(resource.gids.count).must_equal 4
|
|
|
|
_(resource.gids).must_equal ["S-1-5-32-544", "S-1-5-32-546", "S-1-5-32-547", "S-1-5-32-545"]
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "finds no group domains" do
|
2018-10-18 20:48:30 +00:00
|
|
|
_(resource.domains.count).must_equal 4
|
2019-07-03 21:24:41 +00:00
|
|
|
_(resource.domains).must_equal %w{WIN-CIV7VMLVHLD WIN-CIV7VMLVHLD
|
|
|
|
WIN-CIV7VMLVHLD WIN-CIV7VMLVHLD}
|
2018-10-18 20:48:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "where method" do
|
|
|
|
it "retrieves entries via gid" do
|
|
|
|
_(resource.where { gid == "S-1-5-32-544" }.entries.length).must_equal 1
|
2018-10-18 20:48:30 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "retrieves entries via name" do
|
|
|
|
_(resource.where { name == "Administrators" }.entries.length).must_equal 1
|
2018-10-18 20:48:30 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "retrieves members via name" do
|
|
|
|
_(resource.where { name == "Administrators" }.members).must_equal ["Administrators", "Domain Admins"]
|
2021-04-23 08:17:55 +00:00
|
|
|
_(resource.where { name == "Administrators" }.members_array).must_equal ["Administrators", "Domain Admins"]
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.where { name == "Administrators" }.exist?).must_equal true
|
2018-10-18 20:48:30 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "retrieves groups via included members" do
|
|
|
|
res = _(resource.where { members.include? "Guest" }.raw_data)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(res.target.count).must_equal 1
|
|
|
|
_(res.target.first["name"]).must_equal "Guests"
|
2018-10-18 20:48:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|