2015-07-14 22:50:34 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# copyright: 2015, Vulcano Security GmbH
|
|
|
|
# license: All rights reserved
|
|
|
|
|
2015-06-21 09:06:39 +00:00
|
|
|
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
|
2015-09-03 18:35:23 +00:00
|
|
|
res = 'be readable'
|
2015-06-21 09:06:39 +00:00
|
|
|
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
|
2015-09-03 18:35:23 +00:00
|
|
|
res = 'be writable'
|
2015-06-21 09:06:39 +00:00
|
|
|
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
|
2015-09-03 18:35:23 +00:00
|
|
|
res = 'be executable'
|
2015-06-21 09:06:39 +00:00
|
|
|
res += " by #{@by_type}" unless @by_type.nil?
|
|
|
|
res += " by user #{@by_user}" unless @by_user.nil?
|
|
|
|
res
|
|
|
|
end
|
|
|
|
end
|
2015-07-14 22:50:34 +00:00
|
|
|
|
|
|
|
# matcher to check /etc/passwd, /etc/shadow and /etc/group
|
|
|
|
RSpec::Matchers.define :contain_legacy_plus do
|
|
|
|
match do |file|
|
|
|
|
file.content.match(/^\+:/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# verifies that no entry in an array contains a value
|
|
|
|
RSpec::Matchers.define :contain_match do |regex|
|
|
|
|
match do |arr|
|
2015-09-04 07:59:30 +00:00
|
|
|
arr.inject { |result, i|
|
2015-07-14 22:50:34 +00:00
|
|
|
match = i.match(regex)
|
|
|
|
result || i.match(/$/)
|
2015-09-04 07:59:30 +00:00
|
|
|
}
|
2015-07-14 22:50:34 +00:00
|
|
|
end
|
|
|
|
end
|
2015-07-15 13:16:28 +00:00
|
|
|
|
|
|
|
RSpec::Matchers.define :contain_duplicates do
|
|
|
|
match do |arr|
|
2015-09-04 07:59:30 +00:00
|
|
|
dup = arr.select { |element| arr.count(element) > 1 }
|
2015-07-15 13:16:28 +00:00
|
|
|
!dup.uniq.empty?
|
|
|
|
end
|
|
|
|
end
|