summaryrefslogtreecommitdiff
path: root/contrib/varnish/cgit-esi.vtc
blob: 671d6a1b79c9146d65a00969ebe594bfcddfc055 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
vtest "cgit ESI diff fragments are shared across repositories"

# Run with:  varnishtest -D cgit_vcl=$PWD/cgit-esi.vcl cgit-esi.vtc

server s1 {
	# Frame for the commit as seen through fork a.git
	rxreq
	expect req.url == "/a.git/commit/?id=abc"
	txresp -hdr {Surrogate-Control: content="ESI/1.0"} \
	    -body {<html><head><base href='/a.git/'/></head><body>A:<esi:include src='/a.git/esi-diff/?id=abc&id2=def&dt=0'/>:Z</body></html>}

	# The fragment, fetched exactly once
	rxreq
	expect req.url == "/a.git/esi-diff/?id=abc&id2=def&dt=0"
	expect req.http.Cookie == <undef>
	txresp -body {<div class='diff'>DIFF</div>}

	# Frame for the same commit through fork b.git; no fragment fetch follows
	rxreq
	expect req.url == "/b.git/commit/?id=abc&h=next"
	txresp -hdr {Surrogate-Control: content="ESI/1.0"} \
	    -body {<html><head><base href='/b.git/'/></head><body>B:<esi:include src='/b.git/esi-diff/?id=abc&id2=def&dt=0'/>:Z</body></html>}

	# A different diff option is a different fragment
	rxreq
	expect req.url == "/b.git/commit/?id=abc&dt=1"
	txresp -hdr {Surrogate-Control: content="ESI/1.0"} \
	    -body {<html><body>B:<esi:include src='/b.git/esi-diff/?id=abc&id2=def&dt=1'/>:Z</body></html>}
	rxreq
	expect req.url == "/b.git/esi-diff/?id=abc&id2=def&dt=1"
	txresp -body {<table class='ssdiff'>SSDIFF</table>}
} -start

varnish v1 -vcl+backend {
	include "${cgit_vcl}";
} -start

client c1 {
	txreq -url "/a.git/commit/?id=abc" -hdr "Cookie: session=1"
	rxresp
	expect resp.status == 200
	expect resp.http.Surrogate-Control == <undef>
	expect resp.body == "<html><head><base href='/a.git/'/></head><body>A:<div class='diff'>DIFF</div>:Z</body></html>"

	txreq -url "/b.git/commit/?id=abc&h=next"
	rxresp
	expect resp.status == 200
	expect resp.body == "<html><head><base href='/b.git/'/></head><body>B:<div class='diff'>DIFF</div>:Z</body></html>"

	txreq -url "/b.git/commit/?id=abc&dt=1"
	rxresp
	expect resp.status == 200
	expect resp.body == "<html><body>B:<table class='ssdiff'>SSDIFF</table>:Z</body></html>"

	# Fragments cannot be fetched from the outside
	txreq -url "/a.git/esi-diff/?id=abc&id2=def&dt=0"
	rxresp
	expect resp.status == 403
} -run

# Two frames, two distinct fragments: four backend fetches in total, i.e.
# the second fork did not re-render the diff.
varnish v1 -expect n_object == 4
varnish v1 -expect cache_hit == 1