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
|
2018-10-18 20:48:30 +00:00
|
|
|
_(resource.names.count).must_equal 3
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.names).must_equal %w{root www-data GroupWithCaps}
|
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 3
|
|
|
|
_(resource.gids).must_equal [0, 33, 999]
|
|
|
|
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 3
|
|
|
|
_(resource.domains).must_equal [nil, nil, nil]
|
|
|
|
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
|
|
|
|
|
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-06-11 22:24:35 +00:00
|
|
|
_(resource.domains).must_equal ["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"]
|
|
|
|
_(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)
|
2018-10-18 20:48:30 +00:00
|
|
|
res.target.count.must_equal 1
|
2019-06-11 22:24:35 +00:00
|
|
|
res.target.first["name"].must_equal "Guests"
|
2018-10-18 20:48:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|