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