root / spec / classes / masquerade_spec.rb @ ece9be27
Historique | Voir | Annoter | Télécharger (3,71 ko)
1 | 2a3b45ec | tr | require 'spec_helper'
|
---|---|---|---|
2 | |||
3 | describe 'nftables' do |
||
4 | let(:pre_condition) { 'Exec{path => "/bin"}' } |
||
5 | |||
6 | on_supported_os.each do |os, os_facts|
|
||
7 | context "on #{os}" do |
||
8 | let(:facts) { os_facts }
|
||
9 | |||
10 | context 'with masquerade' do |
||
11 | let(:pre_condition) do |
||
12 | """ |
||
13 | nftables::rules::masquerade{
|
||
14 | 'masquerade_eth0':
|
||
15 | oif => 'eth0';
|
||
16 | 'masquerade_eth1_vpn':
|
||
17 | oif => 'eth1',
|
||
18 | saddr => '192.0.2.0/24';
|
||
19 | a0d5c724 | tr | 'masquerade_ssh':
|
20 | 2a3b45ec | tr | saddr => '192.0.2.0/24',
|
21 | daddr => '198.51.100.2',
|
||
22 | proto => 'tcp',
|
||
23 | dport => '22';
|
||
24 | a0d5c724 | tr | 'masquerade_ssh_gitlab':
|
25 | saddr => '192.0.2.0/24',
|
||
26 | daddr => '198.51.100.2',
|
||
27 | dport => '22';
|
||
28 | 2a3b45ec | tr | 'masquerade_wireguard':
|
29 | proto => 'udp',
|
||
30 | dport => '51820';
|
||
31 | }
|
||
32 | """ |
||
33 | end
|
||
34 | |||
35 | it { is_expected.to compile } |
||
36 | |||
37 | it { is_expected.to contain_concat('nftables-ip-nat-chain-POSTROUTING').with(
|
||
38 | :path => '/etc/nftables/puppet/ip-nat-chain-POSTROUTING.nft', |
||
39 | :owner => 'root', |
||
40 | :group => 'root', |
||
41 | :mode => '0640', |
||
42 | :ensure_newline => true, |
||
43 | )} |
||
44 | it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-header').with(
|
||
45 | :target => 'nftables-ip-nat-chain-POSTROUTING', |
||
46 | :content => /^chain POSTROUTING {$/, |
||
47 | :order => '00', |
||
48 | )} |
||
49 | it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-type').with(
|
||
50 | :target => 'nftables-ip-nat-chain-POSTROUTING', |
||
51 | :content => /^ type nat hook postrouting priority 100$/, |
||
52 | :order => '01', |
||
53 | )} |
||
54 | it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-policy').with(
|
||
55 | :target => 'nftables-ip-nat-chain-POSTROUTING', |
||
56 | :content => /^ policy accept$/, |
||
57 | :order => '02', |
||
58 | )} |
||
59 | it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_eth0').with(
|
||
60 | :target => 'nftables-ip-nat-chain-POSTROUTING', |
||
61 | :content => /^ oifname eth0 masquerade$/, |
||
62 | :order => '70', |
||
63 | )} |
||
64 | it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_eth1_vpn').with(
|
||
65 | :target => 'nftables-ip-nat-chain-POSTROUTING', |
||
66 | :content => /^ oifname eth1 ip saddr 192\.0\.2\.0\/24 masquerade$/, |
||
67 | :order => '70', |
||
68 | )} |
||
69 | a0d5c724 | tr | it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_ssh').with(
|
70 | :target => 'nftables-ip-nat-chain-POSTROUTING', |
||
71 | :content => /^ ip saddr 192\.0\.2\.0\/24 ip daddr 198.51.100.2 tcp dport 22 masquerade$/, |
||
72 | :order => '70', |
||
73 | )} |
||
74 | 2a3b45ec | tr | it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_ssh_gitlab').with(
|
75 | :target => 'nftables-ip-nat-chain-POSTROUTING', |
||
76 | :content => /^ ip saddr 192\.0\.2\.0\/24 ip daddr 198.51.100.2 tcp dport 22 masquerade$/, |
||
77 | :order => '70', |
||
78 | )} |
||
79 | it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_wireguard').with(
|
||
80 | :target => 'nftables-ip-nat-chain-POSTROUTING', |
||
81 | :content => /^ udp dport 51820 masquerade$/, |
||
82 | :order => '70', |
||
83 | )} |
||
84 | it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-footer').with(
|
||
85 | :target => 'nftables-ip-nat-chain-POSTROUTING', |
||
86 | :content => /^}$/, |
||
87 | :order => '99', |
||
88 | )} |
||
89 | end
|
||
90 | end
|
||
91 | end
|
||
92 | end |