root / spec / classes / rules / qemu_spec.rb @ 7937a13b
Historique | Voir | Annoter | Télécharger (5,68 ko)
1 |
# frozen_string_literal: true
|
---|---|
2 |
|
3 |
require 'spec_helper'
|
4 |
|
5 |
describe 'nftables::rules::qemu' do |
6 |
on_supported_os.each do |os, os_facts|
|
7 |
context "on #{os}" do |
8 |
let(:facts) { os_facts }
|
9 |
let(:pre_condition) { 'include nftables' } |
10 |
|
11 |
context 'default options' do |
12 |
it { is_expected.to compile } |
13 |
|
14 |
it { |
15 |
expect(subject).to contain_nftables__rule('default_in-qemu_udp_dns').
|
16 |
with_content('iifname "virbr0" udp dport 53 accept')
|
17 |
} |
18 |
|
19 |
it { |
20 |
expect(subject).to contain_nftables__rule('default_in-qemu_tcp_dns').
|
21 |
with_content('iifname "virbr0" tcp dport 53 accept')
|
22 |
} |
23 |
|
24 |
it { |
25 |
expect(subject).to contain_nftables__rule('default_in-qemu_dhcpv4').
|
26 |
with_content('iifname "virbr0" meta l4proto udp udp dport 67 accept')
|
27 |
} |
28 |
|
29 |
it { |
30 |
expect(subject).to contain_nftables__rule('default_fwd-qemu_oip_v4').
|
31 |
with_content('oifname "virbr0" ip daddr 192.168.122.0/24 ct state related,established accept')
|
32 |
} |
33 |
|
34 |
it { |
35 |
expect(subject).to contain_nftables__rule('default_fwd-qemu_iip_v4').
|
36 |
with_content('iifname "virbr0" ip saddr 192.168.122.0/24 accept')
|
37 |
} |
38 |
|
39 |
it { is_expected.not_to contain_nftables__rule('default_fwd-qemu_oip_v6') }
|
40 |
it { is_expected.not_to contain_nftables__rule('default_fwd-qemu_iip_v6') }
|
41 |
|
42 |
it { |
43 |
expect(subject).to contain_nftables__rule('default_fwd-qemu_io_internal').
|
44 |
with_content('iifname "virbr0" oifname "virbr0" accept')
|
45 |
} |
46 |
|
47 |
it { |
48 |
expect(subject).to contain_nftables__rule('POSTROUTING-qemu_ignore_multicast').with(
|
49 |
content: 'ip saddr 192.168.122.0/24 ip daddr 224.0.0.0/24 return', |
50 |
table: 'ip-nat' |
51 |
) |
52 |
} |
53 |
|
54 |
it { |
55 |
expect(subject).to contain_nftables__rule('POSTROUTING-qemu_ignore_broadcast').with(
|
56 |
content: 'ip saddr 192.168.122.0/24 ip daddr 255.255.255.255 return', |
57 |
table: 'ip-nat' |
58 |
) |
59 |
} |
60 |
|
61 |
it { |
62 |
expect(subject).to contain_nftables__rule('POSTROUTING-qemu_masq_tcp').with(
|
63 |
content: 'meta l4proto tcp ip saddr 192.168.122.0/24 ip daddr != 192.168.122.0/24 masquerade to :1024-65535', |
64 |
table: 'ip-nat' |
65 |
) |
66 |
} |
67 |
|
68 |
it { |
69 |
expect(subject).to contain_nftables__rule('POSTROUTING-qemu_masq_udp').with(
|
70 |
content: 'meta l4proto udp ip saddr 192.168.122.0/24 ip daddr != 192.168.122.0/24 masquerade to :1024-65535', |
71 |
table: 'ip-nat' |
72 |
) |
73 |
} |
74 |
|
75 |
it { |
76 |
expect(subject).to contain_nftables__rule('POSTROUTING-qemu_masq_ip').with(
|
77 |
content: 'ip saddr 192.168.122.0/24 ip daddr != 192.168.122.0/24 masquerade', |
78 |
table: 'ip-nat' |
79 |
) |
80 |
} |
81 |
end
|
82 |
|
83 |
context 'with all off' do |
84 |
let(:params) do |
85 |
{ |
86 |
dns: false, |
87 |
dhcpv4: false, |
88 |
forward_traffic: false, |
89 |
internal_traffic: false, |
90 |
masquerade: false, |
91 |
} |
92 |
end
|
93 |
|
94 |
it { is_expected.to compile } |
95 |
it { is_expected.not_to contain_nftables__rule('default_in-qemu_udp_dns') }
|
96 |
it { is_expected.not_to contain_nftables__rule('default_in-qemu_tcp_dns') }
|
97 |
it { is_expected.not_to contain_nftables__rule('default_in-qemu_dhcpv4') }
|
98 |
it { is_expected.not_to contain_nftables__rule('default_fwd-qemu_oip_v4') }
|
99 |
it { is_expected.not_to contain_nftables__rule('default_fwd-qemu_iip_v4') }
|
100 |
it { is_expected.not_to contain_nftables__rule('default_fwd-qemu_io_internal') }
|
101 |
it { is_expected.not_to contain_nftables__rule('POSTROUTING-qemu_ignore_multicast') }
|
102 |
it { is_expected.not_to contain_nftables__rule('POSTROUTING-qemu_ignore_broadcast') }
|
103 |
it { is_expected.not_to contain_nftables__rule('POSTROUTING-qemu_masq_tcp') }
|
104 |
it { is_expected.not_to contain_nftables__rule('POSTROUTING-qemu_masq_udp') }
|
105 |
it { is_expected.not_to contain_nftables__rule('POSTROUTING-qemu_masq_ip') }
|
106 |
end
|
107 |
|
108 |
context 'ipv6 prefix' do |
109 |
let(:params) do |
110 |
{ |
111 |
network_v6: '20ac:cafe:1:1::/64', |
112 |
} |
113 |
end
|
114 |
|
115 |
it { is_expected.to compile } |
116 |
|
117 |
it { |
118 |
expect(subject).to contain_nftables__rule('default_fwd-qemu_oip_v4').
|
119 |
with_content('oifname "virbr0" ip daddr 192.168.122.0/24 ct state related,established accept')
|
120 |
} |
121 |
|
122 |
it { |
123 |
expect(subject).to contain_nftables__rule('default_fwd-qemu_iip_v4').
|
124 |
with_content('iifname "virbr0" ip saddr 192.168.122.0/24 accept')
|
125 |
} |
126 |
|
127 |
it { |
128 |
expect(subject).to contain_nftables__rule('default_fwd-qemu_oip_v6').
|
129 |
with_content('oifname "virbr0" ip6 daddr 20ac:cafe:1:1::/64 ct state related,established accept')
|
130 |
} |
131 |
|
132 |
it { |
133 |
expect(subject).to contain_nftables__rule('default_fwd-qemu_iip_v6').
|
134 |
with_content('iifname "virbr0" ip6 saddr 20ac:cafe:1:1::/64 accept')
|
135 |
} |
136 |
end
|
137 |
|
138 |
context 'change interface' do |
139 |
let(:params) do |
140 |
{ |
141 |
interface: 'vfoo0' |
142 |
} |
143 |
end
|
144 |
|
145 |
it { is_expected.to compile } |
146 |
|
147 |
it { |
148 |
expect(subject).to contain_nftables__rule('default_fwd-qemu_iip_v4').
|
149 |
with_content('iifname "vfoo0" ip saddr 192.168.122.0/24 accept')
|
150 |
} |
151 |
end
|
152 |
|
153 |
context 'change ipv4 prefix' do |
154 |
let(:params) do |
155 |
{ |
156 |
network_v4: '172.16.0.0/12' |
157 |
} |
158 |
end
|
159 |
|
160 |
it { is_expected.to compile } |
161 |
|
162 |
it { |
163 |
expect(subject).to contain_nftables__rule('default_fwd-qemu_iip_v4').
|
164 |
with_content('iifname "virbr0" ip saddr 172.16.0.0/12 accept')
|
165 |
} |
166 |
end
|
167 |
end
|
168 |
end
|
169 |
end
|