From ca32d5ad3d19563d864a0ce0e6d0313a48227bbc Mon Sep 17 00:00:00 2001 From: Guillaume Quintard Date: Thu, 25 Jan 2024 11:57:05 -0800 Subject: [PATCH] [vcl] test uncacheability rules --- dev/tests/varnish/no-caching.vtc | 95 ++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 dev/tests/varnish/no-caching.vtc diff --git a/dev/tests/varnish/no-caching.vtc b/dev/tests/varnish/no-caching.vtc new file mode 100644 index 0000000000000..1144c91a23478 --- /dev/null +++ b/dev/tests/varnish/no-caching.vtc @@ -0,0 +1,95 @@ +varnishtest "X-Magento-Cache-Debug header" + +server s1 { + # first request will be the probe, handle it and be on our way + rxreq + expect req.url == "/health_check.php" + txresp + + # the probe expects the connection to close + close + accept + + # the client will send 2 requests for each url, the server should only see one + # of each in the cacheable case, and two otherwise + + # 405, Cache-Control doesn't matter + loop 2 { + rxreq + expect req.url == "/405uncacheable" + txresp -status 405 + } + + # 200, private Cache-Control + loop 2 { + rxreq + expect req.url == "/200uncacheable" + txresp -status 200 -hdr "cache-control: private" + } + + # 404, private Cache-Control + loop 2 { + rxreq + expect req.url == "/404uncacheable" + txresp -status 200 -hdr "cache-control: private" + } + + # 200, no Cache-Control + rxreq + expect req.url == "/200cacheable" + txresp -status 200 + + # 404, but still no Cache-Control + rxreq + expect req.url == "/404cacheable" + txresp -status 404 +} -start + +# generate usable VCL pointing towards s1 +# mostly, we replace the place-holders, but we also jack up the probe +# interval to avoid further interference +shell { + # testdir is automatically set to the directory containing the present vtc + sed \ + -e 's@\.interval = 5s;@.interval = 5m; .initial = 10;@' \ + -e 's@/\* {{ host }} \*/@${s1_addr}@' \ + -e 's@/\* {{ port }} \*/@${s1_port}@' \ + -e 's@/\* {{ ssl_offloaded_header }} \*/@unused@' \ + -e 's@/\* {{ grace_period }} \*/@0@' \ + ${testdir}/../../../app/code/Magento/PageCache/etc/varnish6.vcl > ${tmpdir}/output.vcl +} + +varnish v1 -arg "-f" -arg "${tmpdir}/output.vcl" -start + +# make sure the probe request fired +delay 1 + +client c1 { + loop 2 { + txreq -url /405uncacheable + rxresp + } + + loop 2 { + txreq -url /200uncacheable + rxresp + } + + loop 2 { + txreq -url /404uncacheable + rxresp + } + + loop 2 { + txreq -url /200cacheable + rxresp + } + + loop 2 { + txreq -url /404cacheable + rxresp + } +} -run + +# make sure s1 saw all the requests it was expecting +server s1 -wait