mirror of
https://github.com/inspec/inspec
synced 2024-11-10 15:14:23 +00:00
complete all file tests
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
parent
29a143a67f
commit
c9fcb2913a
6 changed files with 140 additions and 14 deletions
|
@ -18,9 +18,9 @@ module Vulcano::Resources
|
|||
content mtime size selinux_label
|
||||
mounted? immutable? product_version file_version version?
|
||||
md5sum sha256sum
|
||||
}.each do |name|
|
||||
define_method name.to_sym do |*args|
|
||||
@file.method(name.to_sym).call(*args)
|
||||
}.each do |m|
|
||||
define_method m.to_sym do |*args|
|
||||
@file.method(m.to_sym).call(*args)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -62,7 +62,7 @@ module Vulcano::Resources
|
|||
end
|
||||
|
||||
def to_s
|
||||
'Path "#{@path}"'
|
||||
"Path '#{@path}'"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -186,7 +186,7 @@ module Vulcano::Backends
|
|||
path = Shellwords.escape(@path)
|
||||
raw_type = Specinfra::Runner.run_command("stat -c %f #{path}").stdout
|
||||
tmask = raw_type.to_i(16)
|
||||
res = TYPES.find{|name, mask| mask & tmask == mask}
|
||||
res = TYPES.find{|x, mask| mask & tmask == mask}
|
||||
return :unknown if res.nil?
|
||||
res[0]
|
||||
end
|
||||
|
@ -200,16 +200,16 @@ module Vulcano::Backends
|
|||
end
|
||||
|
||||
def owner
|
||||
Specinfra::Runner.get_file_owner(@path).stdout
|
||||
Specinfra::Runner.get_file_owner_user(@path).stdout.strip
|
||||
end
|
||||
|
||||
def group
|
||||
Specinfra::Runner.get_file_group(@path).stdout
|
||||
Specinfra::Runner.get_file_owner_group(@path).stdout.strip
|
||||
end
|
||||
|
||||
def link_target
|
||||
path = Shellwords.escape(@path)
|
||||
Specinfra::Runner.run_command("readlink #{path}").stdout
|
||||
Specinfra::Runner.run_command("readlink #{path}").stdout.strip
|
||||
end
|
||||
|
||||
def content
|
||||
|
@ -228,8 +228,8 @@ module Vulcano::Backends
|
|||
Specinfra::Runner.get_file_selinuxlabel(@path).stdout.strip
|
||||
end
|
||||
|
||||
def mounted?(opts, only_with)
|
||||
Specinfra::Runner.check_file_is_mounted(@name, opts, only_with)
|
||||
def mounted?(opts = {}, only_with = nil)
|
||||
Specinfra::Runner.check_file_is_mounted(@path, opts, only_with)
|
||||
end
|
||||
|
||||
def immutable?
|
||||
|
|
|
@ -9,16 +9,16 @@ module Vulcano::Plugins
|
|||
Vulcano::Plugins::Backend.__register(name, self)
|
||||
end
|
||||
|
||||
def self.__register(name, obj)
|
||||
def self.__register(id, obj)
|
||||
# raise errors for all missing methods
|
||||
%w{ file run_command os }.each do |m|
|
||||
next if obj.public_method_defined?(m.to_sym)
|
||||
obj.send(:define_method, m.to_sym) do |*args|
|
||||
raise NotImplementedError.new("Backend must implement the #{name}() method.")
|
||||
raise NotImplementedError.new("Backend must implement the #{m}() method.")
|
||||
end
|
||||
end
|
||||
|
||||
Vulcano::Backend.registry[name] = obj
|
||||
Vulcano::Backend.registry[id] = obj
|
||||
end
|
||||
|
||||
class FileCommon
|
||||
|
|
|
@ -22,6 +22,10 @@ module Vulcano
|
|||
@rules = []
|
||||
@profile_id = profile_id
|
||||
@conf = Vulcano::Backend.target_config(normalize_map(conf))
|
||||
|
||||
# global reset
|
||||
RSpec.world.reset
|
||||
|
||||
configure_output
|
||||
configure_backend
|
||||
end
|
||||
|
|
|
@ -41,7 +41,7 @@ class DockerTester
|
|||
end
|
||||
|
||||
def test_container(container_id)
|
||||
opts = { target: "docker://#{container_id}" }
|
||||
opts = { 'target' => "docker://#{container_id}" }
|
||||
runner = Vulcano::Runner.new(nil, opts)
|
||||
runner.add_tests(@tests)
|
||||
runner.run
|
||||
|
|
|
@ -1,4 +1,126 @@
|
|||
|
||||
describe file('/tmp') do
|
||||
it { should exist }
|
||||
end
|
||||
|
||||
describe file('/tmpest') do
|
||||
it { should_not exist }
|
||||
end
|
||||
|
||||
describe file('/tmp') do
|
||||
its(:type) { should eq :directory }
|
||||
it { should be_directory }
|
||||
end
|
||||
|
||||
describe file('/proc/version') do
|
||||
its(:type) { should eq :file }
|
||||
it { should be_file }
|
||||
it { should_not be_directory }
|
||||
end
|
||||
|
||||
describe file('/dev/stdout') do
|
||||
its(:type) { should eq :symlink }
|
||||
it { should be_symlink }
|
||||
it { should_not be_file }
|
||||
it { should_not be_directory }
|
||||
end
|
||||
|
||||
describe file('/dev/zero') do
|
||||
its(:type) { should eq :character_device }
|
||||
it { should be_character_device }
|
||||
it { should_not be_file }
|
||||
it { should_not be_directory }
|
||||
end
|
||||
|
||||
# describe file('...') do
|
||||
# its(:type) { should eq :block_device }
|
||||
# it { should be_block_device }
|
||||
# end
|
||||
|
||||
# describe file('...') do
|
||||
# its(:type) { should eq :socket }
|
||||
# it { should be_socket }
|
||||
# end
|
||||
|
||||
# describe file('...') do
|
||||
# its(:type) { should eq :pipe }
|
||||
# it { should be_pipe }
|
||||
# end
|
||||
|
||||
describe file('/dev') do
|
||||
its(:mode) { should eq 00755 }
|
||||
end
|
||||
|
||||
describe file('/dev') do
|
||||
it { should be_mode 00755 }
|
||||
end
|
||||
|
||||
describe file('/root') do
|
||||
its(:owner) { should eq 'root' }
|
||||
end
|
||||
|
||||
describe file('/dev') do
|
||||
it { should be_owned_by 'root' }
|
||||
end
|
||||
|
||||
describe file('/root') do
|
||||
its(:group) { should eq 'root' }
|
||||
end
|
||||
|
||||
describe file('/dev') do
|
||||
it { should be_grouped_into 'root' }
|
||||
end
|
||||
|
||||
describe file('/dev/kcore') do
|
||||
its(:link_target) { should eq '/proc/kcore' }
|
||||
end
|
||||
|
||||
describe file('/dev/kcore') do
|
||||
it { should be_linked_to '/proc/kcore' }
|
||||
end
|
||||
|
||||
describe file('/proc/cpuinfo') do
|
||||
its(:content) { should match /^processor/ }
|
||||
end
|
||||
|
||||
describe file('/').mtime.to_i do
|
||||
it { should <= Time.now.to_i }
|
||||
it { should >= Time.now.to_i - 1000}
|
||||
end
|
||||
|
||||
describe file('/') do
|
||||
its(:size) { should be > 64 }
|
||||
its(:size) { should be < 10240 }
|
||||
end
|
||||
|
||||
describe file('/proc/cpuinfo') do
|
||||
its(:size) { should be 0 }
|
||||
end
|
||||
|
||||
# @TODO selinux_label
|
||||
|
||||
describe file('/proc') do
|
||||
it { should be_mounted }
|
||||
end
|
||||
|
||||
describe file('/proc/cpuinfo') do
|
||||
it { should_not be_mounted }
|
||||
end
|
||||
|
||||
# @TODO immutable?
|
||||
# @TODO product_version
|
||||
# @TODO file_version
|
||||
# @TODO version?
|
||||
|
||||
require 'digest'
|
||||
cpuinfo = file('/proc/cpuinfo').content
|
||||
|
||||
md5sum = Digest::MD5.hexdigest(cpuinfo)
|
||||
describe file('/proc/cpuinfo') do
|
||||
its(:md5sum) { should eq md5sum }
|
||||
end
|
||||
|
||||
sha256sum = Digest::SHA256.hexdigest(cpuinfo)
|
||||
describe file('/proc/cpuinfo') do
|
||||
its(:sha256sum) { should eq sha256sum }
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue