mirror of
https://github.com/inspec/inspec
synced 2024-11-10 15:14:23 +00:00
update integration tests
This commit is contained in:
parent
202190ea56
commit
500ac1c41a
13 changed files with 158 additions and 77 deletions
|
@ -11,6 +11,8 @@ if node['platform_family'] != 'windows'
|
|||
'system'
|
||||
when 'freebsd'
|
||||
'wheel'
|
||||
when 'solaris', 'solaris2'
|
||||
'sys'
|
||||
else
|
||||
'root'
|
||||
end
|
||||
|
|
|
@ -9,6 +9,8 @@ gid = case node['platform_family']
|
|||
'system'
|
||||
when 'freebsd'
|
||||
'wheel'
|
||||
when 'solaris', 'solaris2'
|
||||
'sys'
|
||||
else
|
||||
'root'
|
||||
end
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
#
|
||||
# file mount tests
|
||||
|
||||
case node['platform']
|
||||
when 'ubuntu', 'rhel', 'centos', 'fedora'
|
||||
|
||||
# copy iso file for mount tests
|
||||
# NB created using `mkdir empty; mkisofs -o empty.iso empty/`
|
||||
cookbook_file '/root/empty.iso' do
|
||||
|
@ -27,3 +30,4 @@ mount '/mnt/iso-disk' do
|
|||
options 'loop'
|
||||
action [:mount, :enable]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1 +1 @@
|
|||
p "You are currently running on OS family: #{os[:family] || 'unknown'}, OS release: #{os[:release] || 'unknown'}"
|
||||
p "You are currently running on OS: #{os[:name] || 'unknown'}, OS release: #{os[:release] || 'unknown'}, OS family: #{os[:family] || 'unknown'}"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# encoding: utf-8
|
||||
|
||||
if os.linux?
|
||||
# uses the `cmp` matcher instead of the eq matcher
|
||||
describe sshd_config do
|
||||
its('Port') { should eq '22' }
|
||||
|
@ -17,3 +18,4 @@ describe sshd_config do
|
|||
its('LogLevel') { should cmp 'info' }
|
||||
its('LogLevel') { should cmp 'InfO' }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
# encoding: utf-8
|
||||
|
||||
root_group = case os[:family]
|
||||
when 'aix'
|
||||
'system'
|
||||
when 'freebsd'
|
||||
'wheel'
|
||||
else
|
||||
'root'
|
||||
root_group = 'root'
|
||||
|
||||
if os[:family] == 'aix'
|
||||
root_group = 'system'
|
||||
elsif os[:family] == 'freebsd'
|
||||
root_group = 'wheel'
|
||||
elsif os.solaris?
|
||||
root_group = 'sys'
|
||||
end
|
||||
|
||||
if os.unix?
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
# encoding: utf-8
|
||||
|
||||
case os[:family]
|
||||
when 'freebsd'
|
||||
if os[:family] == 'freebsd'
|
||||
filedata = {
|
||||
user: 'root',
|
||||
group: 'wheel',
|
||||
|
@ -9,7 +8,7 @@ when 'freebsd'
|
|||
dir_md5sum: '598f4fe64aefab8f00bcbea4c9239abf',
|
||||
dir_sha256sum: '9b4fb24edd6d1d8830e272398263cdbf026b97392cc35387b991dc0248a628f9',
|
||||
}
|
||||
when 'aix'
|
||||
elsif os[:family] == 'aix'
|
||||
filedata = {
|
||||
user: 'root',
|
||||
group: 'system',
|
||||
|
@ -17,6 +16,14 @@ when 'aix'
|
|||
dir_md5sum: nil,
|
||||
dir_sha256sum: nil,
|
||||
}
|
||||
elsif os.solaris?
|
||||
filedata = {
|
||||
user: 'root',
|
||||
group: 'sys',
|
||||
dir_content: nil,
|
||||
dir_md5sum: nil,
|
||||
dir_sha256sum: nil,
|
||||
}
|
||||
else
|
||||
filedata = {
|
||||
user: 'root',
|
||||
|
@ -116,7 +123,9 @@ if os.unix?
|
|||
its('group') { should eq filedata[:group] }
|
||||
its('type') { should eq :directory }
|
||||
end
|
||||
end
|
||||
|
||||
if os.linux?
|
||||
# for server spec compatibility
|
||||
# Do not use `.with` or `.only_with`, this syntax is deprecated and will be removed
|
||||
# in InSpec version 1
|
||||
|
@ -140,8 +149,9 @@ if os.unix?
|
|||
})
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
elsif os.windows?
|
||||
if os.windows?
|
||||
describe file('C:\\Windows') do
|
||||
it { should exist }
|
||||
it { should be_directory }
|
||||
|
|
|
@ -11,10 +11,7 @@ if os.linux?
|
|||
it { should_not exist }
|
||||
its('gid') { should eq nil }
|
||||
end
|
||||
end
|
||||
|
||||
if os[:family] == 'freebsd'
|
||||
|
||||
elsif os[:family] == 'freebsd'
|
||||
describe group('wheel') do
|
||||
it { should exist }
|
||||
its('gid') { should eq 0 }
|
||||
|
@ -29,9 +26,7 @@ if os[:family] == 'freebsd'
|
|||
it { should_not exist }
|
||||
its('gid') { should eq nil }
|
||||
end
|
||||
end
|
||||
|
||||
if os[:family] == 'aix'
|
||||
elsif os[:family] == 'aix'
|
||||
describe group('system') do
|
||||
it { should exist }
|
||||
its('gid') { should eq 0 }
|
||||
|
@ -42,6 +37,21 @@ if os[:family] == 'aix'
|
|||
its('gid') { should eq 2 }
|
||||
end
|
||||
|
||||
describe group('noroot') do
|
||||
it { should_not exist }
|
||||
its('gid') { should eq nil }
|
||||
end
|
||||
elsif os.solaris?
|
||||
describe group('root') do
|
||||
it { should exist }
|
||||
its('gid') { should eq 0 }
|
||||
end
|
||||
|
||||
describe group('bin') do
|
||||
it { should exist }
|
||||
its('gid') { should eq 2 }
|
||||
end
|
||||
|
||||
describe group('noroot') do
|
||||
it { should_not exist }
|
||||
its('gid') { should eq nil }
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# encoding: utf-8
|
||||
|
||||
if os.linux?
|
||||
# instead of `.with` or `.only_with` we recommend to use the `mount` resource
|
||||
describe mount '/mnt/iso-disk' do
|
||||
it { should be_mounted }
|
||||
|
@ -8,3 +9,4 @@ describe mount '/mnt/iso-disk' do
|
|||
its('type') { should eq 'iso9660' }
|
||||
its('options') { should eq ['ro'] }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,6 +10,22 @@ when 'aix'
|
|||
it { should be_installed }
|
||||
its('version') { should match /^(6|7)[.|\d]+\d$/ }
|
||||
end
|
||||
when 'solaris'
|
||||
|
||||
if os[:release] == '11'
|
||||
pkg = 'system/file-system/zfs'
|
||||
ver = /^0\.5.+$/
|
||||
else
|
||||
pkg = 'SUNWzfsr'
|
||||
ver = /^11\.10.+$/
|
||||
end
|
||||
|
||||
describe package(pkg) do
|
||||
it { should be_installed }
|
||||
its('version') { should match ver }
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
describe package('nginx') do
|
||||
|
|
|
@ -1,15 +1,21 @@
|
|||
# encoding: utf-8
|
||||
|
||||
if os.unix?
|
||||
# check that ssh runs
|
||||
if os.unix?
|
||||
describe port(22) do
|
||||
it { should be_listening }
|
||||
its('protocols') { should include('tcp') }
|
||||
its('protocols') { should_not include('udp') }
|
||||
its('processes') { should include 'sshd' }
|
||||
end
|
||||
|
||||
describe port(65432) do
|
||||
it { should_not be_listening }
|
||||
end
|
||||
end
|
||||
|
||||
# extra test for linux
|
||||
if os.linux?
|
||||
describe port(22) do
|
||||
its('processes') { should include 'sshd' }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,13 +13,16 @@ elsif ['ubuntu'].include?(os[:family])
|
|||
# Ubuntu
|
||||
unavailable_service = 'sshd'
|
||||
available_service = 'ssh'
|
||||
elsif ['windows'].include?(os[:family])
|
||||
elsif os.windows?
|
||||
# Ubuntu
|
||||
unavailable_service = 'sshd'
|
||||
available_service = 'dhcp'
|
||||
elsif ['aix'].include?(os[:family])
|
||||
unavailable_service = 'clamav'
|
||||
available_service = 'xntpd'
|
||||
elsif os.solaris?
|
||||
unavailable_service = 'clamav'
|
||||
available_service = 'ssh'
|
||||
end
|
||||
|
||||
describe service(unavailable_service) do
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
# encoding: utf-8
|
||||
|
||||
case os[:family]
|
||||
when 'centos', 'redhat', 'fedora', 'opensuse', 'debian', 'ubuntu'
|
||||
if ['centos', 'redhat', 'fedora', 'opensuse', 'debian', 'ubuntu'].include?(os[:family])
|
||||
userinfo = {
|
||||
name: 'root',
|
||||
group: 'root',
|
||||
|
@ -15,19 +14,17 @@ when 'centos', 'redhat', 'fedora', 'opensuse', 'debian', 'ubuntu'
|
|||
# different groupset for centos 5
|
||||
userinfo[:groups] = ["root", "bin", "daemon", "sys", "adm", "disk", "wheel"] \
|
||||
if os[:release].to_i == 5
|
||||
|
||||
when 'freebsd'
|
||||
elsif ['freebsd'].include?(os[:family])
|
||||
userinfo = {
|
||||
name: 'root',
|
||||
group: 'wheel',
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
groups: ["wheel", "operator"],
|
||||
groups: "wheel", # at least this group should be there
|
||||
home: '/root',
|
||||
shell: '/bin/csh',
|
||||
}
|
||||
|
||||
when 'windows'
|
||||
elsif os.windows?
|
||||
userinfo = {
|
||||
name: 'Administrator',
|
||||
group: nil,
|
||||
|
@ -37,27 +34,46 @@ when 'windows'
|
|||
home: nil,
|
||||
shell: nil,
|
||||
}
|
||||
|
||||
when 'aix'
|
||||
elsif os[:family] == 'aix'
|
||||
userinfo = {
|
||||
name: 'bin',
|
||||
group: 'bin',
|
||||
uid: 2,
|
||||
gid: 2,
|
||||
groups: %w{bin sys adm},
|
||||
groups: "adm", # at least this group should be there
|
||||
home: '/bin',
|
||||
shell: nil,
|
||||
#mindays: 0,
|
||||
#maxdays: 0,
|
||||
warndays: 0,
|
||||
}
|
||||
|
||||
elsif os.solaris?
|
||||
if os[:release].to_i > 10
|
||||
userinfo = {
|
||||
name: 'root',
|
||||
group: 'root',
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
groups: "sys", # at least this group should be there
|
||||
home: '/root',
|
||||
shell: '/usr/bin/bash',
|
||||
}
|
||||
else
|
||||
userinfo = {
|
||||
name: 'root',
|
||||
group: 'root',
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
groups: "sys", # at least this group should be there
|
||||
home: '/',
|
||||
shell: '/sbin/sh',
|
||||
}
|
||||
end
|
||||
else
|
||||
userinfo = {}
|
||||
end
|
||||
|
||||
case os[:family]
|
||||
when 'windows'
|
||||
if os.windows?
|
||||
describe user(userinfo[:name]) do
|
||||
it { should exist }
|
||||
end
|
||||
|
@ -66,7 +82,14 @@ else
|
|||
it { should exist }
|
||||
userinfo.each do |k, v|
|
||||
next if k.to_sym == :name
|
||||
|
||||
# check that the user is part of the groups
|
||||
if k.to_s == 'groups'
|
||||
its(k) { should include v }
|
||||
# default eq comparison
|
||||
else
|
||||
its(k) { should eq v }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue