root / spec / classes / router_spec.rb @ 9ae64df9
Historique | Voir | Annoter | Télécharger (5,93 ko)
1 |
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 "as router" do |
11 |
let(:pre_condition) {
|
12 |
""" |
13 |
# inet-filter-chain-default_fwd
|
14 |
nftables::rule{
|
15 |
'default_fwd-out':
|
16 |
order => '20',
|
17 |
content => 'iifname eth1 oifname eth0 accept';
|
18 |
'default_fwd-drop':
|
19 |
order => '90',
|
20 |
content => 'iifname eth0 drop';
|
21 |
'default_fwd-in_web':
|
22 |
order => '30',
|
23 |
content => 'iifname eth0 oifname eth1 ip daddr 192.0.2.2 tcp dport { http, https } accept';
|
24 |
'PREROUTING-in_web':
|
25 |
table => 'ip-nat',
|
26 |
order => '30',
|
27 |
content => 'iifname eth0 tcp dport { http, https } dnat to 192.0.2.2';
|
28 |
'POSTROUTING-masquerade':
|
29 |
table => 'ip-nat',
|
30 |
order => '20',
|
31 |
content => 'oifname eth0 masquerade';
|
32 |
}
|
33 |
""" |
34 |
} |
35 |
|
36 |
it { is_expected.to compile } |
37 |
|
38 |
it { is_expected.to contain_concat('nftables-inet-filter-chain-default_fwd').with(
|
39 |
:path => '/etc/nftables/puppet/inet-filter-chain-default_fwd.nft', |
40 |
:owner => 'root', |
41 |
:group => 'root', |
42 |
:mode => '0640', |
43 |
:ensure_newline => true, |
44 |
)} |
45 |
it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-header').with(
|
46 |
:target => 'nftables-inet-filter-chain-default_fwd', |
47 |
:content => /^chain default_fwd {$/, |
48 |
:order => '00', |
49 |
)} |
50 |
it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-out').with(
|
51 |
:target => 'nftables-inet-filter-chain-default_fwd', |
52 |
:content => /^ iifname eth1 oifname eth0 accept$/, |
53 |
:order => '20', |
54 |
)} |
55 |
it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-in_web').with(
|
56 |
:target => 'nftables-inet-filter-chain-default_fwd', |
57 |
:content => /^ iifname eth0 oifname eth1 ip daddr 192.0.2.2 tcp dport \{ http, https \} accept$/, |
58 |
:order => '30', |
59 |
)} |
60 |
it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-drop').with(
|
61 |
:target => 'nftables-inet-filter-chain-default_fwd', |
62 |
:content => /^ iifname eth0 drop$/, |
63 |
:order => '90', |
64 |
)} |
65 |
it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-footer').with(
|
66 |
:target => 'nftables-inet-filter-chain-default_fwd', |
67 |
:content => /^}$/, |
68 |
:order => '99', |
69 |
)} |
70 |
|
71 |
it { is_expected.to contain_concat('nftables-ip-nat-chain-PREROUTING').with(
|
72 |
:path => '/etc/nftables/puppet/ip-nat-chain-PREROUTING.nft', |
73 |
:owner => 'root', |
74 |
:group => 'root', |
75 |
:mode => '0640', |
76 |
:ensure_newline => true, |
77 |
)} |
78 |
it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-header').with(
|
79 |
:target => 'nftables-ip-nat-chain-PREROUTING', |
80 |
:content => /^chain PREROUTING {$/, |
81 |
:order => '00', |
82 |
)} |
83 |
it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-type').with(
|
84 |
:target => 'nftables-ip-nat-chain-PREROUTING', |
85 |
:content => /^ type nat hook prerouting priority -100$/, |
86 |
:order => '01', |
87 |
)} |
88 |
it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-policy').with(
|
89 |
:target => 'nftables-ip-nat-chain-PREROUTING', |
90 |
:content => /^ policy accept$/, |
91 |
:order => '02', |
92 |
)} |
93 |
it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-in_web').with(
|
94 |
:target => 'nftables-ip-nat-chain-PREROUTING', |
95 |
:content => /^ iifname eth0 tcp dport \{ http, https \} dnat to 192.0.2.2$/, |
96 |
:order => '30', |
97 |
)} |
98 |
it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-footer').with(
|
99 |
:target => 'nftables-ip-nat-chain-PREROUTING', |
100 |
:content => /^}$/, |
101 |
:order => '99', |
102 |
)} |
103 |
|
104 |
it { is_expected.to contain_concat('nftables-ip-nat-chain-POSTROUTING').with(
|
105 |
:path => '/etc/nftables/puppet/ip-nat-chain-POSTROUTING.nft', |
106 |
:owner => 'root', |
107 |
:group => 'root', |
108 |
:mode => '0640', |
109 |
:ensure_newline => true, |
110 |
)} |
111 |
it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-header').with(
|
112 |
:target => 'nftables-ip-nat-chain-POSTROUTING', |
113 |
:content => /^chain POSTROUTING {$/, |
114 |
:order => '00', |
115 |
)} |
116 |
it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-type').with(
|
117 |
:target => 'nftables-ip-nat-chain-POSTROUTING', |
118 |
:content => /^ type nat hook postrouting priority 100$/, |
119 |
:order => '01', |
120 |
)} |
121 |
it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-policy').with(
|
122 |
:target => 'nftables-ip-nat-chain-POSTROUTING', |
123 |
:content => /^ policy accept$/, |
124 |
:order => '02', |
125 |
)} |
126 |
it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade').with(
|
127 |
:target => 'nftables-ip-nat-chain-POSTROUTING', |
128 |
:content => /^ oifname eth0 masquerade$/, |
129 |
:order => '20', |
130 |
)} |
131 |
it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-footer').with(
|
132 |
:target => 'nftables-ip-nat-chain-POSTROUTING', |
133 |
:content => /^}$/, |
134 |
:order => '99', |
135 |
)} |
136 |
end
|
137 |
end
|
138 |
end
|
139 |
end
|