root / spec / defines / simplerule_spec.rb @ 77abc10b
Historique | Voir | Annoter | Télécharger (5,37 ko)
1 | 83382bb5 | Nacho Barrientos | require 'spec_helper'
|
---|---|---|---|
2 | |||
3 | describe 'nftables::simplerule' do |
||
4 | let(:pre_condition) { 'include nftables' } |
||
5 | |||
6 | let(:title) { 'my_default_rule_name' } |
||
7 | |||
8 | on_supported_os.each do |os, os_facts|
|
||
9 | context "on #{os}" do |
||
10 | let(:facts) { os_facts }
|
||
11 | |||
12 | describe 'minimum instantiation' do |
||
13 | it { is_expected.to compile } |
||
14 | it { |
||
15 | is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
||
16 | content: 'accept', |
||
17 | 3a52fb41 | Nacho Barrientos | order: '50', |
18 | 83382bb5 | Nacho Barrientos | ) |
19 | } |
||
20 | end
|
||
21 | |||
22 | 77abc10b | Nacho Barrientos | describe 'dport without protocol' do |
23 | d38aab5b | Nacho Barrientos | let(:params) do |
24 | { |
||
25 | dport: 333, |
||
26 | } |
||
27 | end
|
||
28 | |||
29 | it { is_expected.not_to compile } |
||
30 | end
|
||
31 | |||
32 | 77abc10b | Nacho Barrientos | describe 'sport without protocol' do |
33 | let(:params) do |
||
34 | { |
||
35 | sport: 333, |
||
36 | } |
||
37 | end
|
||
38 | |||
39 | it { is_expected.not_to compile } |
||
40 | end
|
||
41 | |||
42 | 83382bb5 | Nacho Barrientos | describe 'all parameters provided' do |
43 | let(:title) { 'my_big_rule' } |
||
44 | let(:params) do |
||
45 | { |
||
46 | action: 'accept', |
||
47 | comment: 'this is my rule', |
||
48 | d43ced4d | Nacho Barrientos | counter: true, |
49 | 83382bb5 | Nacho Barrientos | dport: 333, |
50 | 77abc10b | Nacho Barrientos | sport: 444, |
51 | 83382bb5 | Nacho Barrientos | proto: 'udp', |
52 | chain: 'default_out', |
||
53 | aaa37172 | Nacho Barrientos | daddr: '2001:1458::/32', |
54 | 83382bb5 | Nacho Barrientos | } |
55 | end
|
||
56 | |||
57 | it { is_expected.to compile } |
||
58 | it { |
||
59 | is_expected.to contain_nftables__rule('default_out-my_big_rule').with(
|
||
60 | 77abc10b | Nacho Barrientos | content: 'udp sport {444} udp dport {333} ip6 daddr 2001:1458::/32 counter accept comment "this is my rule"', |
61 | 3a52fb41 | Nacho Barrientos | order: '50', |
62 | ) |
||
63 | } |
||
64 | end
|
||
65 | |||
66 | describe 'port range' do |
||
67 | let(:params) do |
||
68 | { |
||
69 | dport: '333-334', |
||
70 | 77abc10b | Nacho Barrientos | sport: '1-2', |
71 | 3a52fb41 | Nacho Barrientos | proto: 'tcp', |
72 | } |
||
73 | end
|
||
74 | |||
75 | it { is_expected.to compile } |
||
76 | it { |
||
77 | is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
||
78 | 77abc10b | Nacho Barrientos | content: 'tcp sport {1-2} tcp dport {333-334} accept', |
79 | 3a52fb41 | Nacho Barrientos | ) |
80 | } |
||
81 | end
|
||
82 | |||
83 | describe 'port array' do |
||
84 | let(:params) do |
||
85 | { |
||
86 | dport: [333, 335], |
||
87 | 77abc10b | Nacho Barrientos | sport: [433, 435], |
88 | proto: 'tcp', |
||
89 | } |
||
90 | end
|
||
91 | |||
92 | it { is_expected.to compile } |
||
93 | it { |
||
94 | is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
||
95 | content: 'tcp sport {433, 435} tcp dport {333, 335} accept', |
||
96 | ) |
||
97 | } |
||
98 | end
|
||
99 | |||
100 | describe 'only sport TCP traffic' do |
||
101 | let(:params) do |
||
102 | { |
||
103 | sport: 555, |
||
104 | 3a52fb41 | Nacho Barrientos | proto: 'tcp', |
105 | } |
||
106 | end
|
||
107 | |||
108 | it { is_expected.to compile } |
||
109 | it { |
||
110 | is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
||
111 | 77abc10b | Nacho Barrientos | content: 'tcp sport {555} accept', |
112 | 83382bb5 | Nacho Barrientos | ) |
113 | } |
||
114 | end
|
||
115 | 316bc3f8 | Nacho Barrientos | |
116 | describe 'only IPv4 TCP traffic' do |
||
117 | let(:params) do |
||
118 | { |
||
119 | dport: 333, |
||
120 | proto: 'tcp4', |
||
121 | } |
||
122 | end
|
||
123 | |||
124 | it { is_expected.to compile } |
||
125 | it { |
||
126 | is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
||
127 | 6793d286 | Nacho Barrientos | content: 'ip version 4 tcp dport {333} accept', |
128 | 316bc3f8 | Nacho Barrientos | ) |
129 | } |
||
130 | end
|
||
131 | |||
132 | describe 'only IPv6 UDP traffic' do |
||
133 | let(:params) do |
||
134 | { |
||
135 | dport: 33, |
||
136 | proto: 'udp6', |
||
137 | } |
||
138 | end
|
||
139 | |||
140 | it { is_expected.to compile } |
||
141 | it { |
||
142 | is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
||
143 | 6793d286 | Nacho Barrientos | content: 'ip version 6 udp dport {33} accept', |
144 | 316bc3f8 | Nacho Barrientos | ) |
145 | } |
||
146 | end
|
||
147 | aaa37172 | Nacho Barrientos | |
148 | describe 'with an IPv4 CIDR as daddr' do |
||
149 | let(:params) do |
||
150 | { |
||
151 | daddr: '192.168.0.1/24', |
||
152 | dport: 33, |
||
153 | proto: 'tcp', |
||
154 | } |
||
155 | end
|
||
156 | |||
157 | it { is_expected.to compile } |
||
158 | it { |
||
159 | is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
||
160 | 6793d286 | Nacho Barrientos | content: 'tcp dport {33} ip daddr 192.168.0.1/24 accept', |
161 | aaa37172 | Nacho Barrientos | ) |
162 | } |
||
163 | end
|
||
164 | |||
165 | describe 'with an IPv6 address as daddr' do |
||
166 | let(:params) do |
||
167 | { |
||
168 | daddr: '2001:1458::1', |
||
169 | } |
||
170 | end
|
||
171 | |||
172 | it { is_expected.to compile } |
||
173 | it { |
||
174 | is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
||
175 | content: 'ip6 daddr 2001:1458::1 accept', |
||
176 | ) |
||
177 | } |
||
178 | end
|
||
179 | |||
180 | describe 'with an IPv6 set as daddr, default set_type' do |
||
181 | let(:params) do |
||
182 | { |
||
183 | daddr: '@my6_set', |
||
184 | } |
||
185 | end
|
||
186 | |||
187 | it { is_expected.to compile } |
||
188 | it { |
||
189 | is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
||
190 | content: 'ip6 daddr @my6_set accept', |
||
191 | ) |
||
192 | } |
||
193 | end
|
||
194 | |||
195 | describe 'with a IPv4 set as daddr' do |
||
196 | let(:params) do |
||
197 | { |
||
198 | daddr: '@my4_set', |
||
199 | set_type: 'ip', |
||
200 | } |
||
201 | end
|
||
202 | |||
203 | it { is_expected.to compile } |
||
204 | it { |
||
205 | is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
||
206 | content: 'ip daddr @my4_set accept', |
||
207 | ) |
||
208 | } |
||
209 | end
|
||
210 | |||
211 | d43ced4d | Nacho Barrientos | describe 'with counter enabled' do |
212 | let(:params) do |
||
213 | { |
||
214 | counter: true, |
||
215 | } |
||
216 | end
|
||
217 | |||
218 | it { is_expected.to compile } |
||
219 | it { |
||
220 | is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
|
||
221 | content: 'counter accept', |
||
222 | ) |
||
223 | } |
||
224 | end
|
||
225 | 83382bb5 | Nacho Barrientos | end
|
226 | end
|
||
227 | end |