1
+ varnishtest "GraphQL X-Magento-Cache-Id validation & cache bypassing"
2
+
3
+ server s1 {
4
+ # first request will be the probe, handle it and be on our way
5
+ rxreq
6
+ expect req.url == "/health_check.php"
7
+ txresp
8
+
9
+ # the probe expects the connection to close
10
+ close
11
+ accept
12
+
13
+ # 1. First MISS
14
+ rxreq
15
+ expect req.url == "/graphql"
16
+ expect req.method == "GET"
17
+ expect req.http.X-Magento-Cache-Id == <undef>
18
+ txresp
19
+
20
+ # 3. UNCACHEABLE (Cache-Id mismatch)
21
+ rxreq
22
+ expect req.url == "/graphql"
23
+ expect req.method == "GET"
24
+ expect req.http.X-Magento-Cache-Id == "1234"
25
+ txresp -hdr "X-Magento-Cache-Id: notmatching"
26
+
27
+ # 4. MISS with Cache-Id
28
+ rxreq
29
+ expect req.url == "/graphql"
30
+ expect req.method == "GET"
31
+ expect req.http.X-Magento-Cache-Id == "12345"
32
+ txresp -hdr "X-Magento-Cache-Id: 12345"
33
+
34
+ # 6. MISS with different Cache-Id
35
+ rxreq
36
+ expect req.url == "/graphql"
37
+ expect req.method == "GET"
38
+ expect req.http.X-Magento-Cache-Id == "12346"
39
+ txresp -hdr "X-Magento-Cache-Id: 12346"
40
+
41
+ # 7. MISS with Store header
42
+ rxreq
43
+ expect req.url == "/graphql"
44
+ expect req.method == "GET"
45
+ expect req.http.X-Magento-Cache-Id == "12345"
46
+ expect req.http.Store == "1"
47
+ txresp -hdr "X-Magento-Cache-Id: 12345" -hdr "Store: 1"
48
+
49
+ # 8. MISS with Store and Currency
50
+ rxreq
51
+ expect req.url == "/graphql"
52
+ expect req.method == "GET"
53
+ expect req.http.X-Magento-Cache-Id == "12345"
54
+ expect req.http.Store == "1"
55
+ expect req.http.Content-Currency == "1"
56
+ txresp -hdr "X-Magento-Cache-Id: 12345" -hdr "Store: 1" -hdr "Content-Currency: 1"
57
+
58
+ # 9. UNCACHEABLE with Authorization
59
+ rxreq
60
+ expect req.url == "/graphql"
61
+ expect req.method == "GET"
62
+ expect req.http.X-Magento-Cache-Id == <undef>
63
+ expect req.http.Authorization == "Bearer 12345"
64
+ txresp
65
+
66
+ # 10. MISS with Authorization and Cache-Id
67
+ rxreq
68
+ expect req.url == "/graphql"
69
+ expect req.method == "GET"
70
+ expect req.http.X-Magento-Cache-Id == "12345"
71
+ expect req.http.Authorization == "Bearer 12345"
72
+ txresp -hdr "X-Magento-Cache-Id: 12345"
73
+ } -start
74
+
75
+ # Generate the VCL file based on included variables and write it to output.vcl
76
+ shell {
77
+ export s1_addr="${s1_addr}"
78
+ export s1_port="${s1_port}"
79
+ ${testdir}/helpers/parse_vcl.pl "${testdir}/../../etc/varnish6.vcl" "${tmpdir}/output.vcl"
80
+ }
81
+
82
+ varnish v1 -arg "-f" -arg "${tmpdir}/output.vcl" -arg "-p" -arg "vsl_mask=+Hash" -start
83
+
84
+ # make sure the probe request fired
85
+ delay 1
86
+
87
+ client c1 {
88
+ txreq -method "GET" -url "/graphql"
89
+ rxresp
90
+ expect resp.http.X-Magento-Cache-Debug == "MISS"
91
+
92
+ txreq -method "GET" -url "/graphql"
93
+ rxresp
94
+ expect resp.http.X-Magento-Cache-Debug == "HIT"
95
+
96
+ txreq -method "GET" -url "/graphql" \
97
+ -hdr "X-Magento-Cache-Id: 1234"
98
+ rxresp
99
+ expect resp.http.X-Magento-Cache-Debug == "UNCACHEABLE"
100
+
101
+ txreq -method "GET" -url "/graphql" \
102
+ -hdr "X-Magento-Cache-Id: 12345"
103
+ rxresp
104
+ expect resp.http.X-Magento-Cache-Debug == "MISS"
105
+
106
+ txreq -method "GET" -url "/graphql" \
107
+ -hdr "X-Magento-Cache-Id: 12345"
108
+ rxresp
109
+ expect resp.http.X-Magento-Cache-Debug == "HIT"
110
+
111
+ txreq -method "GET" -url "/graphql" \
112
+ -hdr "X-Magento-Cache-Id: 12346"
113
+ rxresp
114
+ expect resp.http.X-Magento-Cache-Debug == "MISS"
115
+
116
+ txreq -method "GET" -url "/graphql" \
117
+ -hdr "X-Magento-Cache-Id: 12346"
118
+ rxresp
119
+ expect resp.http.X-Magento-Cache-Debug == "HIT"
120
+
121
+ txreq -method "GET" -url "/graphql" \
122
+ -hdr "X-Magento-Cache-Id: 12345" \
123
+ -hdr "Store: 1"
124
+ rxresp
125
+ expect resp.http.X-Magento-Cache-Debug == "MISS"
126
+
127
+ txreq -method "GET" -url "/graphql" \
128
+ -hdr "X-Magento-Cache-Id: 12345" \
129
+ -hdr "Store: 1"
130
+ rxresp
131
+ expect resp.http.X-Magento-Cache-Debug == "HIT"
132
+
133
+ txreq -method "GET" -url "/graphql" \
134
+ -hdr "X-Magento-Cache-Id: 12345" \
135
+ -hdr "Store: 1" \
136
+ -hdr "Content-Currency: 1"
137
+ rxresp
138
+ expect resp.http.X-Magento-Cache-Debug == "MISS"
139
+
140
+ txreq -method "GET" -url "/graphql" \
141
+ -hdr "X-Magento-Cache-Id: 12345" \
142
+ -hdr "Store: 1" \
143
+ -hdr "Content-Currency: 1"
144
+ rxresp
145
+ expect resp.http.X-Magento-Cache-Debug == "HIT"
146
+
147
+ txreq -method "GET" -url "/graphql" \
148
+ -hdr "Authorization: Bearer 12345"
149
+ rxresp
150
+ expect resp.http.X-Magento-Cache-Debug == "UNCACHEABLE"
151
+
152
+ txreq -method "GET" -url "/graphql" \
153
+ -hdr "Authorization: Bearer 12345" \
154
+ -hdr "X-Magento-Cache-Id: 12345"
155
+ rxresp
156
+ expect resp.http.X-Magento-Cache-Debug == "MISS"
157
+
158
+ txreq -method "GET" -url "/graphql" \
159
+ -hdr "Authorization: Bearer 12345" \
160
+ -hdr "X-Magento-Cache-Id: 12345"
161
+ rxresp
162
+ expect resp.http.X-Magento-Cache-Debug == "HIT"
163
+ } -run
0 commit comments