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