mirror of
https://github.com/inspec/inspec
synced 2024-09-21 15:02:01 +00:00
add mount
resource
This commit is contained in:
parent
772df929f6
commit
a5acb03e49
6 changed files with 69 additions and 1 deletions
|
@ -44,6 +44,7 @@ require 'resources/kernel_module'
|
|||
require 'resources/kernel_parameter'
|
||||
require 'resources/limits_conf'
|
||||
require 'resources/login_def'
|
||||
require 'resources/mount'
|
||||
require 'resources/mysql'
|
||||
require 'resources/mysql_conf'
|
||||
require 'resources/mysql_session'
|
||||
|
|
45
lib/resources/mount.rb
Normal file
45
lib/resources/mount.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
# encoding: utf-8
|
||||
# author: Christoph Hartmann
|
||||
# author: Dominik Richter
|
||||
|
||||
require 'utils/simpleconfig'
|
||||
|
||||
class Mount < Inspec.resource(1)
|
||||
name 'mount'
|
||||
desc 'Use the mount InSpec audit resource to test if mount points.'
|
||||
example "
|
||||
describe mount('/') do
|
||||
it { should be_mounted }
|
||||
its('device') { should eq '/dev/mapper/VolGroup-lv_root' }
|
||||
its('type') { should eq 'ext4' }
|
||||
its('options') { should eq ['rw', 'mode=620'] }
|
||||
end
|
||||
"
|
||||
include MountParser
|
||||
|
||||
attr_reader :file
|
||||
|
||||
def initialize(path)
|
||||
@path = path
|
||||
@file = inspec.backend.file(@path)
|
||||
end
|
||||
|
||||
def mounted?
|
||||
file.mounted?
|
||||
end
|
||||
|
||||
def method_missing(name)
|
||||
return nil if !file.mounted?
|
||||
|
||||
mounted = file.mounted
|
||||
|
||||
# parse content if we are on linux
|
||||
@mount_options ||= parse_mount_options(mounted.stdout)
|
||||
|
||||
@mount_options[name]
|
||||
end
|
||||
|
||||
def to_s
|
||||
"Mount #{@path}"
|
||||
end
|
||||
end
|
|
@ -196,7 +196,8 @@ class MockLoader
|
|||
# apache_conf
|
||||
'find /etc/apache2/ports.conf -maxdepth 1 -type f' => cmd.call('find-apache2-ports-conf'),
|
||||
'find /etc/apache2/conf-enabled/*.conf -maxdepth 1 -type f' => cmd.call('find-apache2-conf-enabled'),
|
||||
|
||||
# mount
|
||||
"mount | grep -- ' on /'" => cmd.call("mount"),
|
||||
}
|
||||
|
||||
@backend
|
||||
|
|
1
test/unit/mock/cmd/mount
Normal file
1
test/unit/mock/cmd/mount
Normal file
|
@ -0,0 +1 @@
|
|||
/dev/xvda1 on / type ext4 (rw,discard)
|
|
@ -1,3 +1,7 @@
|
|||
# encoding: utf-8
|
||||
# author: Christoph Hartmann
|
||||
# author: Dominik Richter
|
||||
|
||||
require 'helper'
|
||||
require 'inspec/resource'
|
||||
|
||||
|
|
16
test/unit/resources/mount_test.rb
Normal file
16
test/unit/resources/mount_test.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
# encoding: utf-8
|
||||
# author: Christoph Hartmann
|
||||
# author: Dominik Richter
|
||||
|
||||
require 'helper'
|
||||
require 'inspec/resource'
|
||||
|
||||
describe Inspec::Resources::File do
|
||||
let(:resource) { load_resource('mount', '/') }
|
||||
|
||||
it 'parses the mount data properly' do
|
||||
resource.send(:device).must_equal('/dev/xvda1')
|
||||
resource.send(:type).must_equal('ext4')
|
||||
resource.send(:options).must_equal(['rw','discard'])
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue