Ema has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/278948

Change subject: VTC tests compatible with Varnish 3 and 4
......................................................................

VTC tests compatible with Varnish 3 and 4

All VTC tests introduced in https://gerrit.wikimedia.org/r/#/c/269466/
have been ported to a syntax compatible with both Varnish 3 and 4
wherever possible, allowing to run the same testsuite against the
current v3 VCL as well as the v4 port.

This patch also changes the way backends are added to directors in the
test version of wikimedia-common.inc.vcl to allow using the same backend
name across all VTC files.

Bug: T128188
Change-Id: I9208a5b027194dd58278174e5a37dd4cbd32866b
---
D modules/varnish/files/tests/maps/01-backend-basic-caching.vtc
A modules/varnish/files/tests/maps/01-basic-caching.vtc
D modules/varnish/files/tests/maps/01-frontend-basic-caching.vtc
A modules/varnish/files/tests/maps/02-test-forbidden-methods.vtc
A modules/varnish/files/tests/maps/03-test-beacon-endpoints.vtc
A modules/varnish/files/tests/maps/04-honor-cache-control.vtc
A modules/varnish/files/tests/maps/05-purging.vtc
A modules/varnish/files/tests/maps/06-do-gzip.vtc
A modules/varnish/files/tests/maps/07-frontend-tls-redirect.vtc
A modules/varnish/files/tests/maps/08-keep-alive-on-purge.vtc
A modules/varnish/files/tests/maps/09-custom-error-page-unreachable-backend.vtc
A modules/varnish/files/tests/maps/10-WMF-Last-Access.vtc
A modules/varnish/files/tests/maps/11-custom-synth-errorpage.vtc
M modules/varnish/templates/vcl/wikimedia-common.inc.vcl.erb
14 files changed, 373 insertions(+), 52 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/48/278948/1

