Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run acceptance tests #2

Merged
merged 6 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ concurrency:
jobs:
puppet:
name: Puppet
uses: voxpupuli/gha-puppet/.github/workflows/basic.yml@v1
uses: voxpupuli/gha-puppet/.github/workflows/beaker.yml@v2
with:
beaker_hypervisor: 'vagrant_libvirt'
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ end

group :system_tests do
gem 'voxpupuli-acceptance', '~> 3.0', :require => false
# https://github.com/voxpupuli/beaker-vagrant/pull/80
gem 'beaker-vagrant', github: 'ekohl/beaker-vagrant', branch: 'shorter-directory-names', require: false
# https://github.com/voxpupuli/beaker-hostgenerator/pull/353
gem 'beaker-hostgenerator', github: 'ekohl/beaker-hostgenerator', branch: 'use-latest-centos-images-on-vagrant', require: false
end

group :release do
Expand Down
6 changes: 2 additions & 4 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@
{
"operatingsystem": "Fedora",
"operatingsystemrelease": [
"30",
"31",
"32",
"33"
"38",
"39"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions spec/acceptance/class_disabled_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
end

context 'when switching from enforcing to disabled' do
let(:pp) do
let(:manifest) do
<<-EOS
class { 'selinux': mode => 'disabled' }
EOS
Expand All @@ -60,12 +60,12 @@
it_behaves_like 'an idempotent resource'

describe file('/etc/selinux/config') do
its(:content) { is_expected.to match(%r{^SELINUX=disabled$}) }

Check failure on line 63 in spec/acceptance/class_disabled_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Debian 11

selinux class - mode switching when switching from enforcing to disabled before reboot File "/etc/selinux/config" content is expected to match /^SELINUX=disabled$/ Failure/Error: its(:content) { is_expected.to match(%r{^SELINUX=disabled$}) } expected "" to match /^SELINUX=disabled$/ Diff: @@ -1 +1 @@ -/^SELINUX=disabled$/ +""

Check failure on line 63 in spec/acceptance/class_disabled_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Debian 11

selinux class - mode switching when switching from enforcing to disabled before reboot File "/etc/selinux/config" content is expected to match /^SELINUX=disabled$/ Failure/Error: its(:content) { is_expected.to match(%r{^SELINUX=disabled$}) } expected "" to match /^SELINUX=disabled$/ Diff: @@ -1 +1 @@ -/^SELINUX=disabled$/ +""
end

# Testing for Permissive brecause only after a reboot it's disabled
describe command('getenforce') do
its(:stdout) { is_expected.to match(%r{^Permissive$}) }

Check failure on line 68 in spec/acceptance/class_disabled_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Debian 11

selinux class - mode switching when switching from enforcing to disabled before reboot Command "getenforce" stdout is expected to match /^Permissive$/ Failure/Error: its(:stdout) { is_expected.to match(%r{^Permissive$}) } expected "" to match /^Permissive$/ Diff: @@ -1 +1 @@ -/^Permissive$/ +""

Check failure on line 68 in spec/acceptance/class_disabled_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Debian 11

selinux class - mode switching when switching from enforcing to disabled before reboot Command "getenforce" stdout is expected to match /^Permissive$/ Failure/Error: its(:stdout) { is_expected.to match(%r{^Permissive$}) } expected "" to match /^Permissive$/ Diff: @@ -1 +1 @@ -/^Permissive$/ +""
end
end

Expand All @@ -74,12 +74,12 @@
hosts.each(&:reboot)
end

it 'applies without changes' do

Check failure on line 77 in spec/acceptance/class_disabled_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Debian 11

selinux class - mode switching when switching from enforcing to disabled after reboot applies without changes Failure/Error: hosts.each(&:reboot) Beaker::Host::RebootWarning: Could not find system boot time using 'last -F reboot || who -b': ''

Check failure on line 77 in spec/acceptance/class_disabled_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Debian 11

selinux class - mode switching when switching from enforcing to disabled after reboot applies without changes Failure/Error: hosts.each(&:reboot) Beaker::Host::RebootWarning: Could not find system boot time using 'last -F reboot || who -b': ''
apply_manifest(pp, catch_changes: true)
apply_manifest(manifest, catch_changes: true)
end

describe command('getenforce') do
its(:stdout) { is_expected.to match(%r{^Disabled$}) }

Check failure on line 82 in spec/acceptance/class_disabled_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Debian 11

selinux class - mode switching when switching from enforcing to disabled after reboot Command "getenforce" stdout Failure/Error: hosts.each(&:reboot) Beaker::Host::RebootWarning: Could not find system boot time using 'last -F reboot || who -b': ''

Check failure on line 82 in spec/acceptance/class_disabled_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Debian 11

selinux class - mode switching when switching from enforcing to disabled after reboot Command "getenforce" stdout Failure/Error: hosts.each(&:reboot) Beaker::Host::RebootWarning: Could not find system boot time using 'last -F reboot || who -b': ''
end
end
end
Expand All @@ -90,7 +90,7 @@
end

describe file(test_file_path) do
its(:selinux_label) { is_expected.to eq('?') }

Check failure on line 93 in spec/acceptance/class_disabled_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Debian 11

selinux class - mode switching while disabled File "/var/test" selinux_label Failure/Error: on(hosts, "touch #{test_file_path}") Beaker::Host::CommandFailure: Host 'debian11-64-puppet7.example.com' exited with 1 running: touch /var/test Last 10 lines of output were: /bin/bash: Permission denied

Check failure on line 93 in spec/acceptance/class_disabled_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Debian 11

selinux class - mode switching while disabled File "/var/test" selinux_label Failure/Error: on(hosts, "touch #{test_file_path}") Beaker::Host::CommandFailure: Host 'debian11-64-puppet8.example.com' exited with 1 running: touch /var/test Last 10 lines of output were: /bin/bash: Permission denied
end
end

Expand All @@ -105,7 +105,7 @@
it_behaves_like 'an idempotent resource'

describe file('/etc/selinux/config') do
its(:content) { is_expected.to match(%r{^SELINUX=permissive$}) }

Check failure on line 108 in spec/acceptance/class_disabled_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Debian 11

selinux class - mode switching when switching from disabled to permissive before reboot File "/etc/selinux/config" content is expected to match /^SELINUX=permissive$/ Failure/Error: its(:content) { is_expected.to match(%r{^SELINUX=permissive$}) } expected "" to match /^SELINUX=permissive$/ Diff: @@ -1 +1 @@ -/^SELINUX=permissive$/ +""

Check failure on line 108 in spec/acceptance/class_disabled_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Debian 11

selinux class - mode switching when switching from disabled to permissive before reboot File "/etc/selinux/config" content is expected to match /^SELINUX=permissive$/ Failure/Error: its(:content) { is_expected.to match(%r{^SELINUX=permissive$}) } expected "" to match /^SELINUX=permissive$/ Diff: @@ -1 +1 @@ -/^SELINUX=permissive$/ +""
end

# Testing for Permissive brecause only after a reboot it's disabled
Expand All @@ -120,7 +120,7 @@
end

it 'applies without changes' do
apply_manifest(pp, catch_changes: true)
apply_manifest(manifest, catch_changes: true)
end

describe command('getenforce') do
Expand Down
41 changes: 21 additions & 20 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ class { 'selinux': mode => 'enforcing' }
selinux::permissive { 'puppet_selinux_test_policy_t': }

selinux::port { 'puppet_selinux_test_policy_port_t/tcp':
seltype => 'puppet_selinux_test_policy_port_t',
port => 55555,
seltype => 'puppet_selinux_test_policy_port_t',
port => 55555,
protocol => 'tcp',
}
}

# just something simple I found via Google:
file {'/tmp/selinux_simple_policy.te':
file { '/tmp/selinux_simple_policy.te':
ensure => 'file',
content => @("EOF")
module puppet_selinux_simple_policy 1.0;
Expand All @@ -40,7 +40,7 @@ class file { read getattr };
| EOF
}

file {'/tmp/selinux_test_policy.te':
file { '/tmp/selinux_test_policy.te':
ensure => 'file',
content => @("EOF")
policy_module(puppet_selinux_test_policy, 1.0.0)
Expand All @@ -56,48 +56,49 @@ class file { read getattr };
selinux::module { 'puppet_selinux_simple_policy':
source_te => 'file:///tmp/selinux_simple_policy.te',
builder => 'simple',
require => File['/tmp/selinux_simple_policy.te']
require => File['/tmp/selinux_simple_policy.te'],
}

selinux::module { 'puppet_selinux_test_policy':
source_te => 'file:///tmp/selinux_test_policy.te',
builder => 'refpolicy',
require => File['/tmp/selinux_test_policy.te']
source_te => 'file:///tmp/selinux_test_policy.te',
builder => 'refpolicy',
require => File['/tmp/selinux_test_policy.te'],
}

if $have_selinux_ruby_library {
Class['selinux'] ->

file { '/tmp/test_selinux_fcontext':
content => 'TEST',
seltype => 'puppet_selinux_test_policy_exec_t',
require => Class['selinux'],
}

selinux::fcontext {'/tmp/fcontexts_source(/.*)?':
selinux::fcontext { '/tmp/fcontexts_source(/.*)?':
seltype => 'puppet_selinux_test_policy_exec_t',
}

selinux::fcontext::equivalence {'/tmp/fcontexts_equivalent':
selinux::fcontext::equivalence { '/tmp/fcontexts_equivalent':
target => '/tmp/fcontexts_source',
}

file {['/tmp/fcontexts_source', '/tmp/fcontexts_equivalent']:
ensure => 'directory',
ensure => 'directory',
require => [Selinux::Fcontext['/tmp/fcontexts_source(/.*)?'], Selinux::Fcontext::Equivalence['/tmp/fcontexts_equivalent']],
}

file {['/tmp/fcontexts_source/define_test', '/tmp/fcontexts_equivalent/define_test']:
ensure => file,
notify => Exec["/sbin/restorecon -FR /tmp/fcontexts_*"]
file { ['/tmp/fcontexts_source/define_test', '/tmp/fcontexts_equivalent/define_test']:
ensure => file,
notify => Exec['/sbin/restorecon -FR /tmp/fcontexts_*'],
}
exec {'/sbin/restorecon -FR /tmp/fcontexts_*':
# this is needed because puppet creates files with the wrong context as
# it runs unconfined and only becomes idempotent after the second run.
exec { '/sbin/restorecon -FR /tmp/fcontexts_*':
# this is needed because puppet creates files with the wrong context as
# it runs unconfined and only becomes idempotent after the second run.
refreshonly => true,
}

# test purging
resources {['selinux_fcontext', 'selinux_fcontext_equivalence']: purge => true }
resources { ['selinux_fcontext', 'selinux_fcontext_equivalence']:
purge => true,
}
}
EOS
end
Expand Down
Loading