mirror of
https://github.com/inspec/inspec
synced 2024-11-26 14:40:26 +00:00
Members and members array made case insensitive for group resources
Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
This commit is contained in:
parent
964fdacbee
commit
eb7e7305f4
2 changed files with 31 additions and 3 deletions
|
@ -22,6 +22,18 @@ module Inspec::Resources
|
|||
end
|
||||
end
|
||||
|
||||
# Class defined to check for members without case-sensitivity
|
||||
class Members < Array
|
||||
def initialize(group_members)
|
||||
@group_members = group_members
|
||||
super
|
||||
end
|
||||
|
||||
def include?(user)
|
||||
!(@group_members.select { |group_member| group_member.casecmp?(user) }.empty?)
|
||||
end
|
||||
end
|
||||
|
||||
class Groups < Inspec.resource(1)
|
||||
include GroupManagementSelector
|
||||
|
||||
|
@ -82,6 +94,7 @@ module Inspec::Resources
|
|||
# its('gid') { should eq 0 }
|
||||
# end
|
||||
#
|
||||
|
||||
class Group < Inspec.resource(1)
|
||||
include GroupManagementSelector
|
||||
|
||||
|
@ -118,11 +131,13 @@ module Inspec::Resources
|
|||
end
|
||||
|
||||
def members
|
||||
flatten_entry(group_info, "members") || empty_value_for_members
|
||||
members_list = flatten_entry(group_info, "members") || empty_value_for_members
|
||||
inspec.os.windows? ? Members.new(members_list) : members_list
|
||||
end
|
||||
|
||||
def members_array
|
||||
flatten_entry(group_info, "members_array") || []
|
||||
members_list = flatten_entry(group_info, "members_array") || []
|
||||
inspec.os.windows? ? Members.new(members_list) : members_list
|
||||
end
|
||||
|
||||
def local
|
||||
|
|
|
@ -69,10 +69,23 @@ describe "Inspec::Resources::Group" do
|
|||
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
|
||||
|
||||
it "verify members insensitivity on windows" do
|
||||
resource = MockLoader.new(:windows).load_resource("group", "administrators")
|
||||
_(resource.exists?).must_equal true
|
||||
_(resource.members).must_include "administrators"
|
||||
_(resource.members).must_include "domain admins"
|
||||
end
|
||||
|
||||
it "verify members_array insensitivity on windows" do
|
||||
resource = MockLoader.new(:windows).load_resource("group", "administrators")
|
||||
_(resource.exists?).must_equal true
|
||||
_(resource.members_array).must_include "administrators"
|
||||
_(resource.members_array).must_include "domain admins"
|
||||
end
|
||||
|
||||
it "verify power users group on windows" do
|
||||
resource = MockLoader.new(:windows).load_resource("group", "Power Users")
|
||||
_(resource.exists?).must_equal true
|
||||
|
|
Loading…
Reference in a new issue