diff --git a/modules/varnish/files/tests/maps/01-backend-basic-caching.vtc 
b/modules/varnish/files/tests/maps/01-backend-basic-caching.vtc
deleted file mode 100644
index 4e12226..0000000
--- a/modules/varnish/files/tests/maps/01-backend-basic-caching.vtc
+++ /dev/null
@@ -1,26 +0,0 @@
-varnishtest "Maps backend basic caching"
-
-server s1 {
-    rxreq
-    txresp
-} -start
-
-varnish v1 -arg "-p vcc_err_unref=false" -vcl+backend {
-    backend be_kartotherian {
-        .host = "${s1_addr}"; .port = "${s1_port}";
-    }
-
-    include "/usr/share/varnish/tests/wikimedia_maps-backend.vcl";
-} -start
-
-client c1 {
-    txreq -url "/?foo=bar"
-    rxresp
-    expect resp.status == 200
-
-    delay 1
-
-    txreq -url "/?foo=bar"
-    rxresp
-    expect resp.http.age == 1
-} -run
diff --git a/modules/varnish/files/tests/maps/01-basic-caching.vtc 
b/modules/varnish/files/tests/maps/01-basic-caching.vtc
new file mode 100644
index 0000000..f5d0c91
--- /dev/null
+++ b/modules/varnish/files/tests/maps/01-basic-caching.vtc
@@ -0,0 +1,36 @@
+varnishtest "Basic caching behavior"
+
+server s1 {
+    rxreq
+    txresp
+} -start
+
+varnish v1 -arg "-p vcc_err_unref=false" -vcl+backend {
+    backend vtc_backend {
+        .host = "${s1_addr}"; .port = "${s1_port}";
+    }
+
+    include "/usr/share/varnish/tests/wikimedia_maps-backend.vcl";
+} -start
+
+client c1 {
+    txreq
+    rxresp
+    expect resp.status == 200
+}
+
+varnish v1 -expect cache_miss == 0
+varnish v1 -expect cache_hit == 0
+varnish v1 -expect n_object == 0
+
+client c1 -run
+
+varnish v1 -expect cache_miss == 1
+varnish v1 -expect cache_hit == 0
+varnish v1 -expect n_object == 1
+
+client c1 -run
+
+varnish v1 -expect cache_miss == 1
+varnish v1 -expect cache_hit == 1
+varnish v1 -expect n_object == 1
diff --git a/modules/varnish/files/tests/maps/01-frontend-basic-caching.vtc 
b/modules/varnish/files/tests/maps/01-frontend-basic-caching.vtc
deleted file mode 100644
index 8ba4a77..0000000
--- a/modules/varnish/files/tests/maps/01-frontend-basic-caching.vtc
+++ /dev/null
@@ -1,26 +0,0 @@
-varnishtest "Maps frontend basic caching"
-
-server s1 {
-    rxreq
-    txresp
-} -start
-
-varnish v1 -arg "-p vcc_err_unref=false" -vcl+backend {
-    backend ipv4_127_0_0_2  {
-        .host = "${s1_addr}"; .port = "${s1_port}";
-    }
-
-    include "/usr/share/varnish/tests/wikimedia_maps-frontend.vcl";
-} -start
-
-client c1 {
-    txreq -url "/?foo=bar"
-    rxresp
-    expect resp.status == 200
-
-    delay 1
-
-    txreq -url "/?foo=bar"
-    rxresp
-    expect resp.http.age == 1
-} -run
diff --git a/modules/varnish/files/tests/maps/02-test-forbidden-methods.vtc 
b/modules/varnish/files/tests/maps/02-test-forbidden-methods.vtc
new file mode 100644
index 0000000..639d907
--- /dev/null
+++ b/modules/varnish/files/tests/maps/02-test-forbidden-methods.vtc
@@ -0,0 +1,60 @@
+varnishtest "Maps backend forbidden methods"
+
+server s1 {
+    rxreq
+    txresp
+} -start
+
+varnish v1 -arg "-p vcc_err_unref=false" -vcl+backend {
+    backend vtc_backend {
+        .host = "${s1_addr}"; .port = "${s1_port}";
+    }
+
+    include "/usr/share/varnish/tests/wikimedia_maps-backend.vcl";
+} -start
+
+# Allowed methods: (GET|HEAD|POST|PURGE)
+
+client c1 {
+    txreq -req GET
+    rxresp
+    expect resp.status == 200
+} -run
+
+client c2 {
+    txreq -req HEAD
+    rxresp
+    expect resp.status == 200
+} -run
+
+client c3 {
+    txreq -req POST
+    rxresp
+    expect resp.status == 200
+} -run
+
+client c4 {
+    txreq -req PURGE
+    rxresp
+    expect resp.status == 204
+} -run
+
+# Forbidden methods: (OPTIONS|PUT|DELETE)
+
+client c5 {
+    txreq -req OPTIONS
+    rxresp
+    expect resp.status == 405
+} -run
+
+client c6 {
+    txreq -req PUT
+    rxresp
+    expect resp.status == 405
+} -run
+
+client c7 {
+    txreq -req DELETE
+    rxresp
+    expect resp.status == 405
+} -run
diff --git a/modules/varnish/files/tests/maps/03-test-beacon-endpoints.vtc 
b/modules/varnish/files/tests/maps/03-test-beacon-endpoints.vtc
new file mode 100644
index 0000000..31098fd
--- /dev/null
+++ b/modules/varnish/files/tests/maps/03-test-beacon-endpoints.vtc
@@ -0,0 +1,21 @@
+varnishtest "WMF Frontend beacon endpoints"
+
+server s1 {
+    rxreq
+    txresp
+} -start
+
+varnish v1 -arg "-p vcc_err_unref=false" -vcl+backend {
+    backend vtc_backend {
+        .host = "${s1_addr}"; .port = "${s1_port}";
+    }
+
+    include "/usr/share/varnish/tests/wikimedia_maps-frontend.vcl";
+} -start
+
+client c1 {
+    # Logging beacon endpoints
+    txreq -url "/beacon/something"
+    rxresp
+    expect resp.status == 204
+} -run
diff --git a/modules/varnish/files/tests/maps/04-honor-cache-control.vtc 
b/modules/varnish/files/tests/maps/04-honor-cache-control.vtc
new file mode 100644
index 0000000..32fc409
--- /dev/null
+++ b/modules/varnish/files/tests/maps/04-honor-cache-control.vtc
@@ -0,0 +1,39 @@
+varnishtest "Do not cache private objects"
+
+server s1 {
+    rxreq
+    txresp -hdr "Cache-Control: private"
+
+    rxreq
+    txresp -hdr "Cache-Control: private"
+} -start
+
+varnish v1 -arg "-p vcc_err_unref=false" -vcl+backend {
+    backend vtc_backend {
+        .host = "${s1_addr}"; .port = "${s1_port}";
+    }
+
+    include "/usr/share/varnish/tests/wikimedia_maps-backend.vcl";
+} -start
+
+client c1 {
+    txreq -url "/?foo=private"
+    rxresp
+    expect resp.status == 200
+}
+
+varnish v1 -expect cache_miss == 0
+varnish v1 -expect cache_hit == 0
+varnish v1 -expect n_object == 0
+
+client c1 -run
+
+varnish v1 -expect cache_miss == 1
+varnish v1 -expect cache_hit == 0
+varnish v1 -expect n_object == 1
+
+client c1 -run
+
+varnish v1 -expect cache_miss == 1
+varnish v1 -expect cache_hit == 0
+varnish v1 -expect n_object == 1
diff --git a/modules/varnish/files/tests/maps/05-purging.vtc 
b/modules/varnish/files/tests/maps/05-purging.vtc
new file mode 100644
index 0000000..00ca3c3
--- /dev/null
+++ b/modules/varnish/files/tests/maps/05-purging.vtc
@@ -0,0 +1,52 @@
+varnishtest "Purging items"
+
+server s1 {
+    rxreq
+    txresp
+
+    rxreq
+    txresp
+} -start
+
+varnish v1 -arg "-p vcc_err_unref=false" -vcl+backend {
+    backend vtc_backend {
+        .host = "${s1_addr}"; .port = "${s1_port}";
+    }
+
+    include "/usr/share/varnish/tests/wikimedia_maps-backend.vcl";
+} -start
+
+client c1 {
+    txreq -url "/?foo=bar"
+    rxresp
+    expect resp.status == 200
+}
+
+client c2 {
+    txreq -req PURGE -url "/?foo=bar"
+    rxresp
+    expect resp.status == 204
+}
+
+varnish v1 -expect cache_miss == 0
+varnish v1 -expect cache_hit == 0
+
+client c1 -run
+
+varnish v1 -expect cache_miss == 1
+varnish v1 -expect cache_hit == 0
+
+client c1 -run
+
+varnish v1 -expect cache_miss == 1
+varnish v1 -expect cache_hit == 1
+
+client c2 -run
+
+varnish v1 -expect cache_miss == 1
+varnish v1 -expect cache_hit == 1
+
+client c1 -run
+
+varnish v1 -expect cache_miss == 2
+varnish v1 -expect cache_hit == 1
diff --git a/modules/varnish/files/tests/maps/06-do-gzip.vtc 
b/modules/varnish/files/tests/maps/06-do-gzip.vtc
new file mode 100644
index 0000000..ee5e916
--- /dev/null
+++ b/modules/varnish/files/tests/maps/06-do-gzip.vtc
@@ -0,0 +1,32 @@
+varnishtest "Compress compressible things if the backend didn't already"
+
+server s1 {
+    # Responses without Content-Type do NOT get compressed
+    rxreq
+    txresp -body { Hello world }
+
+    # Responses with Content-Type: text/plain (among others) *do* get 
compressed
+    rxreq
+    txresp -hdr "Content-Type: text/plain" -body { Hello world }
+} -start
+
+varnish v1 -arg "-p vcc_err_unref=false" -vcl+backend {
+    backend vtc_backend {
+        .host = "${s1_addr}"; .port = "${s1_port}";
+    }
+
+    include "/usr/share/varnish/tests/wikimedia_maps-backend.vcl";
+} -start
+
+client c1 {
+    txreq -url "/banana"
+    rxresp
+    expect resp.status == 200
+    expect resp.http.Transfer-Encoding != "chunked"
+
+    # Different URL to avoid a cache hit
+    txreq -url "/potato"
+    rxresp
+    expect resp.status == 200
+    expect resp.http.Transfer-Encoding == "chunked"
+} -run
diff --git a/modules/varnish/files/tests/maps/07-frontend-tls-redirect.vtc 
b/modules/varnish/files/tests/maps/07-frontend-tls-redirect.vtc
new file mode 100644
index 0000000..612b021
--- /dev/null
+++ b/modules/varnish/files/tests/maps/07-frontend-tls-redirect.vtc
@@ -0,0 +1,36 @@
+varnishtest "Maps frontend TLS redirect"
+
+server s1 {
+       rxreq
+       txresp
+} -start
+
+varnish v1 -arg "-p vcc_err_unref=false" -vcl+backend {
+       backend vtc_backend {
+               .host = "${s1_addr}"; .port = "${s1_port}";
+       }
+
+       include "/usr/share/varnish/tests/wikimedia_maps-frontend.vcl";
+} -start
+
+client c1 {
+       # Using https according to X-Forwarded-Proto
+       txreq -url "/?foo=bar" -hdr "Host: en.wikipedia.org" -hdr 
"X-Forwarded-Proto: https"
+       rxresp
+       expect resp.status == 200
+} -run
+
+client c2 {
+       # No X-Forwarded-Proto
+       txreq -url "/?foo=bar" -hdr "Host: en.wikipedia.org"
+       rxresp
+       expect resp.status == 301
+       expect resp.http.location == "https://en.wikipedia.org/?foo=bar";
+} -run
+
+client c3 {
+       # Insecure POST
+       txreq -req POST -url "/?foo=bar" -hdr "Host: en.wikipedia.org"
+       rxresp
+       expect resp.status == 403
+} -run
diff --git a/modules/varnish/files/tests/maps/08-keep-alive-on-purge.vtc 
b/modules/varnish/files/tests/maps/08-keep-alive-on-purge.vtc
new file mode 100644
index 0000000..cb36655
--- /dev/null
+++ b/modules/varnish/files/tests/maps/08-keep-alive-on-purge.vtc
@@ -0,0 +1,21 @@
+varnishtest "Frontend keep-alive on PURGE"
+
+server s1 {
+       rxreq
+       txresp
+} -start
+
+varnish v1 -arg "-p vcc_err_unref=false" -vcl+backend {
+       backend vtc_backend {
+               .host = "${s1_addr}"; .port = "${s1_port}";
+       }
+
+       include "/usr/share/varnish/tests/wikimedia_maps-frontend.vcl";
+} -start
+
+client c1 {
+       txreq -req PURGE
+       rxresp
+       expect resp.status == 204
+       expect resp.http.Connection == "keep-alive"
+} -run
diff --git 
a/modules/varnish/files/tests/maps/09-custom-error-page-unreachable-backend.vtc 
b/modules/varnish/files/tests/maps/09-custom-error-page-unreachable-backend.vtc
new file mode 100644
index 0000000..c08abbf
--- /dev/null
+++ 
b/modules/varnish/files/tests/maps/09-custom-error-page-unreachable-backend.vtc
@@ -0,0 +1,21 @@
+varnishtest "Custom error page on unreachable backend"
+
+varnish v1 -arg "-p vcc_err_unref=false" -vcl+backend {
+       backend vtc_backend {
+               .host = "${bad_ip}"; .port = "31337";
+       }
+
+       include "/usr/share/varnish/tests/wikimedia_maps-frontend.vcl";
+} -start
+
+client c1 {
+       txreq
+       rxresp
+       expect resp.status == 503
+
+       # The regex matching operator has been added in varnish 4
+#      expect resp.body ~ "<title>Wikimedia Error</title>"
+#      expect resp.body ~ "Request from 127.0.0.1 via"
+#      expect resp.body ~ ", Varnish XID [0-9]"
+#      expect resp.body ~ "Error: 503, Backend fetch failed at [A-Z]"
+} -run
diff --git a/modules/varnish/files/tests/maps/10-WMF-Last-Access.vtc 
b/modules/varnish/files/tests/maps/10-WMF-Last-Access.vtc
new file mode 100644
index 0000000..61d56ea
--- /dev/null
+++ b/modules/varnish/files/tests/maps/10-WMF-Last-Access.vtc
@@ -0,0 +1,23 @@
+varnishtest "WMF-Last-Access"
+
+server s1 {
+    rxreq
+    txresp
+} -start
+
+varnish v1 -arg "-p vcc_err_unref=false" -vcl+backend {
+    backend vtc_backend {
+        .host = "${s1_addr}"; .port = "${s1_port}";
+    }
+
+    include "/usr/share/varnish/tests/wikimedia_maps-frontend.vcl";
+} -start
+
+client c1 {
+    txreq
+    rxresp
+    expect resp.status == 200
+
+    # The regex matching operator has been added in varnish 4
+    #expect resp.http.Set-Cookie ~ 
"^WMF-Last-Access=[0-9]{2}-[A-Za-z]{3}-[0-9]{4};Path=/;HttpOnly;Expires=[A-Z][a-z]{2},
 [0-9]{2} [A-Z][a-z]{2} [0-9]{4} (12|00):00:00"
+} -run
diff --git a/modules/varnish/files/tests/maps/11-custom-synth-errorpage.vtc 
b/modules/varnish/files/tests/maps/11-custom-synth-errorpage.vtc
new file mode 100644
index 0000000..6b4c318
--- /dev/null
+++ b/modules/varnish/files/tests/maps/11-custom-synth-errorpage.vtc
@@ -0,0 +1,26 @@
+varnishtest "Custom synth errorpage"
+
+server s1 {
+    rxreq
+    txresp
+} -start
+
+varnish v1 -arg "-p vcc_err_unref=false" -vcl+backend {
+       backend vtc_backend {
+               .host = "${s1_addr}"; .port = "${s1_port}";
+       }
+
+       include "/usr/share/varnish/tests/wikimedia_maps-frontend.vcl";
+} -start
+
+client c1 {
+       txreq -req PUT
+       rxresp
+       expect resp.status == 405
+
+       # The regex matching operator has been added in varnish 4
+       #expect resp.body ~ "<title>Wikimedia Error</title>"
+       #expect resp.body ~ "Request from 127.0.0.1 via"
+       #expect resp.body ~ ", Varnish XID [0-9]"
+       #expect resp.body ~ "Error: 405, HTTP method not allowed. at [A-Z]"
+} -run
diff --git a/modules/varnish/templates/vcl/wikimedia-common.inc.vcl.erb 
b/modules/varnish/templates/vcl/wikimedia-common.inc.vcl.erb
index f7dbfed..4f7fbc0 100644
--- a/modules/varnish/templates/vcl/wikimedia-common.inc.vcl.erb
+++ b/modules/varnish/templates/vcl/wikimedia-common.inc.vcl.erb
@@ -150,6 +150,12 @@
 <%
        backends.each do |backend|
                name = /^[0-9\.]+$/.match(backend) ? "ipv4_" + 
backend.gsub(".", "_") : "be_" + backend.split(".")[0].gsub("-", "_")
+
+               # Override backend name for test VCL files. This way we can use
+               # "vtc_backend" as the backend name in our VTC tests.
+               if @varnish_testing
+                       name = "vtc_backend";
+               end
 -%>
        {
                .backend = <%= name %>;

-- 
To view, visit https://gerrit.wikimedia.org/r/278948
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9208a5b027194dd58278174e5a37dd4cbd32866b
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Ema <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to