mirror of
https://github.com/inspec/inspec
synced 2024-11-10 23:24:18 +00:00
Use only strings in resource examples, docs and tests
This commit is contained in:
parent
c5afdf46ce
commit
f78afe0d75
18 changed files with 75 additions and 75 deletions
|
@ -117,7 +117,7 @@ The following test shows how to audit machines running |mysql| to ensure that pa
|
|||
them to an attacker. Prevent this at all costs.
|
||||
'
|
||||
describe command('env') do
|
||||
its(:stdout) { should_not match(/^MYSQL_PWD=/) }
|
||||
its('stdout') { should_not match(/^MYSQL_PWD=/) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -364,7 +364,7 @@ The following examples show how to use this InSpec audit resource.
|
|||
|
||||
# syntax for auditd >= 2.3
|
||||
describe auditd_rules do
|
||||
its(:lines) { should contain_match(%r{-w /etc/ssh/sshd_config/}) }
|
||||
its('lines') { should contain_match(%r{-w /etc/ssh/sshd_config/}) }
|
||||
end
|
||||
|
||||
The syntax for recent auditd versions allows more precise tests, such as the following:
|
||||
|
@ -386,7 +386,7 @@ The syntax for recent auditd versions allows more precise tests, such as the fol
|
|||
end
|
||||
|
||||
describe auditd_rules.key('sshd_config') do
|
||||
its(:permissions) { should contain_match(/x/) }
|
||||
its('permissions') { should contain_match(/x/) }
|
||||
end
|
||||
|
||||
Note that filters can be chained, for example:
|
||||
|
@ -2045,7 +2045,7 @@ The following examples show how to use this InSpec audit resource.
|
|||
.. code-block:: ruby
|
||||
|
||||
describe kernel_parameter('net.ipv4.conf.all.forwarding') do
|
||||
its(:value) { should eq 1 }
|
||||
its('value') { should eq 1 }
|
||||
end
|
||||
|
||||
**Test if global forwarding is disabled for an IPv6 address**
|
||||
|
@ -2053,7 +2053,7 @@ The following examples show how to use this InSpec audit resource.
|
|||
.. code-block:: ruby
|
||||
|
||||
describe kernel_parameter('net.ipv6.conf.all.forwarding') do
|
||||
its(:value) { should eq 0 }
|
||||
its('value') { should eq 0 }
|
||||
end
|
||||
|
||||
**Test if an IPv6 address accepts redirects**
|
||||
|
@ -2061,7 +2061,7 @@ The following examples show how to use this InSpec audit resource.
|
|||
.. code-block:: ruby
|
||||
|
||||
describe kernel_parameter('net.ipv6.conf.interface.accept_redirects') do
|
||||
its(:value) { should eq 'true' }
|
||||
its('value') { should eq 'true' }
|
||||
end
|
||||
|
||||
|
||||
|
@ -2417,7 +2417,7 @@ The following examples show how to use this InSpec audit resource.
|
|||
|
||||
sql = mysql_session('my_user','password')
|
||||
describe sql.query('show databases like \'test\';') do
|
||||
its(:stdout) { should_not match(/test/) }
|
||||
its('stdout') { should_not match(/test/) }
|
||||
end
|
||||
|
||||
|
||||
|
@ -3148,12 +3148,12 @@ A ``passwd`` |inspec resource| block declares one (or more) users and associated
|
|||
.. code-block:: ruby
|
||||
|
||||
describe passwd do
|
||||
its(:users) { should_not include 'forbidden_user' }
|
||||
its('users') { should_not include 'forbidden_user' }
|
||||
end
|
||||
|
||||
describe passwd.uid(0) do
|
||||
its(:users) { should cmp 'root' }
|
||||
its(:count) { should eq 1 }
|
||||
its('users') { should cmp 'root' }
|
||||
its('count') { should eq 1 }
|
||||
end
|
||||
|
||||
where
|
||||
|
|
|
@ -48,7 +48,7 @@ module Inspec
|
|||
|
||||
if @qualifier.length > 1
|
||||
last = @qualifier[-1]
|
||||
# preventing its(:to_i) as the value returned is always 0
|
||||
# preventing its('to_i') as the value returned is always 0
|
||||
if last.length == 1 && last[0] != 'to_i'
|
||||
xres = last[0]
|
||||
else
|
||||
|
|
|
@ -106,7 +106,7 @@ RSpec::Matchers.define :be_installed do
|
|||
end
|
||||
|
||||
chain :with_version do |version|
|
||||
warn "[DEPRECATION] `with_version` is deprecated. Please use `its(:version) { should eq '1.4.1' }` instead."
|
||||
warn "[DEPRECATION] `with_version` is deprecated. Please use `its('version') { should eq '1.4.1' }` instead."
|
||||
@version = version
|
||||
end
|
||||
end
|
||||
|
@ -146,7 +146,7 @@ end
|
|||
# Deprecated: You should not use this matcher anymore
|
||||
RSpec::Matchers.define :belong_to_group do |compare_group|
|
||||
match do |user|
|
||||
warn "[DEPRECATION] `belong_to_group` is deprecated. Please use `its(:groups) { should include('root') }` instead."
|
||||
warn "[DEPRECATION] `belong_to_group` is deprecated. Please use `its('groups') { should include('root') }` instead."
|
||||
user.groups.include?(compare_group)
|
||||
end
|
||||
|
||||
|
@ -159,7 +159,7 @@ end
|
|||
# Deprecated: You should not use this matcher anymore
|
||||
RSpec::Matchers.define :belong_to_primary_group do |compare_group|
|
||||
match do |user|
|
||||
warn "[DEPRECATION] `belong_to_primary_group` is deprecated. Please use `its(:group) { should eq 'root' }` instead."
|
||||
warn "[DEPRECATION] `belong_to_primary_group` is deprecated. Please use `its('group') { should eq 'root' }` instead."
|
||||
user.group == compare_group
|
||||
end
|
||||
|
||||
|
|
|
@ -67,11 +67,11 @@ module Inspec::Resources
|
|||
end
|
||||
|
||||
describe auditd_rules.key('sshd_config') do
|
||||
its(:permissions) { should contain_match(/x/) }
|
||||
its('permissions') { should contain_match(/x/) }
|
||||
end
|
||||
|
||||
describe auditd_rules do
|
||||
its(:lines) { should contain_match(%r{-w /etc/ssh/sshd_config/}) }
|
||||
its('lines') { should contain_match(%r{-w /etc/ssh/sshd_config/}) }
|
||||
end
|
||||
"
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
# describe host('example.com') do
|
||||
# it { should be_resolvable }
|
||||
# it { should be_reachable }
|
||||
# its(:ipaddress) { should include '93.184.216.34' }
|
||||
# its('ipaddress') { should include '93.184.216.34' }
|
||||
# end
|
||||
#
|
||||
# To verify a hostname with protocol and port
|
||||
|
|
|
@ -12,7 +12,7 @@ module Inspec::Resources
|
|||
describe interface('eth0') do
|
||||
it { should exist }
|
||||
it { should be_up }
|
||||
its(:speed) { should eq 1000 }
|
||||
its('speed') { should eq 1000 }
|
||||
end
|
||||
"
|
||||
def initialize(iface)
|
||||
|
|
|
@ -8,7 +8,7 @@ module Inspec::Resources
|
|||
desc 'Use the kernel_parameter InSpec audit resource to test kernel parameters on Linux platforms.'
|
||||
example "
|
||||
describe kernel_parameter('net.ipv4.conf.all.forwarding') do
|
||||
its(:value) { should eq 0 }
|
||||
its('value') { should eq 0 }
|
||||
end
|
||||
"
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ module Inspec::Resources
|
|||
example "
|
||||
describe mount('/') do
|
||||
it { should be_mounted }
|
||||
its(:count) { should eq 1 }
|
||||
its('count') { should eq 1 }
|
||||
its('device') { should eq '/dev/mapper/VolGroup-lv_root' }
|
||||
its('type') { should eq 'ext4' }
|
||||
its('options') { should eq ['rw', 'mode=620'] }
|
||||
|
|
|
@ -11,7 +11,7 @@ module Inspec::Resources
|
|||
example "
|
||||
sql = mysql_session('my_user','password')
|
||||
describe sql.query('show databases like \'test\';') do
|
||||
its(:stdout) { should_not match(/test/) }
|
||||
its('stdout') { should_not match(/test/) }
|
||||
end
|
||||
"
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
# Usage:
|
||||
#
|
||||
# describe os_env('PATH') do
|
||||
# its(:split) { should_not include('') }
|
||||
# its(:split) { should_not include('.') }
|
||||
# its('split') { should_not include('') }
|
||||
# its('split') { should_not include('.') }
|
||||
# end
|
||||
|
||||
require 'utils/simpleconfig'
|
||||
|
|
|
@ -6,15 +6,15 @@
|
|||
#
|
||||
# describe user('root') do
|
||||
# it { should exist }
|
||||
# its(:uid) { should eq 0 }
|
||||
# its(:gid) { should eq 0 }
|
||||
# its(:group) { should eq 'root' }
|
||||
# its(:groups) { should eq ['root', 'wheel']}
|
||||
# its(:home) { should eq '/root' }
|
||||
# its(:shell) { should eq '/bin/bash' }
|
||||
# its(:mindays) { should eq 0 }
|
||||
# its(:maxdays) { should eq 99 }
|
||||
# its(:warndays) { should eq 5 }
|
||||
# its('uid') { should eq 0 }
|
||||
# its('gid') { should eq 0 }
|
||||
# its('group') { should eq 'root' }
|
||||
# its('groups') { should eq ['root', 'wheel']}
|
||||
# its('home') { should eq '/root' }
|
||||
# its('shell') { should eq '/bin/bash' }
|
||||
# its('mindays') { should eq 0 }
|
||||
# its('maxdays') { should eq 99 }
|
||||
# its('warndays') { should eq 5 }
|
||||
# end
|
||||
#
|
||||
# The following Serverspec matchers are deprecated in favor for direct value access
|
||||
|
@ -24,8 +24,8 @@
|
|||
# it { should have_uid 0 }
|
||||
# it { should have_home_directory '/root' }
|
||||
# it { should have_login_shell '/bin/bash' }
|
||||
# its(:minimum_days_between_password_change) { should eq 0 }
|
||||
# its(:maximum_days_between_password_change) { should eq 99 }
|
||||
# its('minimum_days_between_password_change') { should eq 0 }
|
||||
# its('maximum_days_between_password_change') { should eq 99 }
|
||||
# end
|
||||
|
||||
# ServerSpec tests that are not supported:
|
||||
|
@ -119,13 +119,13 @@ module Inspec::Resources
|
|||
|
||||
# implement 'mindays' method to be compatible with serverspec
|
||||
def minimum_days_between_password_change
|
||||
deprecated('minimum_days_between_password_change', "Please use 'its(:mindays)'")
|
||||
deprecated('minimum_days_between_password_change', "Please use: its('mindays')")
|
||||
mindays
|
||||
end
|
||||
|
||||
# implement 'maxdays' method to be compatible with serverspec
|
||||
def maximum_days_between_password_change
|
||||
deprecated('maximum_days_between_password_change', "Please use 'its(:maxdays)'")
|
||||
deprecated('maximum_days_between_password_change', "Please use: its('maxdays')")
|
||||
maxdays
|
||||
end
|
||||
|
||||
|
@ -137,12 +137,12 @@ module Inspec::Resources
|
|||
end
|
||||
|
||||
def has_home_directory?(compare_home)
|
||||
deprecated('has_home_directory?', "Please use 'its(:home)'")
|
||||
deprecated('has_home_directory?', "Please use: its('home')")
|
||||
home == compare_home
|
||||
end
|
||||
|
||||
def has_login_shell?(compare_shell)
|
||||
deprecated('has_login_shell?', "Please use 'its(:shell)'")
|
||||
deprecated('has_login_shell?', "Please use: its('shell')")
|
||||
shell == compare_shell
|
||||
end
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
return unless os[:family] == 'centos'
|
||||
|
||||
describe auditd_rules.syscall('open') do
|
||||
its(:action) { should eq(['always']) }
|
||||
its('action') { should eq(['always']) }
|
||||
end
|
||||
|
||||
describe auditd_rules.syscall('open').action do
|
||||
|
@ -12,7 +12,7 @@ describe auditd_rules.syscall('open').action do
|
|||
end
|
||||
|
||||
describe auditd_rules.key('sshd_config') do
|
||||
its(:permissions) { should contain_match(/x/) }
|
||||
its('permissions') { should contain_match(/x/) }
|
||||
end
|
||||
|
||||
describe auditd_rules.file('/etc/ssh/sshd_config').permissions do
|
||||
|
@ -20,7 +20,7 @@ describe auditd_rules.file('/etc/ssh/sshd_config').permissions do
|
|||
end
|
||||
|
||||
describe auditd_rules do
|
||||
its(:lines) { should contain_match(%r{-w /etc/ssh/sshd_config/}) }
|
||||
its('lines') { should contain_match(%r{-w /etc/ssh/sshd_config/}) }
|
||||
end
|
||||
|
||||
describe auditd_rules.syscall('open').action('always').list do
|
||||
|
|
|
@ -30,27 +30,27 @@ end
|
|||
# test on all linux systems
|
||||
if os.linux?
|
||||
describe kernel_parameter('kernel.panic') do
|
||||
its(:value) { should eq test_values[:kernel_panic] }
|
||||
its('value') { should eq test_values[:kernel_panic] }
|
||||
end
|
||||
|
||||
describe kernel_parameter('net.netfilter.nf_log.0') do
|
||||
its(:value) { should eq test_values[:nf_log] }
|
||||
its('value') { should eq test_values[:nf_log] }
|
||||
end
|
||||
|
||||
describe kernel_parameter('kernel.sched_autogroup_enabled') do
|
||||
its(:value) { should eq test_values[:sched_autogroup_enabled] }
|
||||
its('value') { should eq test_values[:sched_autogroup_enabled] }
|
||||
end
|
||||
|
||||
describe kernel_parameter('net.ipv4.ip_local_port_range') do
|
||||
its(:value) { should eq test_values[:ip_local_port_range] }
|
||||
its('value') { should eq test_values[:ip_local_port_range] }
|
||||
end
|
||||
|
||||
describe kernel_parameter('net.ipv4.conf.all.forwarding') do
|
||||
its(:value) { should eq test_values[:forwarding] }
|
||||
its('value') { should eq test_values[:forwarding] }
|
||||
end
|
||||
|
||||
# serverspec compatability
|
||||
describe linux_kernel_parameter('net.ipv4.conf.all.forwarding') do
|
||||
its(:value) { should eq test_values[:forwarding] }
|
||||
its('value') { should eq test_values[:forwarding] }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,21 +3,21 @@
|
|||
# author: Christoph Hartmann
|
||||
|
||||
describe command('echo hello') do
|
||||
its(:stdout) { should eq "hello\n" }
|
||||
its(:stderr) { should eq '' }
|
||||
its(:exit_status) { should eq 0 }
|
||||
its('stdout') { should eq "hello\n" }
|
||||
its('stderr') { should eq '' }
|
||||
its('exit_status') { should eq 0 }
|
||||
end
|
||||
|
||||
describe command('>&2 echo error') do
|
||||
its(:stdout) { should eq '' }
|
||||
its(:stderr) { should eq "error\n" }
|
||||
its(:exit_status) { should eq 0 }
|
||||
its('stdout') { should eq '' }
|
||||
its('stderr') { should eq "error\n" }
|
||||
its('exit_status') { should eq 0 }
|
||||
end
|
||||
|
||||
describe command('exit 123') do
|
||||
its(:stdout) { should eq '' }
|
||||
its(:stderr) { should eq '' }
|
||||
its(:exit_status) { should eq 123 }
|
||||
its('stdout') { should eq '' }
|
||||
its('stderr') { should eq '' }
|
||||
its('exit_status') { should eq 123 }
|
||||
end
|
||||
|
||||
describe command('/bin/sh').exist? do
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# author: Christoph Hartmann
|
||||
|
||||
describe command('echo hello') do
|
||||
its(:stdout) { should eq "hello\n" }
|
||||
its('stdout') { should eq "hello\n" }
|
||||
end
|
||||
|
||||
describe 'describe + it + expect' do
|
||||
|
|
|
@ -11,18 +11,18 @@ describe file('/tmpest') do
|
|||
end
|
||||
|
||||
describe file('/tmp') do
|
||||
its(:type) { should eq :directory }
|
||||
its('type') { should eq :directory }
|
||||
it { should be_directory }
|
||||
end
|
||||
|
||||
describe file('/proc/version') do
|
||||
its(:type) { should eq :file }
|
||||
its('type') { should eq :file }
|
||||
it { should be_file }
|
||||
it { should_not be_directory }
|
||||
end
|
||||
|
||||
describe file('/dev/stdout') do
|
||||
its(:type) { should eq :pipe }
|
||||
its('type') { should eq :pipe }
|
||||
its('source.type') { should eq :symlink }
|
||||
it { should be_symlink }
|
||||
it { should be_pipe }
|
||||
|
@ -31,29 +31,29 @@ describe file('/dev/stdout') do
|
|||
end
|
||||
|
||||
describe file('/dev/zero') do
|
||||
its(:type) { should eq :character_device }
|
||||
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 }
|
||||
# its('type') { should eq :block_device }
|
||||
# it { should be_block_device }
|
||||
# end
|
||||
|
||||
# describe file('...') do
|
||||
# its(:type) { should eq :socket }
|
||||
# its('type') { should eq :socket }
|
||||
# it { should be_socket }
|
||||
# end
|
||||
|
||||
# describe file('...') do
|
||||
# its(:type) { should eq :pipe }
|
||||
# its('type') { should eq :pipe }
|
||||
# it { should be_pipe }
|
||||
# end
|
||||
|
||||
describe file('/dev') do
|
||||
its(:mode) { should eq 00755 }
|
||||
its('mode') { should eq 00755 }
|
||||
end
|
||||
|
||||
describe file('/dev') do
|
||||
|
@ -61,7 +61,7 @@ describe file('/dev') do
|
|||
end
|
||||
|
||||
describe file('/root') do
|
||||
its(:owner) { should eq 'root' }
|
||||
its('owner') { should eq 'root' }
|
||||
end
|
||||
|
||||
describe file('/dev') do
|
||||
|
@ -69,7 +69,7 @@ describe file('/dev') do
|
|||
end
|
||||
|
||||
describe file('/root') do
|
||||
its(:group) { should eq 'root' }
|
||||
its('group') { should eq 'root' }
|
||||
end
|
||||
|
||||
describe file('/dev') do
|
||||
|
@ -77,7 +77,7 @@ describe file('/dev') do
|
|||
end
|
||||
|
||||
describe file('/dev/kcore') do
|
||||
its(:link_path) { should eq '/proc/kcore' }
|
||||
its('link_path') { should eq '/proc/kcore' }
|
||||
end
|
||||
|
||||
describe file('/dev/kcore') do
|
||||
|
@ -85,7 +85,7 @@ describe file('/dev/kcore') do
|
|||
end
|
||||
|
||||
describe file('/proc/cpuinfo') do
|
||||
its(:content) { should match /^processor/ }
|
||||
its('content') { should match /^processor/ }
|
||||
end
|
||||
|
||||
describe file('/').mtime.to_i do
|
||||
|
@ -94,12 +94,12 @@ describe file('/').mtime.to_i do
|
|||
end
|
||||
|
||||
describe file('/') do
|
||||
its(:size) { should be > 64 }
|
||||
its(:size) { should be < 10240 }
|
||||
its('size') { should be > 64 }
|
||||
its('size') { should be < 10240 }
|
||||
end
|
||||
|
||||
describe file('/proc/cpuinfo') do
|
||||
its(:size) { should be 0 }
|
||||
its('size') { should be 0 }
|
||||
end
|
||||
|
||||
# @TODO selinux_label
|
||||
|
@ -123,10 +123,10 @@ cpuinfo = file('/proc/cpuinfo').content
|
|||
|
||||
md5sum = Digest::MD5.hexdigest(cpuinfo)
|
||||
describe file('/proc/cpuinfo') do
|
||||
its(:md5sum) { should eq md5sum }
|
||||
its('md5sum') { should eq md5sum }
|
||||
end
|
||||
|
||||
sha256sum = Digest::SHA256.hexdigest(cpuinfo)
|
||||
describe file('/proc/cpuinfo') do
|
||||
its(:sha256sum) { should eq sha256sum }
|
||||
its('sha256sum') { should eq sha256sum }
|
||||
end
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
describe command('touch /tmp/inspec_test_DONT_CREATE') do
|
||||
its(:exit_status) { should eq 123 }
|
||||
its('exit_status') { should eq 123 }
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue