2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resources/groups"
|
2015-10-06 12:47:37 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "Inspec::Resources::Group" do
|
2015-10-06 12:47:37 +00:00
|
|
|
|
|
|
|
# ubuntu 14.04
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify group on ubuntu" do
|
|
|
|
resource = MockLoader.new(:ubuntu1404).load_resource("group", "root")
|
2015-10-06 12:47:37 +00:00
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.gid).must_equal 0
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify group on ubuntu with mixed case" do
|
|
|
|
resource = MockLoader.new(:ubuntu1404).load_resource("group", "GroupWithCaps")
|
2015-10-07 10:04:48 +00:00
|
|
|
_(resource.exists?).must_equal true
|
2017-08-30 20:02:45 +00:00
|
|
|
_(resource.gid).must_equal 999
|
2018-10-18 20:48:30 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify group on ubuntu with members" do
|
|
|
|
resource = MockLoader.new(:ubuntu1404).load_resource("group", "www-data")
|
2018-10-18 20:48:30 +00:00
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.members).must_equal "www-data,root"
|
2015-10-07 10:04:48 +00:00
|
|
|
end
|
|
|
|
|
2021-04-23 08:17:55 +00:00
|
|
|
it "verify group on ubuntu with members_array" do
|
|
|
|
resource = MockLoader.new(:ubuntu1404).load_resource("group", "www-data")
|
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.members_array).must_equal %w{www-data root}
|
|
|
|
end
|
|
|
|
|
2015-10-07 10:04:48 +00:00
|
|
|
# ubuntu with non-existent group
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify group on ubuntu" do
|
|
|
|
resource = MockLoader.new(:ubuntu1404).load_resource("group", "nogroup")
|
2015-10-07 10:04:48 +00:00
|
|
|
_(resource.exists?).must_equal false
|
2017-06-11 10:16:10 +00:00
|
|
|
_(resource.gid).must_be_nil
|
2015-10-07 10:04:48 +00:00
|
|
|
end
|
|
|
|
|
2015-10-06 12:47:37 +00:00
|
|
|
# mac
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify group on mac" do
|
2020-07-01 22:35:23 +00:00
|
|
|
resource = MockLoader.new(:macos10_10).load_resource("group", "root")
|
2015-10-06 12:47:37 +00:00
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.gid).must_equal 0
|
|
|
|
end
|
2015-10-06 12:50:55 +00:00
|
|
|
|
2019-07-30 00:33:25 +00:00
|
|
|
if osx?
|
|
|
|
it "actually verifies group on mac" do
|
2020-07-01 22:35:23 +00:00
|
|
|
resource = quick_resource(:group, :macos10_10, "staff")
|
2019-07-30 00:33:25 +00:00
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.members).must_include "root"
|
|
|
|
_(resource.members).must_include ENV["LOGNAME"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-07 10:04:48 +00:00
|
|
|
# freebsd
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify group on freebsd" do
|
|
|
|
resource = MockLoader.new(:freebsd10).load_resource("group", "root")
|
2015-10-07 10:04:48 +00:00
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.gid).must_equal 0
|
|
|
|
end
|
|
|
|
|
|
|
|
# windows with local group
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify administrator group on windows" do
|
|
|
|
resource = MockLoader.new(:windows).load_resource("group", "Administrators")
|
2015-10-07 10:04:48 +00:00
|
|
|
_(resource.exists?).must_equal true
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.gid).must_equal "S-1-5-32-544"
|
|
|
|
_(resource.members).must_equal ["Administrators", "Domain Admins"]
|
2018-05-31 17:37:44 +00:00
|
|
|
end
|
|
|
|
|
2021-09-17 06:50:24 +00:00
|
|
|
it "verify administrator group with case insensitivity handling on windows" do
|
|
|
|
resource = MockLoader.new(:windows).load_resource("group", "administrators")
|
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.gid).must_equal "S-1-5-32-544"
|
|
|
|
_(resource.members).must_equal ["Administrators", "Domain Admins"]
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify power users group on windows" do
|
|
|
|
resource = MockLoader.new(:windows).load_resource("group", "Power Users")
|
2018-05-31 17:37:44 +00:00
|
|
|
_(resource.exists?).must_equal true
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.gid).must_equal "S-1-5-32-547"
|
2018-05-31 17:37:44 +00:00
|
|
|
_(resource.members).must_equal []
|
2021-04-23 08:17:55 +00:00
|
|
|
_(resource.members_array).must_equal []
|
|
|
|
end
|
|
|
|
|
|
|
|
it "verify administrator group members_array property on windows" do
|
|
|
|
resource = MockLoader.new(:windows).load_resource("group", "Administrators")
|
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.gid).must_equal "S-1-5-32-544"
|
|
|
|
_(resource.members_array).must_equal ["Administrators", "Domain Admins"]
|
2015-10-07 10:04:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# windows non-existent group
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify non-existing group on windows" do
|
|
|
|
resource = MockLoader.new(:windows).load_resource("group", "dhcp")
|
2015-10-07 10:04:48 +00:00
|
|
|
_(resource.exists?).must_equal false
|
2017-06-11 10:16:10 +00:00
|
|
|
_(resource.gid).must_be_nil
|
2021-04-19 13:10:34 +00:00
|
|
|
_(resource.members).must_equal []
|
2021-04-23 08:17:55 +00:00
|
|
|
_(resource.members_array).must_equal []
|
2015-10-07 10:04:48 +00:00
|
|
|
end
|
|
|
|
|
2015-10-06 12:50:55 +00:00
|
|
|
# undefined
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify package handling on unsupported os" do
|
|
|
|
resource = MockLoader.new(:undefined).load_resource("group", "root")
|
2015-10-06 12:50:55 +00:00
|
|
|
_(resource.exists?).must_equal false
|
2017-06-11 10:16:10 +00:00
|
|
|
_(resource.gid).must_be_nil
|
2015-10-06 12:50:55 +00:00
|
|
|
end
|
2021-04-19 13:10:34 +00:00
|
|
|
|
|
|
|
# centos7
|
|
|
|
it "verify group on centos7 with members" do
|
|
|
|
resource = MockLoader.new(:centos7).load_resource("group", "sftpusers")
|
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.members).must_include "sftponly"
|
|
|
|
end
|
|
|
|
|
|
|
|
# centos with non-existent group member
|
|
|
|
it "verify non-existent group member on centos" do
|
|
|
|
resource = MockLoader.new(:centos7).load_resource("group", "root")
|
|
|
|
_(resource.exists?).must_equal true
|
2021-04-22 13:16:02 +00:00
|
|
|
_(resource.members).must_equal ""
|
2021-04-19 13:10:34 +00:00
|
|
|
end
|
2015-10-06 12:47:37 +00:00
|
|
|
end
|