CFINSPEC-94: Add new matchers belong_to_group/primary_group

Signed-off-by: Sonu Saha <sonu.saha@progress.com>
This commit is contained in:
Sonu Saha 2022-03-23 16:20:52 +05:30
parent 978e6ea798
commit 112e8cc061
2 changed files with 29 additions and 0 deletions

View file

@ -285,6 +285,22 @@ module Inspec::Resources
raise NotImplementedError
end
def belongs_to_primary_group?(group_name)
groupname = group_name
end
def belongs_to_group?(group_name)
groupsname = groups
is_valid_group = false
groupsname.each do |g|
if g == group_name
is_valid_group = true
break
end
end
is_valid_group
end
def to_s
"User #{@username}"
end

View file

@ -340,3 +340,16 @@ RSpec::Matchers.define :be_mounted do
end
end
end
# user resource belong_to matcher for serverspec compatibility
RSpec::Matchers.define :belong_to_primary_group do |group|
match do |user|
user.belongs_to_primary_group?(group)
end
end
RSpec::Matchers.define :belong_to_group do |group|
match do |user|
user.belongs_to_group?(group)
end
end