From 0e29d131c944ebf98ae298b59c357531840cf8e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A9nes=20Magyari?= Date: Fri, 1 Mar 2024 23:21:50 +0100 Subject: [PATCH 1/2] fix(plugins): Caddy config cache_keys json parse error --- configurationtypes/types.go | 2 -- plugins/caddy/httpcache_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/configurationtypes/types.go b/configurationtypes/types.go index 4c0c7d02f..8093faebf 100644 --- a/configurationtypes/types.go +++ b/configurationtypes/types.go @@ -20,8 +20,6 @@ func (c *CacheKeys) parseJSON(rootDecoder *json.Decoder) { var token json.Token var err error - _, _ = rootDecoder.Token() - _, _ = rootDecoder.Token() _, _ = rootDecoder.Token() for err == nil { diff --git a/plugins/caddy/httpcache_test.go b/plugins/caddy/httpcache_test.go index b9f46fc43..9399abf68 100644 --- a/plugins/caddy/httpcache_test.go +++ b/plugins/caddy/httpcache_test.go @@ -114,6 +114,39 @@ func TestQueryString(t *testing.T) { } } +func TestCacheKeys(t *testing.T) { + tester := caddytest.NewTester(t) + tester.InitServer(` + { + admin localhost:2999 + order cache before rewrite + http_port 9080 + https_port 9443 + cache + } + localhost:9080 { + route /query-string { + cache { + cache_keys { + query= { + disable_query + } + } + } + respond "Hello, query string!" + } + }`, "caddyfile") + + resp1, _ := tester.AssertGetResponse(`http://localhost:9080/query-string?query=string`, 200, "Hello, query string!") + if resp1.Header.Get("Cache-Status") != "Souin; fwd=uri-miss; stored; key=GET-http-localhost:9080-/query-string" { + t.Errorf("unexpected Cache-Status header %v", resp1.Header) + } + resp2, _ := tester.AssertGetResponse(`http://localhost:9080/query-string?foo=bar`, 200, "Hello, query string!") + if resp2.Header.Get("Cache-Status") != "Souin; fwd=uri-miss; stored; key=GET-http-localhost:9080-/query-string?foo=bar" { + t.Errorf("unexpected Cache-Status header %v", resp2.Header) + } +} + func TestMaxAge(t *testing.T) { tester := caddytest.NewTester(t) tester.InitServer(` From 2c447f973e9b75eb7bc414bf7886efbb28fdaef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A9nes=20Magyari?= Date: Sat, 2 Mar 2024 01:33:47 +0100 Subject: [PATCH 2/2] fix(plugins): Caddy config cache_keys test fix --- plugins/caddy/httpcache_test.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/caddy/httpcache_test.go b/plugins/caddy/httpcache_test.go index 9399abf68..8c3b8e7df 100644 --- a/plugins/caddy/httpcache_test.go +++ b/plugins/caddy/httpcache_test.go @@ -125,24 +125,28 @@ func TestCacheKeys(t *testing.T) { cache } localhost:9080 { - route /query-string { + route /cache-keys { cache { cache_keys { query= { disable_query } + query2= { + disable_body + disable_host + } } } respond "Hello, query string!" } }`, "caddyfile") - resp1, _ := tester.AssertGetResponse(`http://localhost:9080/query-string?query=string`, 200, "Hello, query string!") - if resp1.Header.Get("Cache-Status") != "Souin; fwd=uri-miss; stored; key=GET-http-localhost:9080-/query-string" { + resp1, _ := tester.AssertGetResponse(`http://localhost:9080/cache-keys?query=string`, 200, "Hello, query string!") + if resp1.Header.Get("Cache-Status") != "Souin; fwd=uri-miss; stored; key=GET-http-localhost:9080-/cache-keys" { t.Errorf("unexpected Cache-Status header %v", resp1.Header) } - resp2, _ := tester.AssertGetResponse(`http://localhost:9080/query-string?foo=bar`, 200, "Hello, query string!") - if resp2.Header.Get("Cache-Status") != "Souin; fwd=uri-miss; stored; key=GET-http-localhost:9080-/query-string?foo=bar" { + resp2, _ := tester.AssertGetResponse(`http://localhost:9080/cache-keys?foo=bar`, 200, "Hello, query string!") + if resp2.Header.Get("Cache-Status") != "Souin; fwd=uri-miss; stored; key=GET-http-localhost:9080-/cache-keys?foo=bar" { t.Errorf("unexpected Cache-Status header %v", resp2.Header) } }