root / spec / defines / chain_spec.rb @ 0b7bcb5d
Historique | Voir | Annoter | Télécharger (4,16 ko)
1 |
# frozen_string_literal: true
|
---|---|
2 |
|
3 |
require 'spec_helper'
|
4 |
|
5 |
describe 'nftables::chain' do |
6 |
let(:title) { 'MYCHAIN' } |
7 |
let(:pre_condition) { 'include nftables' } |
8 |
|
9 |
on_supported_os.each do |os, facts|
|
10 |
context "on #{os}" do |
11 |
let(:facts) do |
12 |
facts |
13 |
end
|
14 |
|
15 |
nft_mode = case facts[:os]['family'] |
16 |
when 'RedHat' |
17 |
'0600'
|
18 |
else
|
19 |
'0640'
|
20 |
end
|
21 |
|
22 |
it { is_expected.to compile } |
23 |
|
24 |
it { is_expected.to contain_concat('nftables-inet-filter-chain-MYCHAIN').that_notifies('Exec[nft validate]') } |
25 |
it { is_expected.to contain_exec('nft validate').that_comes_before('File[/etc/nftables/puppet/inet-filter-chain-MYCHAIN.nft]') } |
26 |
it { is_expected.to contain_file('/etc/nftables/puppet/inet-filter-chain-MYCHAIN.nft').that_comes_before('Service[nftables]') } |
27 |
|
28 |
it { |
29 |
expect(subject).to contain_concat('nftables-inet-filter-chain-MYCHAIN').with(
|
30 |
path: '/etc/nftables/puppet-preflight/inet-filter-chain-MYCHAIN.nft', |
31 |
owner: 'root', |
32 |
group: 'root', |
33 |
mode: nft_mode,
|
34 |
ensure_newline: true |
35 |
) |
36 |
} |
37 |
|
38 |
it { |
39 |
expect(subject).to contain_file('/etc/nftables/puppet/inet-filter-chain-MYCHAIN.nft').with(
|
40 |
ensure: 'file', |
41 |
source: '/etc/nftables/puppet-preflight/inet-filter-chain-MYCHAIN.nft', |
42 |
mode: nft_mode,
|
43 |
owner: 'root', |
44 |
group: 'root' |
45 |
) |
46 |
} |
47 |
|
48 |
it { |
49 |
expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-MYCHAIN-header').with(
|
50 |
order: '00', |
51 |
content: "# Start of fragment order:00 MYCHAIN header\nchain MYCHAIN {", |
52 |
target: 'nftables-inet-filter-chain-MYCHAIN' |
53 |
) |
54 |
} |
55 |
|
56 |
it { |
57 |
expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-MYCHAIN-footer').with(
|
58 |
order: '99', |
59 |
content: "# Start of fragment order:99 MYCHAIN footer\n}", |
60 |
target: 'nftables-inet-filter-chain-MYCHAIN' |
61 |
) |
62 |
} |
63 |
|
64 |
context('with table set to ip6-foo') do |
65 |
let(:params) do |
66 |
{ |
67 |
table: 'ip6-foo', |
68 |
} |
69 |
end
|
70 |
|
71 |
it { |
72 |
expect(subject).to contain_concat('nftables-ip6-foo-chain-MYCHAIN').with(
|
73 |
path: '/etc/nftables/puppet-preflight/ip6-foo-chain-MYCHAIN.nft', |
74 |
owner: 'root', |
75 |
group: 'root', |
76 |
mode: nft_mode,
|
77 |
ensure_newline: true |
78 |
) |
79 |
} |
80 |
|
81 |
it { |
82 |
expect(subject).to contain_file('/etc/nftables/puppet/ip6-foo-chain-MYCHAIN.nft').with(
|
83 |
ensure: 'file', |
84 |
source: '/etc/nftables/puppet-preflight/ip6-foo-chain-MYCHAIN.nft', |
85 |
mode: nft_mode,
|
86 |
owner: 'root', |
87 |
group: 'root' |
88 |
) |
89 |
} |
90 |
|
91 |
it { |
92 |
expect(subject).to contain_concat__fragment('nftables-ip6-foo-chain-MYCHAIN-header').with(
|
93 |
order: '00', |
94 |
content: "# Start of fragment order:00 MYCHAIN header\nchain MYCHAIN {", |
95 |
target: 'nftables-ip6-foo-chain-MYCHAIN' |
96 |
) |
97 |
} |
98 |
|
99 |
it { |
100 |
expect(subject).to contain_concat__fragment('nftables-ip6-foo-chain-MYCHAIN-footer').with(
|
101 |
order: '99', |
102 |
content: "# Start of fragment order:99 MYCHAIN footer\n}", |
103 |
target: 'nftables-ip6-foo-chain-MYCHAIN' |
104 |
) |
105 |
} |
106 |
end
|
107 |
|
108 |
context 'with inject set to 22-foobar' do |
109 |
let(:params) do |
110 |
{ |
111 |
inject: '22-foobar', |
112 |
} |
113 |
end
|
114 |
|
115 |
it { is_expected.to contain_nftables__rule('foobar-jump_MYCHAIN') }
|
116 |
|
117 |
it { |
118 |
expect(subject).to contain_nftables__rule('foobar-jump_MYCHAIN').with(
|
119 |
order: '22', |
120 |
content: 'jump MYCHAIN' |
121 |
) |
122 |
} |
123 |
|
124 |
context 'with inject_oif set to alpha and inject_oif set to beta' do |
125 |
let(:params) do |
126 |
super().merge(inject_iif: 'alpha', inject_oif: 'beta') |
127 |
end
|
128 |
|
129 |
it { |
130 |
expect(subject).to contain_nftables__rule('foobar-jump_MYCHAIN').with(
|
131 |
order: '22', |
132 |
content: 'iifname alpha oifname beta jump MYCHAIN' |
133 |
) |
134 |
} |
135 |
end
|
136 |
end
|
137 |
end
|
138 |
end
|
139 |
end
|