Debian Codegraph @

spec/defines/frontend_spec.rb

raw
1 # frozen_string_literal: true
2
3 require 'spec_helper'
4
5 describe 'haproxy::frontend' do
6 let(:pre_condition) { 'include haproxy' }
7 let(:title) { 'tyler' }
8 let(:facts) do
9 {
10 networking: {
11 ip: '1.1.1.1'
12 },
13 os: {
14 family: 'RedHat'
15 },
16 concat_basedir: '/dne'
17 }
18 end
19
20 context 'when only one port is provided' do
21 let(:params) do
22 {
23 name: 'croy',
24 ipaddress: '1.1.1.1',
25 ports: 18_140
26 }
27 end
28
29 it {
30 is_expected.to contain_concat__fragment('haproxy-croy_frontend_block').with(
31 'order' => '15-croy-00',
32 'target' => '/etc/haproxy/haproxy.cfg',
33 'content' => "\nfrontend croy\n bind 1.1.1.1:18140 \n option tcplog\n",
34 )
35 }
36 context 'with stringy port' do
37 let(:params) do
38 super().merge(ports: '18140')
39 end
40
41 it {
42 is_expected.to contain_concat__fragment('haproxy-croy_frontend_block').with(
43 'order' => '15-croy-00',
44 'target' => '/etc/haproxy/haproxy.cfg',
45 'content' => "\nfrontend croy\n bind 1.1.1.1:18140 \n option tcplog\n",
46 )
47 }
48 end
49 end
50
51 # C9948 C9947
52 context 'when an array of ports is provided' do
53 let(:params) do
54 {
55 name: 'apache',
56 ipaddress: '23.23.23.23',
57 ports: [80, 443]
58 }
59 end
60
61 it {
62 is_expected.to contain_concat__fragment('haproxy-apache_frontend_block').with(
63 'order' => '15-apache-00',
64 'target' => '/etc/haproxy/haproxy.cfg',
65 'content' => "\nfrontend apache\n bind 23.23.23.23:80 \n bind 23.23.23.23:443 \n option tcplog\n",
66 )
67 }
68 context 'with stringy port' do
69 let(:params) do
70 super().merge(ports: ['80', '443'])
71 end
72
73 it {
74 is_expected.to contain_concat__fragment('haproxy-apache_frontend_block').with(
75 'order' => '15-apache-00',
76 'target' => '/etc/haproxy/haproxy.cfg',
77 'content' => "\nfrontend apache\n bind 23.23.23.23:80 \n bind 23.23.23.23:443 \n option tcplog\n",
78 )
79 }
80 end
81 # C9948
82 context 'with a comma-seperated list of ports' do
83 let(:params) do
84 super().merge(ports: '80,443')
85 end
86
87 it {
88 is_expected.to contain_concat__fragment('haproxy-apache_frontend_block').with(
89 'order' => '15-apache-00',
90 'target' => '/etc/haproxy/haproxy.cfg',
91 'content' => "\nfrontend apache\n bind 23.23.23.23:80 \n bind 23.23.23.23:443 \n option tcplog\n",
92 )
93 }
94 end
95 end
96
97 # C9971
98 context 'when empty list of ports is provided' do
99 let(:params) do
100 {
101 name: 'apache',
102 ipaddress: '23.23.23.23',
103 ports: []
104 }
105 end
106
107 it {
108 is_expected.to contain_concat__fragment('haproxy-apache_frontend_block').with(
109 'order' => '15-apache-00',
110 'target' => '/etc/haproxy/haproxy.cfg',
111 'content' => "\nfrontend apache\n option tcplog\n",
112 )
113 }
114 end
115
116 # C9972
117 context 'when a port is provided greater than 65535' do
118 let(:params) do
119 {
120 name: 'apache',
121 ipaddress: '23.23.23.23',
122 ports: '80443'
123 }
124 end
125
126 it 'raises error' do
127 expect { catalogue }.to raise_error Puppet::Error, %r{outside of range}
128 end
129 end
130
131 # C9946
132 context 'when multiple ports are provided greater than 65535' do
133 let(:params) do
134 {
135 name: 'apache',
136 ipaddress: '23.23.23.23',
137 ports: ['80443', '80444']
138 }
139 end
140
141 it 'raises error' do
142 expect { catalogue }.to raise_error Puppet::Error, %r{outside of range}
143 end
144 end
145
146 # C9973
147 context 'when an invalid ipv4 address is passed' do
148 let(:params) do
149 {
150 name: 'apache',
151 ipaddress: '2323.23.23',
152 ports: '80'
153 }
154 end
155
156 it 'raises error' do
157 expect { catalogue }.to raise_error Puppet::Error, %r{Invalid IP address}
158 end
159 end
160
161 # C9949
162 context 'when a ports parameter and a bind parameter are passed' do
163 let(:params) do
164 {
165 name: 'apache',
166 bind: { '192.168.0.1:80' => ['ssl'] },
167 ports: '80'
168 }
169 end
170
171 it 'raises error' do
172 expect { catalogue }.to raise_error Puppet::Error, %r{mutually exclusive}
173 end
174 end
175
176 context 'when multiple IPs are provided' do
177 let(:params) do
178 {
179 name: 'apache',
180 ipaddress: ['23.23.23.23', '23.23.23.24'],
181 ports: '80'
182 }
183 end
184
185 it {
186 is_expected.to contain_concat__fragment('haproxy-apache_frontend_block').with(
187 'order' => '15-apache-00',
188 'target' => '/etc/haproxy/haproxy.cfg',
189 'content' => "\nfrontend apache\n bind 23.23.23.23:80 \n bind 23.23.23.24:80 \n option tcplog\n",
190 )
191 }
192 end
193
194 context 'when bind options are provided' do
195 let(:params) do
196 {
197 name: 'apache',
198 ipaddress: '1.1.1.1',
199 ports: ['80', '8080'],
200 bind_options: ['the options', 'go here']
201 }
202 end
203
204 it {
205 is_expected.to contain_concat__fragment('haproxy-apache_frontend_block').with(
206 'order' => '15-apache-00',
207 'target' => '/etc/haproxy/haproxy.cfg',
208 'content' => "\nfrontend apache\n bind 1.1.1.1:80 the options go here\n bind 1.1.1.1:8080 the options go here\n option tcplog\n",
209 )
210 }
211 end
212
213 context 'when bind parameter is used without ipaddress parameter' do
214 let(:params) do
215 {
216 name: 'apache',
217 bind: { '1.1.1.1:80' => [] }
218 }
219 end
220
221 it {
222 is_expected.to contain_concat__fragment('haproxy-apache_frontend_block').with(
223 'order' => '15-apache-00',
224 'target' => '/etc/haproxy/haproxy.cfg',
225 'content' => "\nfrontend apache\n bind 1.1.1.1:80 \n option tcplog\n",
226 )
227 }
228 end
229
230 context 'when bind parameter is used with more complex address constructs' do
231 let(:params) do
232 {
233 name: 'apache',
234 bind: {
235 '1.1.1.1:80' => [],
236 ':443,:8443' => ['ssl', 'crt public.puppetlabs.com', 'no-sslv3'],
237 '2.2.2.2:8000-8010' => ['ssl', 'crt public.puppetlabs.com'],
238 'fd@${FD_APP1}' => [],
239 '/var/run/ssl-frontend.sock' => ['user root', 'mode 600', 'accept-proxy']
240 }
241 }
242 end
243
244 it {
245 is_expected.to contain_concat__fragment('haproxy-apache_frontend_block').with(
246 'order' => '15-apache-00',
247 'target' => '/etc/haproxy/haproxy.cfg',
248 'content' => "\nfrontend apache\n bind /var/run/ssl-frontend.sock user root mode 600 accept-proxy\n bind :443,:8443 ssl crt public.puppetlabs.com no-sslv3\n bind fd@${FD_APP1} \n bind 1.1.1.1:80 \n bind 2.2.2.2:8000-8010 ssl crt public.puppetlabs.com\n option tcplog\n", # rubocop:disable Layout/LineLength
249 )
250 }
251 end
252
253 context 'when bind parameter is used with ip addresses that sort wrong lexigraphically' do
254 let(:params) do
255 {
256 name: 'apache',
257 bind: {
258 '10.1.3.21:80' => [],
259 '8.252.206.100:80' => [],
260 '8.252.206.101:80' => [],
261 '8.252.206.99:80' => [],
262 '1.1.1.1:80' => [],
263 ':443,:8443' => ['ssl', 'crt public.puppetlabs.com', 'no-sslv3'],
264 '2.2.2.2:8000-8010' => ['ssl', 'crt public.puppetlabs.com']
265 }
266 }
267 end
268
269 it {
270 is_expected.to contain_concat__fragment('haproxy-apache_frontend_block').with(
271 'order' => '15-apache-00',
272 'target' => '/etc/haproxy/haproxy.cfg',
273 'content' => "\nfrontend apache\n bind :443,:8443 ssl crt public.puppetlabs.com no-sslv3\n bind 1.1.1.1:80 \n bind 2.2.2.2:8000-8010 ssl crt public.puppetlabs.com\n bind 8.252.206.99:80 \n bind 8.252.206.100:80 \n bind 8.252.206.101:80 \n bind 10.1.3.21:80 \n option tcplog\n", # rubocop:disable Layout/LineLength
274 )
275 }
276 end
277
278 context 'when frontend options are specified as an array of hashes' do
279 let(:params) do
280 {
281 name: 'apache',
282 bind: {
283 '0.0.0.0:48001-48003' => []
284 },
285 mode: 'http',
286 options: [
287 { 'reqadd' => 'X-Forwarded-Proto:\ https' },
288 { 'default_backend' => 'dev00_webapp' },
289 { 'capture request header' => ['X-Forwarded-For len 50', 'Host len 15', 'Referrer len 15'] },
290 { 'acl' => ['dst_dev01 dst_port 48001', 'dst_dev02 dst_port 48002', 'dst_dev03 dst_port 48003'] },
291 { 'use_backend' => ['dev01_webapp if dst_dev01', 'dev02_webapp if dst_dev02', 'dev03_webapp if dst_dev03'] },
292 { 'option' => ['httplog', 'http-server-close', 'forwardfor except 127.0.0.1'] },
293 { 'compression' => 'algo gzip',
294 'bind-process' => 'all' },
295 ]
296 }
297 end
298
299 it {
300 is_expected.to contain_concat__fragment('haproxy-apache_frontend_block').with(
301 'order' => '15-apache-00',
302 'target' => '/etc/haproxy/haproxy.cfg',
303 'content' => "\nfrontend apache\n bind 0.0.0.0:48001-48003 \n mode http\n reqadd X-Forwarded-Proto:\\ https\n default_backend dev00_webapp\n capture request header X-Forwarded-For len 50\n capture request header Host len 15\n capture request header Referrer len 15\n acl dst_dev01 dst_port 48001\n acl dst_dev02 dst_port 48002\n acl dst_dev03 dst_port 48003\n use_backend dev01_webapp if dst_dev01\n use_backend dev02_webapp if dst_dev02\n use_backend dev03_webapp if dst_dev03\n option httplog\n option http-server-close\n option forwardfor except 127.0.0.1\n bind-process all\n compression algo gzip\n", # rubocop:disable Layout/LineLength
304 )
305 }
306 end
307
308 context 'when defaults parameter is used with option default_backend' do
309 let(:params) do
310 {
311 name: 'apache',
312 bind: { '1.1.1.1:80' => [] },
313 defaults: 'test',
314 options: { 'default_backend' => 'b1' }
315 }
316 end
317
318 it {
319 is_expected.to contain_concat__fragment('haproxy-apache_frontend_block').with(
320 'order' => '25-test-b1-00-apache',
321 'target' => '/etc/haproxy/haproxy.cfg',
322 'content' => "\nfrontend apache\n bind 1.1.1.1:80 \n default_backend b1\n",
323 )
324 }
325 end
326
327 context 'when configurung custom options for stick-tables' do
328 let(:title) { 'baz' }
329 let(:buzz) { 'type string len 180 size 32m expire 5m store http_req_rate(10s)' }
330 let(:params) do
331 { options: [
332 { 'stick-table' => buzz },
333 { 'stick' => 'on dst' },
334 ] }
335 end
336
337 it {
338 is_expected.to contain_concat__fragment('haproxy-baz_frontend_block').with(
339 'order' => '15-baz-00',
340 'target' => '/etc/haproxy/haproxy.cfg',
341 'content' => "\nfrontend baz\n stick-table #{buzz}\n stick on dst\n",
342 )
343 }
344 end
345
346 context 'when a non-default config file is used' do
347 let(:pre_condition) { 'class { "haproxy": config_file => "/etc/non-default.cfg" }' }
348 let(:params) do
349 {
350 name: 'bar',
351 bind: {
352 '*:5000' => []
353 },
354 options: {
355 'option' => [
356 'tcplog',
357 ]
358 }
359 }
360 end
361
362 it {
363 is_expected.to contain_concat__fragment('haproxy-bar_frontend_block').with(
364 'order' => '15-bar-00',
365 'target' => '/etc/non-default.cfg',
366 'content' => "\nfrontend bar\n bind *:5000 \n option tcplog\n",
367 )
368 }
369 end
370
371 # C9950 C9951 C9952 WONTFIX
372 end