mirror of
https://github.com/inspec/inspec
synced 2024-11-23 13:13:22 +00:00
added file permission by user check for hp-ux
This commit is contained in:
parent
75534fdaa5
commit
1330e09df5
3 changed files with 25 additions and 1 deletions
|
@ -138,6 +138,8 @@ module Inspec::Resources
|
|||
perm_cmd = "sudo -u #{user} test -#{flag} #{path}"
|
||||
elsif inspec.os.aix?
|
||||
perm_cmd = "su #{user} -c test -#{flag} #{path}"
|
||||
elsif inspec.os.hpux?
|
||||
perm_cmd = "su #{user} -c \"test -#{flag} #{path}\""
|
||||
else
|
||||
return skip_resource 'The `file` resource does not support `by_user` on your OS.'
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ module Inspec::Resources
|
|||
"
|
||||
|
||||
# reuse helper methods from backend
|
||||
%w{aix? redhat? debian? suse? bsd? solaris? linux? unix? windows?}.each do |os_family|
|
||||
%w{aix? redhat? debian? suse? bsd? solaris? linux? unix? windows? hpux?}.each do |os_family|
|
||||
define_method(os_family.to_sym) do
|
||||
inspec.backend.os.send(os_family)
|
||||
end
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
require 'helper'
|
||||
require 'inspec/resource'
|
||||
require 'pry'
|
||||
|
||||
def shared_file_permission_tests(method_under_test)
|
||||
it 'returns false if the file does not exist' do
|
||||
|
@ -143,6 +144,27 @@ describe Inspec::Resources::FileResource do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'when on hpux' do
|
||||
before do
|
||||
MockLoader.mock_os(resource, :hpux)
|
||||
end
|
||||
|
||||
it 'executes a properly formatted command' do
|
||||
MockLoader.mock_command(resource, "su user -c \"test -flag /fakepath/fakefile\"", exit_status: 0)
|
||||
resource.send(:check_file_permission_by_user, 'user', 'flag')
|
||||
end
|
||||
|
||||
it 'returns true when the cmd exits 0' do
|
||||
MockLoader.mock_command(resource, "su user -c \"test -flag /fakepath/fakefile\"", exit_status: 0)
|
||||
resource.send(:check_file_permission_by_user, 'user', 'flag').must_equal(true)
|
||||
end
|
||||
|
||||
it 'returns false when the cmd exits non-zero' do
|
||||
MockLoader.mock_command(resource, "su user -c \"test -flag /fakepath/fakefile\"", exit_status: 1)
|
||||
resource.send(:check_file_permission_by_user, 'user', 'flag').must_equal(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when not on linux or freebsd' do
|
||||
before do
|
||||
MockLoader.mock_os(resource, :undefined)
|
||||
|
|
Loading…
Reference in a new issue