Add test scenario client-tags
authorFabian Keil <fk@fabiankeil.de>
Sun, 28 Mar 2021 09:09:29 +0000 (11:09 +0200)
committerFabian Keil <fk@fabiankeil.de>
Wed, 20 Mar 2024 11:38:39 +0000 (12:38 +0100)
Sponsored by: Privoxy project funds collected at SPI

tests/cts/client-tags/client-tags.action [new file with mode: 0644]
tests/cts/client-tags/data/test1 [new file with mode: 0644]
tests/cts/client-tags/data/test2 [new file with mode: 0644]
tests/cts/client-tags/data/test3 [new file with mode: 0644]
tests/cts/client-tags/data/test4 [new file with mode: 0644]
tests/cts/client-tags/data/test5 [new file with mode: 0644]
tests/cts/client-tags/data/test6 [new file with mode: 0644]
tests/cts/client-tags/data/test7 [new file with mode: 0644]
tests/cts/client-tags/privoxy.conf [new file with mode: 0644]

diff --git a/tests/cts/client-tags/client-tags.action b/tests/cts/client-tags/client-tags.action
new file mode 100644 (file)
index 0000000..6fb6b3b
--- /dev/null
@@ -0,0 +1,8 @@
+{+block{Blocked based on the path}}
+/block-request/
+
+{-block}
+CLIENT-TAG:^overrule-blocks$
+
+{-filter}
+CLIENT-TAG:^overrule-filters$
diff --git a/tests/cts/client-tags/data/test1 b/tests/cts/client-tags/data/test1
new file mode 100644 (file)
index 0000000..1c6ea1a
--- /dev/null
@@ -0,0 +1,26 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+</keywords>
+</info>
+
+<client>
+<server>
+none
+</server>
+<name>
+Request to blocked URL with now client-tags active
+</name>
+<command>
+-s --write-out '%{stderr}%{response_code}\n' http://www.electrobsd.org/block-request/
+</command>
+</client>
+
+<verify>
+<stderr>
+403
+</stderr>
+</verify>
+</testcase>
diff --git a/tests/cts/client-tags/data/test2 b/tests/cts/client-tags/data/test2
new file mode 100644 (file)
index 0000000..59f8b12
--- /dev/null
@@ -0,0 +1,27 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+</keywords>
+</info>
+
+<client>
+<server>
+http
+</server>
+<name>
+Attempt to enable client-tag to disable block action for follow-up request without trusted Referer
+</name>
+<command>
+-s --write-out '%{stderr}%{response_code}\n' 'http://p.p/toggle-client-tag?tag=overrule-blocks&toggle-state=1&expires=1' --next -s --write-out '%{stderr}%{response_code}\n' http://%HOSTIP:%HTTPPORT/block-request/
+</command>
+</client>
+
+<verify>
+<stderr>
+403
+403
+</stderr>
+</verify>
+</testcase>
diff --git a/tests/cts/client-tags/data/test3 b/tests/cts/client-tags/data/test3
new file mode 100644 (file)
index 0000000..8b0d6ac
--- /dev/null
@@ -0,0 +1,39 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+</keywords>
+</info>
+
+<reply>
+<data>
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html
+X-Connection: swsclose
+
+Received your input.
+</data>
+</reply>
+
+<client>
+<server>
+http
+</server>
+<name>
+Enabling client-tag to disable block action for follow-up request with trusted Referer
+</name>
+# Limit the transfer rate for the second request so tag timed out by the time the next test is executed.
+<command option="no-include">
+-s --write-out '%{stderr}%{response_code}\n' --referer "http://p.p/client-tags" 'http://p.p/toggle-client-tag?tag=overrule-blocks&toggle-state=1&expires=1' --next -s --include --output log/curl%TESTNUMBER.out --write-out '%{stderr}%{response_code}\n' --limit-rate 10 http://%HOSTIP:%HTTPPORT/block-request/
+</command>
+</client>
+
+<verify>
+<stderr>
+302
+200
+</stderr>
+</verify>
+</testcase>
diff --git a/tests/cts/client-tags/data/test4 b/tests/cts/client-tags/data/test4
new file mode 100644 (file)
index 0000000..6a2240b
--- /dev/null
@@ -0,0 +1,40 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+</keywords>
+</info>
+
+<reply>
+<data>
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html
+X-Connection: swsclose
+
+Received your input.
+</data>
+</reply>
+
+<client>
+<server>
+http
+</server>
+<name>
+Enabling client-tag to disable block action for follow-up request with trusted Referer and disabling it again
+</name>
+<command option="no-include">
+-s --write-out '%{stderr}%{response_code}\n' --referer "http://p.p/client-tags" 'http://p.p/toggle-client-tag?tag=overrule-blocks&toggle-state=1&expires=1' --next -s --include --output log/curl%TESTNUMBER.out --write-out '%{stderr}%{response_code}\n' http://%HOSTIP:%HTTPPORT/block-request/ --next -s --write-out '%{stderr}%{response_code}\n' --referer "http://p.p/client-tags" 'http://p.p/toggle-client-tag?tag=overrule-blocks&toggle-state=0&expires=1' --next --write-out '%{stderr}%{response_code}\n' http://%HOSTIP:%HTTPPORT/block-request/
+</command>
+</client>
+
+<verify>
+<stderr>
+302
+200
+302
+403
+</stderr>
+</verify>
+</testcase>
diff --git a/tests/cts/client-tags/data/test5 b/tests/cts/client-tags/data/test5
new file mode 100644 (file)
index 0000000..4eddbc5
--- /dev/null
@@ -0,0 +1,39 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+</keywords>
+</info>
+
+<reply>
+<data>
+HTTP/1.1 200 OK
+Content-Length: 21
+Content-Type: text/html
+
+Received your input.
+</data>
+</reply>
+
+<client>
+<server>
+http
+</server>
+<name>
+Enabling client-tag to disable block action for follow-up request with trusted Referer and disabling it again reusing the connection (based on test 4)
+</name>
+<command option="no-include">
+-s --write-out '%{stderr}%{response_code}\n' --referer "http://p.p/client-tags" 'http://p.p/toggle-client-tag?tag=overrule-blocks&toggle-state=1&expires=1' --next -s --include --output log/curl%TESTNUMBER.out --write-out '%{stderr}%{response_code}\n' http://%HOSTIP:%HTTPPORT/block-request/ --next -s --write-out '%{stderr}%{response_code}\n' --referer "http://p.p/client-tags" 'http://p.p/toggle-client-tag?tag=overrule-blocks&toggle-state=0&expires=1' --next --write-out '%{stderr}%{response_code}\n' http://%HOSTIP:%HTTPPORT/block-request/
+</command>
+</client>
+
+<verify>
+<stderr>
+302
+200
+302
+403
+</stderr>
+</verify>
+</testcase>
diff --git a/tests/cts/client-tags/data/test6 b/tests/cts/client-tags/data/test6
new file mode 100644 (file)
index 0000000..c11365a
--- /dev/null
@@ -0,0 +1,39 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+</keywords>
+</info>
+
+<reply>
+<data>
+HTTP/1.1 200 OK
+Content-Length: 21
+Content-Type: text/html
+
+Received your input.
+</data>
+</reply>
+
+<client>
+<server>
+http
+</server>
+<name>
+Enabling client-tag to disable block action for follow-up request with Referer specified with trusted-cgi-referer and disabling the tag again reusing the connection (based on test 5)
+</name>
+<command option="no-include">
+-s --write-out '%{stderr}%{response_code}\n' --referer "http://www.electrobsd.org/" 'http://p.p/toggle-client-tag?tag=overrule-blocks&toggle-state=1&expires=1' --next -s --include --output log/curl%TESTNUMBER.out --write-out '%{stderr}%{response_code}\n' http://%HOSTIP:%HTTPPORT/block-request/ --next -s --write-out '%{stderr}%{response_code}\n' --referer "http://www.electrobsd.org/" 'http://p.p/toggle-client-tag?tag=overrule-blocks&toggle-state=0&expires=1' --next --write-out '%{stderr}%{response_code}\n' http://%HOSTIP:%HTTPPORT/block-request/
+</command>
+</client>
+
+<verify>
+<stderr>
+302
+200
+302
+403
+</stderr>
+</verify>
+</testcase>
diff --git a/tests/cts/client-tags/data/test7 b/tests/cts/client-tags/data/test7
new file mode 100644 (file)
index 0000000..905cab5
--- /dev/null
@@ -0,0 +1,38 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+</keywords>
+</info>
+
+<proxy-reply>
+<data>
+HTTP/1.1 302 Done dealing with toggle request
+Location: //config.privoxy.org/client-tags
+Access-Control-Allow-Origin: http://www.electrobsd.org/
+Access-Control-Allow-Methods: GET,POST
+Access-Control-Allow-Headers: X-Requested-With
+Access-Control-Max-Age: 86400
+Content-Length: 0
+X-Ignore-Header: Date
+Date: Sun, 28 Mar 2021 09:35:05 GMT
+
+</data>
+</proxy-reply>
+
+<client>
+<server>
+none
+</server>
+<name>
+Confirm that the cors-allowed-origin directives results in headers being are added to CGI responses.
+</name>
+<command>
+--head --referer http://www.electrobsd.org/ 'http://p.p/toggle-client-tag'
+</command>
+</client>
+
+<verify>
+</verify>
+</testcase>
diff --git a/tests/cts/client-tags/privoxy.conf b/tests/cts/client-tags/privoxy.conf
new file mode 100644 (file)
index 0000000..443b78a
--- /dev/null
@@ -0,0 +1,36 @@
+listen-address 127.0.0.1:9119
+
+debug     1 # Log the destination for each request Privoxy let through. See also debug 1024.
+debug     2 # show each connection status
+debug     4 # show tagging-related messages
+debug     8 # show header parsing
+debug    32 # debug force feature
+debug    64 # debug regular expression filters
+debug   128 # debug redirects
+debug   256 # debug GIF de-animation
+debug   512 # Common Log Format
+debug  1024 # Log the destination for requests Privoxy didn't let through, and the reason why.
+debug  4096 # Startup banner and warnings.
+debug  8192 # Non-fatal errors
+debug 65536 # log applying actions
+#debug    16 # log all data written to the network into the logfile
+#debug 32768 # log all data read from the network
+
+actionsfile client-tags.action
+filterfile ../../../default.filter
+
+socket-timeout 3
+
+templdir ../../../templates/
+
+client-specific-tag overrule-blocks Overrule block sections.
+client-specific-tag overrule-filters Overrule filter sections.
+
+# Try to let tags timeout between tests. This is racy but works for me.
+client-tag-lifetime 1
+
+trusted-cgi-referer http://www.electrobsd.org/
+cors-allowed-origin http://www.electrobsd.org/
+
+keep-alive-timeout 10
+default-server-timeout 10