Révision 01d8a819
Styling to make tests green
spec/classes/dnat4_spec.rb | ||
---|---|---|
9 | 9 |
|
10 | 10 |
context 'with dnat' do |
11 | 11 |
let(:pre_condition) do |
12 |
"""
|
|
12 |
'
|
|
13 | 13 |
# inet-filter-chain-ingoing |
14 |
nftables::chain{ 'ingoing':
|
|
15 |
inject => '20-default_fwd',
|
|
16 |
inject_iif => 'eth0',
|
|
17 |
inject_oif => 'eth1';
|
|
14 |
nftables::chain{ \'ingoing\':
|
|
15 |
inject => \'20-default_fwd\',
|
|
16 |
inject_iif => \'eth0\',
|
|
17 |
inject_oif => \'eth1\';
|
|
18 | 18 |
} |
19 | 19 |
|
20 | 20 |
# inet-filter-chain-default_fwd |
21 | 21 |
nftables::rules::dnat4{ |
22 |
'http':
|
|
23 |
order => '10',
|
|
24 |
chain => 'ingoing',
|
|
25 |
daddr => '192.0.2.2',
|
|
26 |
port => 'http';
|
|
27 |
'https':
|
|
28 |
order => '10',
|
|
29 |
chain => 'ingoing',
|
|
30 |
daddr => '192.0.2.2',
|
|
31 |
port => 'https';
|
|
32 |
'http_alt':
|
|
33 |
order => '10',
|
|
34 |
chain => 'ingoing',
|
|
35 |
iif => 'eth0',
|
|
36 |
daddr => '192.0.2.2',
|
|
37 |
proto => 'tcp',
|
|
22 |
\'http\':
|
|
23 |
order => \'10\',
|
|
24 |
chain => \'ingoing\',
|
|
25 |
daddr => \'192.0.2.2\',
|
|
26 |
port => \'http\';
|
|
27 |
\'https\':
|
|
28 |
order => \'10\',
|
|
29 |
chain => \'ingoing\',
|
|
30 |
daddr => \'192.0.2.2\',
|
|
31 |
port => \'https\';
|
|
32 |
\'http_alt\':
|
|
33 |
order => \'10\',
|
|
34 |
chain => \'ingoing\',
|
|
35 |
iif => \'eth0\',
|
|
36 |
daddr => \'192.0.2.2\',
|
|
37 |
proto => \'tcp\',
|
|
38 | 38 |
port => 8080, |
39 | 39 |
dport => 8000; |
40 |
'wireguard':
|
|
41 |
order => '10',
|
|
42 |
chain => 'ingoing',
|
|
43 |
iif => 'eth0',
|
|
44 |
daddr => '192.0.2.3',
|
|
45 |
proto => 'udp',
|
|
46 |
port => '51820';
|
|
40 |
\'wireguard\':
|
|
41 |
order => \'10\',
|
|
42 |
chain => \'ingoing\',
|
|
43 |
iif => \'eth0\',
|
|
44 |
daddr => \'192.0.2.3\',
|
|
45 |
proto => \'udp\',
|
|
46 |
port => \'51820\';
|
|
47 | 47 |
} |
48 |
"""
|
|
48 |
'
|
|
49 | 49 |
end |
50 | 50 |
|
51 | 51 |
it { is_expected.to compile } |
52 | 52 |
|
53 |
it { is_expected.to contain_concat('nftables-inet-filter-chain-default_fwd').with( |
|
54 |
:path => '/etc/nftables/puppet/inet-filter-chain-default_fwd.nft', |
|
55 |
:owner => 'root', |
|
56 |
:group => 'root', |
|
57 |
:mode => '0640', |
|
58 |
:ensure_newline => true, |
|
59 |
)} |
|
60 |
it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-header').with( |
|
61 |
:target => 'nftables-inet-filter-chain-default_fwd', |
|
62 |
:content => /^chain default_fwd {$/, |
|
63 |
:order => '00', |
|
64 |
)} |
|
65 |
it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-jump_ingoing').with( |
|
66 |
:target => 'nftables-inet-filter-chain-default_fwd', |
|
67 |
:content => /^ iifname eth0 oifname eth1 jump ingoing$/, |
|
68 |
:order => '20', |
|
69 |
)} |
|
70 |
it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-footer').with( |
|
71 |
:target => 'nftables-inet-filter-chain-default_fwd', |
|
72 |
:content => /^}$/, |
|
73 |
:order => '99', |
|
74 |
)} |
|
53 |
it { |
|
54 |
is_expected.to contain_concat('nftables-inet-filter-chain-default_fwd').with( |
|
55 |
path: '/etc/nftables/puppet/inet-filter-chain-default_fwd.nft', |
|
56 |
owner: 'root', |
|
57 |
group: 'root', |
|
58 |
mode: '0640', |
|
59 |
ensure_newline: true, |
|
60 |
) |
|
61 |
} |
|
62 |
it { |
|
63 |
is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-header').with( |
|
64 |
target: 'nftables-inet-filter-chain-default_fwd', |
|
65 |
content: %r{^chain default_fwd \{$}, |
|
66 |
order: '00', |
|
67 |
) |
|
68 |
} |
|
69 |
it { |
|
70 |
is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-jump_ingoing').with( |
|
71 |
target: 'nftables-inet-filter-chain-default_fwd', |
|
72 |
content: %r{^ iifname eth0 oifname eth1 jump ingoing$}, |
|
73 |
order: '20', |
|
74 |
) |
|
75 |
} |
|
76 |
it { |
|
77 |
is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-footer').with( |
|
78 |
target: 'nftables-inet-filter-chain-default_fwd', |
|
79 |
content: %r{^\}$}, |
|
80 |
order: '99', |
|
81 |
) |
|
82 |
} |
|
75 | 83 |
|
76 |
it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-header').with( |
|
77 |
:target => 'nftables-inet-filter-chain-ingoing', |
|
78 |
:content => /^chain ingoing {$/, |
|
79 |
:order => '00', |
|
80 |
)} |
|
81 |
it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-http').with( |
|
82 |
:target => 'nftables-inet-filter-chain-ingoing', |
|
83 |
:content => /^ ip daddr 192.0.2.2 tcp dport http accept$/, |
|
84 |
:order => '10', |
|
85 |
)} |
|
86 |
it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-https').with( |
|
87 |
:target => 'nftables-inet-filter-chain-ingoing', |
|
88 |
:content => /^ ip daddr 192.0.2.2 tcp dport https accept$/, |
|
89 |
:order => '10', |
|
90 |
)} |
|
91 |
it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-http_alt').with( |
|
92 |
:target => 'nftables-inet-filter-chain-ingoing', |
|
93 |
:content => /^ iifname eth0 ip daddr 192.0.2.2 tcp dport 8000 accept$/, |
|
94 |
:order => '10', |
|
95 |
)} |
|
96 |
it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-wireguard').with( |
|
97 |
:target => 'nftables-inet-filter-chain-ingoing', |
|
98 |
:content => /^ iifname eth0 ip daddr 192.0.2.3 udp dport 51820 accept$/, |
|
99 |
:order => '10', |
|
100 |
)} |
|
101 |
it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-footer').with( |
|
102 |
:target => 'nftables-inet-filter-chain-ingoing', |
|
103 |
:content => /^}$/, |
|
104 |
:order => '99', |
|
105 |
)} |
|
84 |
it { |
|
85 |
is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-header').with( |
|
86 |
target: 'nftables-inet-filter-chain-ingoing', |
|
87 |
content: %r{^chain ingoing \{$}, |
|
88 |
order: '00', |
|
89 |
) |
|
90 |
} |
|
91 |
it { |
|
92 |
is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-http').with( |
|
93 |
target: 'nftables-inet-filter-chain-ingoing', |
|
94 |
content: %r{^ ip daddr 192.0.2.2 tcp dport http accept$}, |
|
95 |
order: '10', |
|
96 |
) |
|
97 |
} |
|
98 |
it { |
|
99 |
is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-https').with( |
|
100 |
target: 'nftables-inet-filter-chain-ingoing', |
|
101 |
content: %r{^ ip daddr 192.0.2.2 tcp dport https accept$}, |
|
102 |
order: '10', |
|
103 |
) |
|
104 |
} |
|
105 |
it { |
|
106 |
is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-http_alt').with( |
|
107 |
target: 'nftables-inet-filter-chain-ingoing', |
|
108 |
content: %r{^ iifname eth0 ip daddr 192.0.2.2 tcp dport 8000 accept$}, |
|
109 |
order: '10', |
|
110 |
) |
|
111 |
} |
|
112 |
it { |
|
113 |
is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-wireguard').with( |
|
114 |
target: 'nftables-inet-filter-chain-ingoing', |
|
115 |
content: %r{^ iifname eth0 ip daddr 192.0.2.3 udp dport 51820 accept$}, |
|
116 |
order: '10', |
|
117 |
) |
|
118 |
} |
|
119 |
it { |
|
120 |
is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-footer').with( |
|
121 |
target: 'nftables-inet-filter-chain-ingoing', |
|
122 |
content: %r{^\}$}, |
|
123 |
order: '99', |
|
124 |
) |
|
125 |
} |
|
106 | 126 |
|
107 |
it { is_expected.to contain_concat('nftables-ip-nat-chain-PREROUTING').with( |
|
108 |
:path => '/etc/nftables/puppet/ip-nat-chain-PREROUTING.nft', |
|
109 |
:owner => 'root', |
|
110 |
:group => 'root', |
|
111 |
:mode => '0640', |
|
112 |
:ensure_newline => true, |
|
113 |
)} |
|
114 |
it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-header').with( |
|
115 |
:target => 'nftables-ip-nat-chain-PREROUTING', |
|
116 |
:content => /^chain PREROUTING {$/, |
|
117 |
:order => '00', |
|
118 |
)} |
|
119 |
it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-type').with( |
|
120 |
:target => 'nftables-ip-nat-chain-PREROUTING', |
|
121 |
:content => /^ type nat hook prerouting priority -100$/, |
|
122 |
:order => '01', |
|
123 |
)} |
|
124 |
it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-policy').with( |
|
125 |
:target => 'nftables-ip-nat-chain-PREROUTING', |
|
126 |
:content => /^ policy accept$/, |
|
127 |
:order => '02', |
|
128 |
)} |
|
129 |
it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-http').with( |
|
130 |
:target => 'nftables-ip-nat-chain-PREROUTING', |
|
131 |
:content => /^ tcp dport http dnat to 192.0.2.2$/, |
|
132 |
:order => '10', |
|
133 |
)} |
|
134 |
it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-https').with( |
|
135 |
:target => 'nftables-ip-nat-chain-PREROUTING', |
|
136 |
:content => /^ tcp dport https dnat to 192.0.2.2$/, |
|
137 |
:order => '10', |
|
138 |
)} |
|
139 |
it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-http_alt').with( |
|
140 |
:target => 'nftables-ip-nat-chain-PREROUTING', |
|
141 |
:content => /^ iifname eth0 tcp dport 8080 dnat to 192.0.2.2:8000$/, |
|
142 |
:order => '10', |
|
143 |
)} |
|
144 |
it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-wireguard').with( |
|
145 |
:target => 'nftables-ip-nat-chain-PREROUTING', |
|
146 |
:content => /^ iifname eth0 udp dport 51820 dnat to 192.0.2.3$/, |
|
147 |
:order => '10', |
|
148 |
)} |
|
149 |
it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-footer').with( |
|
150 |
:target => 'nftables-ip-nat-chain-PREROUTING', |
|
151 |
:content => /^}$/, |
|
152 |
:order => '99', |
|
153 |
)} |
|
127 |
it { |
|
128 |
is_expected.to contain_concat('nftables-ip-nat-chain-PREROUTING').with( |
|
129 |
path: '/etc/nftables/puppet/ip-nat-chain-PREROUTING.nft', |
|
130 |
owner: 'root', |
|
131 |
group: 'root', |
|
132 |
mode: '0640', |
|
133 |
ensure_newline: true, |
|
134 |
) |
|
135 |
} |
|
136 |
it { |
|
137 |
is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-header').with( |
|
138 |
target: 'nftables-ip-nat-chain-PREROUTING', |
|
139 |
content: %r{^chain PREROUTING \{$}, |
|
140 |
order: '00', |
|
141 |
) |
|
142 |
} |
|
143 |
it { |
|
144 |
is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-type').with( |
|
145 |
target: 'nftables-ip-nat-chain-PREROUTING', |
|
146 |
content: %r{^ type nat hook prerouting priority -100$}, |
|
147 |
order: '01', |
|
148 |
) |
|
149 |
} |
|
150 |
it { |
|
151 |
is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-policy').with( |
|
152 |
target: 'nftables-ip-nat-chain-PREROUTING', |
|
153 |
content: %r{^ policy accept$}, |
|
154 |
order: '02', |
|
155 |
) |
|
156 |
} |
|
157 |
it { |
|
158 |
is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-http').with( |
|
159 |
target: 'nftables-ip-nat-chain-PREROUTING', |
|
160 |
content: %r{^ tcp dport http dnat to 192.0.2.2$}, |
|
161 |
order: '10', |
|
162 |
) |
|
163 |
} |
|
164 |
it { |
|
165 |
is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-https').with( |
|
166 |
target: 'nftables-ip-nat-chain-PREROUTING', |
|
167 |
content: %r{^ tcp dport https dnat to 192.0.2.2$}, |
|
168 |
order: '10', |
|
169 |
) |
|
170 |
} |
|
171 |
it { |
|
172 |
is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-http_alt').with( |
|
173 |
target: 'nftables-ip-nat-chain-PREROUTING', |
|
174 |
content: %r{^ iifname eth0 tcp dport 8080 dnat to 192.0.2.2:8000$}, |
|
175 |
order: '10', |
|
176 |
) |
|
177 |
} |
|
178 |
it { |
|
179 |
is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-wireguard').with( |
|
180 |
target: 'nftables-ip-nat-chain-PREROUTING', |
|
181 |
content: %r{^ iifname eth0 udp dport 51820 dnat to 192.0.2.3$}, |
|
182 |
order: '10', |
|
183 |
) |
|
184 |
} |
|
185 |
it { |
|
186 |
is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-footer').with( |
|
187 |
target: 'nftables-ip-nat-chain-PREROUTING', |
|
188 |
content: %r{^\}$}, |
|
189 |
order: '99', |
|
190 |
) |
|
191 |
} |
|
154 | 192 |
end |
155 | 193 |
end |
156 | 194 |
end |
Formats disponibles : Unified diff