root / spec / classes / snat4_spec.rb @ 331b8d85
Historique | Voir | Annoter | Télécharger (3,88 ko)
1 |
# frozen_string_literal: true
|
---|---|
2 |
|
3 |
require 'spec_helper'
|
4 |
|
5 |
describe 'nftables' do |
6 |
let(:pre_condition) { 'Exec{path => "/bin"}' } |
7 |
|
8 |
on_supported_os.each do |os, os_facts|
|
9 |
context "on #{os}" do |
10 |
let(:facts) { os_facts }
|
11 |
|
12 |
context 'with snat4' do |
13 |
let(:pre_condition) do |
14 |
'
|
15 |
nftables::rules::snat4{
|
16 |
\'static\':
|
17 |
order => \'60\',
|
18 |
snat => \'198.51.100.1\',
|
19 |
oif => \'eth0\';
|
20 |
\'1_1\':
|
21 |
order => \'61\',
|
22 |
saddr => \'192.0.2.2\',
|
23 |
snat => \'198.51.100.3\',
|
24 |
oif => \'eth0\';
|
25 |
\'1_1_smtp\':
|
26 |
saddr => \'192.0.2.2\',
|
27 |
snat => \'198.51.100.2\',
|
28 |
dport => \'25\';
|
29 |
\'1_1_wireguard\':
|
30 |
saddr => \'192.0.2.2\',
|
31 |
snat => \'198.51.100.2\',
|
32 |
proto => \'udp\',
|
33 |
dport => \'51820\';
|
34 |
}
|
35 |
'
|
36 |
end
|
37 |
|
38 |
it { is_expected.to compile } |
39 |
|
40 |
it { |
41 |
expect(subject).to contain_concat('nftables-ip-nat-chain-POSTROUTING').with(
|
42 |
path: '/etc/nftables/puppet-preflight/ip-nat-chain-POSTROUTING.nft', |
43 |
owner: 'root', |
44 |
group: 'root', |
45 |
mode: '0640', |
46 |
ensure_newline: true |
47 |
) |
48 |
} |
49 |
|
50 |
it { |
51 |
expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-header').with(
|
52 |
target: 'nftables-ip-nat-chain-POSTROUTING', |
53 |
content: %r{^chain POSTROUTING \{$}, |
54 |
order: '00' |
55 |
) |
56 |
} |
57 |
|
58 |
it { |
59 |
expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-type').with(
|
60 |
target: 'nftables-ip-nat-chain-POSTROUTING', |
61 |
content: %r{^ type nat hook postrouting priority 100$}, |
62 |
order: '01-nftables-ip-nat-chain-POSTROUTING-rule-type-b' |
63 |
) |
64 |
} |
65 |
|
66 |
it { |
67 |
expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-policy').with(
|
68 |
target: 'nftables-ip-nat-chain-POSTROUTING', |
69 |
content: %r{^ policy accept$}, |
70 |
order: '02-nftables-ip-nat-chain-POSTROUTING-rule-policy-b' |
71 |
) |
72 |
} |
73 |
|
74 |
it { |
75 |
expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-static').with(
|
76 |
target: 'nftables-ip-nat-chain-POSTROUTING', |
77 |
content: %r{^ oifname eth0 snat 198\.51\.100\.1$}, |
78 |
order: '60-nftables-ip-nat-chain-POSTROUTING-rule-static-b' |
79 |
) |
80 |
} |
81 |
|
82 |
it { |
83 |
expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-1_1').with(
|
84 |
target: 'nftables-ip-nat-chain-POSTROUTING', |
85 |
content: %r{^ oifname eth0 ip saddr 192\.0\.2\.2 snat 198\.51\.100\.3$}, |
86 |
order: '61-nftables-ip-nat-chain-POSTROUTING-rule-1_1-b' |
87 |
) |
88 |
} |
89 |
|
90 |
it { |
91 |
expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-1_1_smtp').with(
|
92 |
target: 'nftables-ip-nat-chain-POSTROUTING', |
93 |
content: %r{^ ip saddr 192\.0\.2\.2 tcp dport 25 snat 198\.51\.100\.2$}, |
94 |
order: '70-nftables-ip-nat-chain-POSTROUTING-rule-1_1_smtp-b' |
95 |
) |
96 |
} |
97 |
|
98 |
it { |
99 |
expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-1_1_wireguard').with(
|
100 |
target: 'nftables-ip-nat-chain-POSTROUTING', |
101 |
content: %r{^ ip saddr 192\.0\.2\.2 udp dport 51820 snat 198\.51\.100\.2$}, |
102 |
order: '70-nftables-ip-nat-chain-POSTROUTING-rule-1_1_wireguard-b' |
103 |
) |
104 |
} |
105 |
|
106 |
it { |
107 |
expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-footer').with(
|
108 |
target: 'nftables-ip-nat-chain-POSTROUTING', |
109 |
content: %r{^\}$}, |
110 |
order: '99' |
111 |
) |
112 |
} |
113 |
end
|
114 |
end
|
115 |
end
|
116 |
end
|