--- /dev/null
+varnishtest "cache rules are forbidden in defaults sections"
+
+# A cache rule declared in a defaults section would create an implicit
+# cache-store filter on the defaults section itself. It would never be
+# resolved nor attached to the proxies inheriting the rule, leading to
+# crashes or silently broken caching. Such rules are rejected at check
+# time: haproxy must refuse the configuration.
+
+feature ignore_unknown_macro
+
+# A "cache-use" rule in a defaults section is rejected.
+haproxy h1 -conf-BAD {'cache-use' rules are not supported in a defaults section} {
+ defaults d
+ mode http
+ timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
+ timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
+ timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
+ http-request cache-use my_cache
+
+ frontend fe from d
+
+ cache my_cache
+ total-max-size 1
+}
+
+# A "cache-store" rule in a defaults section is rejected too.
+haproxy h2 -conf-BAD {'cache-store' rules are not supported in a defaults section} {
+ defaults d
+ mode http
+ timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
+ timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
+ timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
+ http-response cache-store my_cache
+
+ frontend fe from d
+
+ cache my_cache
+ total-max-size 1
+}
struct cache_flt_conf *cconf = NULL;
char *name = rule->arg.act.p[0];
+ if (proxy->cap & PR_CAP_DEF) {
+ memprintf(err, "'%s' rules are not supported in a defaults section",
+ rule->kw ? rule->kw->kw : "cache");
+ return 0;
+ }
+
/* check if a cache filter was already registered with this cache
* name, if that's the case, must use it. */
fconf = flt_find_conf(proxy, cache_store_flt_id, FLT_SIDE_RES, cache_store_find_flt, (char *)name);