root / spec / acceptance / default_spec.rb @ 2b1896c1
Historique | Voir | Annoter | Télécharger (5,66 ko)
1 |
# frozen_string_literal: true
|
---|---|
2 |
|
3 |
require 'spec_helper_acceptance'
|
4 |
|
5 |
describe 'nftables class' do |
6 |
context 'configure default nftables service' do |
7 |
it 'works idempotently with no errors' do |
8 |
pp = <<-EOS |
9 |
# default mask of firewalld service fails if service is not installed.
|
10 |
# https://tickets.puppetlabs.com/browse/PUP-10814
|
11 |
class { 'nftables':
|
12 |
firewalld_enable => false,
|
13 |
}
|
14 |
$config_path = $facts['os']['family'] ? {
|
15 |
'Archlinux' => '/etc/nftables.conf',
|
16 |
'Debian' => '/etc/nftables.conf',
|
17 |
default => '/etc/sysconfig/nftables.conf',
|
18 |
}
|
19 |
$nft_path = $facts['os']['family'] ? {
|
20 |
'Archlinux' => '/usr/bin/nft',
|
21 |
default => '/usr/sbin/nft',
|
22 |
}
|
23 |
# nftables cannot be started in docker so replace service with a validation only.
|
24 |
systemd::dropin_file{"zzz_docker_nft.conf":
|
25 |
ensure => present,
|
26 |
unit => "nftables.service",
|
27 |
content => [
|
28 |
"[Service]",
|
29 |
"ExecStart=",
|
30 |
"ExecStart=${nft_path} -c -I /etc/nftables/puppet -f ${config_path}",
|
31 |
"ExecReload=",
|
32 |
"ExecReload=${nft_path} -c -I /etc/nftables/puppet -f ${config_path}",
|
33 |
"",
|
34 |
].join("\n"),
|
35 |
notify => Service["nftables"],
|
36 |
}
|
37 |
EOS
|
38 |
# Run it twice and test for idempotency
|
39 |
apply_manifest(pp, catch_failures: true) |
40 |
apply_manifest(pp, catch_changes: true) |
41 |
end
|
42 |
|
43 |
describe package('nftables') do |
44 |
it { is_expected.to be_installed } |
45 |
end
|
46 |
|
47 |
describe service('nftables') do |
48 |
it { is_expected.to be_running } |
49 |
it { is_expected.to be_enabled } |
50 |
end
|
51 |
|
52 |
describe file('/etc/nftables/puppet.nft', '/etc/systemd/system/nftables.service.d/puppet_nft.conf') do |
53 |
it { is_expected.to be_file } |
54 |
end
|
55 |
|
56 |
describe file('/etc/nftables/puppet') do |
57 |
it { is_expected.to be_directory } |
58 |
end
|
59 |
end
|
60 |
|
61 |
context 'with bad invalid nft rules' do |
62 |
it 'puppet fails but should leave nft service running' do |
63 |
pp = <<-EOS |
64 |
class{'nftables':
|
65 |
firewalld_enable => false,
|
66 |
}
|
67 |
nftables::rule{'default_out-junk':
|
68 |
content => 'A load of junk',
|
69 |
}
|
70 |
$config_path = $facts['os']['family'] ? {
|
71 |
'Archlinux' => '/etc/nftables.conf',
|
72 |
'Debian' => '/etc/nftables.conf',
|
73 |
default => '/etc/sysconfig/nftables.conf',
|
74 |
}
|
75 |
$nft_path = $facts['os']['family'] ? {
|
76 |
'Archlinux' => '/usr/bin/nft',
|
77 |
default => '/usr/sbin/nft',
|
78 |
}
|
79 |
# nftables cannot be started in docker so replace service with a validation only.
|
80 |
systemd::dropin_file{"zzz_docker_nft.conf":
|
81 |
ensure => present,
|
82 |
unit => "nftables.service",
|
83 |
content => [
|
84 |
"[Service]",
|
85 |
"ExecStart=",
|
86 |
"ExecStart=${nft_path} -c -I /etc/nftables/puppet -f $config_path",
|
87 |
"ExecReload=",
|
88 |
"ExecReload=${nft_path} -c -I /etc/nftables/puppet -f $config_path",
|
89 |
"",
|
90 |
].join("\n"),
|
91 |
notify => Service["nftables"],
|
92 |
}
|
93 |
EOS
|
94 |
apply_manifest(pp, expect_failures: true) |
95 |
end
|
96 |
|
97 |
describe service('nftables') do |
98 |
it { is_expected.to be_running } |
99 |
it { is_expected.to be_enabled } |
100 |
end
|
101 |
end
|
102 |
|
103 |
context 'with totally empty firewall' do |
104 |
it 'no rules validate okay' do |
105 |
pp = <<-EOS |
106 |
class{'nftables':
|
107 |
firewalld_enable => false,
|
108 |
inet_filter => false,
|
109 |
nat => false,
|
110 |
}
|
111 |
$config_path = $facts['os']['family'] ? {
|
112 |
'Archlinux' => '/etc/nftables.conf',
|
113 |
'Debian' => '/etc/nftables.conf',
|
114 |
default => '/etc/sysconfig/nftables.conf',
|
115 |
}
|
116 |
$nft_path = $facts['os']['family'] ? {
|
117 |
'Archlinux' => '/usr/bin/nft',
|
118 |
default => '/usr/sbin/nft',
|
119 |
}
|
120 |
# nftables cannot be started in docker so replace service with a validation only.
|
121 |
systemd::dropin_file{"zzz_docker_nft.conf":
|
122 |
ensure => present,
|
123 |
unit => "nftables.service",
|
124 |
content => [
|
125 |
"[Service]",
|
126 |
"ExecStart=",
|
127 |
"ExecStart=${nft_path} -c -I /etc/nftables/puppet -f $config_path",
|
128 |
"ExecReload=",
|
129 |
"ExecReload=${nft_path} -c -I /etc/nftables/puppet -f $config_path",
|
130 |
"",
|
131 |
].join("\n"),
|
132 |
notify => Service["nftables"],
|
133 |
}
|
134 |
EOS
|
135 |
apply_manifest(pp, catch_failures: true) |
136 |
end
|
137 |
|
138 |
describe service('nftables') do |
139 |
it { is_expected.to be_running } |
140 |
it { is_expected.to be_enabled } |
141 |
end
|
142 |
end
|
143 |
|
144 |
context 'with custom nat_table_name' do |
145 |
it 'no rules validate okay' do |
146 |
pp = <<-EOS |
147 |
class{'nftables':
|
148 |
firewalld_enable => false,
|
149 |
nat => true,
|
150 |
nat_table_name => 'mycustomtablename',
|
151 |
}
|
152 |
$config_path = $facts['os']['family'] ? {
|
153 |
'Archlinux' => '/etc/nftables.conf',
|
154 |
'Debian' => '/etc/nftables.conf',
|
155 |
default => '/etc/sysconfig/nftables.conf',
|
156 |
}
|
157 |
$nft_path = $facts['os']['family'] ? {
|
158 |
'Archlinux' => '/usr/bin/nft',
|
159 |
default => '/usr/sbin/nft',
|
160 |
}
|
161 |
# nftables cannot be started in docker so replace service with a validation only.
|
162 |
systemd::dropin_file{"zzz_docker_nft.conf":
|
163 |
ensure => present,
|
164 |
unit => "nftables.service",
|
165 |
content => [
|
166 |
"[Service]",
|
167 |
"ExecStart=",
|
168 |
"ExecStart=${nft_path} -c -I /etc/nftables/puppet -f $config_path",
|
169 |
"ExecReload=",
|
170 |
"ExecReload=${nft_path} -c -I /etc/nftables/puppet -f $config_path",
|
171 |
"",
|
172 |
].join("\n"),
|
173 |
notify => Service["nftables"],
|
174 |
}
|
175 |
EOS
|
176 |
apply_manifest(pp, catch_failures: true) |
177 |
end
|
178 |
|
179 |
describe service('nftables') do |
180 |
it { is_expected.to be_running } |
181 |
it { is_expected.to be_enabled } |
182 |
end
|
183 |
end
|
184 |
end
|