improvement: file permission matchers add full description

This commit is contained in:
Dominik Richter 2015-06-21 11:06:39 +02:00
parent b942a1a103
commit 9e79b49f43
2 changed files with 64 additions and 0 deletions

63
lib/matchers/matchers.rb Normal file
View file

@ -0,0 +1,63 @@
# Copyright (c) 2015 Vulcano Security GmbH. All rights reserved.
RSpec::Matchers.define :be_readable do
match do |file|
file.readable?(@by_type, @by_user)
end
chain :by do |by_type|
@by_type = by_type
end
chain :by_user do |by_user|
@by_user = by_user
end
description do
res = "be readable"
res += " by #{@by_type}" unless @by_type.nil?
res += " by user #{@by_user}" unless @by_user.nil?
res
end
end
RSpec::Matchers.define :be_writable do
match do |file|
file.writable?(@by_type, @by_user)
end
chain :by do |by_type|
@by_type = by_type
end
chain :by_user do |by_user|
@by_user = by_user
end
description do
res = "be writable"
res += " by #{@by_type}" unless @by_type.nil?
res += " by user #{@by_user}" unless @by_user.nil?
res
end
end
RSpec::Matchers.define :be_executable do
match do |file|
file.executable?(@by_type, @by_user)
end
chain :by do |by_type|
@by_type = by_type
end
chain :by_user do |by_user|
@by_user = by_user
end
description do
res = "be executable"
res += " by #{@by_type}" unless @by_type.nil?
res += " by user #{@by_user}" unless @by_user.nil?
res
end
end

View file

@ -17,6 +17,7 @@ require 'resources/processes'
require 'resources/registry_key'
require 'resources/security_policy'
require 'resources/ssh_conf'
require 'matchers/matchers'
require 'vulcano/version'
require 'vulcano/rule'