Add tests for destination rewrite
authorFabian Keil <fk@fabiankeil.de>
Sat, 9 Jan 2021 18:54:09 +0000 (19:54 +0100)
committerFabian Keil <fk@fabiankeil.de>
Wed, 20 Mar 2024 11:38:38 +0000 (12:38 +0100)
Sponsored by: Privoxy project funds collected at SPI

tests/cts/rewrite-behind-client-back/data/test1 [new file with mode: 0644]
tests/cts/rewrite-behind-client-back/data/test2 [new file with mode: 0644]
tests/cts/rewrite-behind-client-back/data/test3 [new file with mode: 0644]
tests/cts/rewrite-behind-client-back/data/test4 [new file with mode: 0644]
tests/cts/rewrite-behind-client-back/data/test5 [new file with mode: 0644]
tests/cts/rewrite-behind-client-back/privoxy.conf [new file with mode: 0644]
tests/cts/rewrite-behind-client-back/rewrites.action [new file with mode: 0644]
tests/cts/rewrite-behind-client-back/rewrites.filter [new file with mode: 0644]

diff --git a/tests/cts/rewrite-behind-client-back/data/test1 b/tests/cts/rewrite-behind-client-back/data/test1
new file mode 100644 (file)
index 0000000..dd0175b
--- /dev/null
@@ -0,0 +1,45 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+</keywords>
+</info>
+
+<reply>
+<data>
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html
+Content-Length: 29
+
+Not actually used.
+</data>
+</reply>
+
+<proxy-reply>
+<data>
+HTTP/1.1 400 Malformed request after rewriting
+Content-Type: text/plain
+Connection: close
+
+Bad request. Messed up with header filters.
+</data>
+</proxy-reply>
+
+
+<client>
+<server>
+none
+</server>
+<name>
+Rewrite behind the client's back: invalid upgrade to https
+</name>
+<command>
+http://%HOSTIP/%TESTNUMBER-upgrade-to-https
+</command>
+</client>
+
+<verify>
+</verify>
+</testcase>
diff --git a/tests/cts/rewrite-behind-client-back/data/test2 b/tests/cts/rewrite-behind-client-back/data/test2
new file mode 100644 (file)
index 0000000..b145d73
--- /dev/null
@@ -0,0 +1,41 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+</keywords>
+</info>
+
+<reply>
+<data>
+HTTP/1.1 200 OK
+Date: Thu, 22 Jul 2010 11:22:33 GMT
+Content-Length: 9
+
+Blafasel
+</data>
+</reply>
+
+
+<client>
+<server>
+http
+</server>
+<name>
+Rewrite path behind the client's back
+</name>
+<command>
+http://%HOSTIP:%HTTPPORT/%TESTNUMBER-remove-this
+</command>
+</client>
+
+<verify>
+<protocol>
+GET /%TESTNUMBER HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+\r
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/cts/rewrite-behind-client-back/data/test3 b/tests/cts/rewrite-behind-client-back/data/test3
new file mode 100644 (file)
index 0000000..61e3557
--- /dev/null
@@ -0,0 +1,42 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+</keywords>
+</info>
+
+<reply>
+<data>
+HTTP/1.1 200 OK
+Date: Thu, 22 Jul 2010 11:22:33 GMT
+Content-Length: 9
+
+Blafasel
+</data>
+</reply>
+
+
+<client>
+<server>
+http
+</server>
+<name>
+Rewrite host behind the client's back
+</name>
+<command>
+http://www.example.org/%TESTNUMBER-%HOSTIP:%HTTPPORT
+</command>
+</client>
+
+<verify>
+<protocol>
+GET /%TESTNUMBER HTTP/1.1\r
+Host: www.example.org\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+Connection: close\r
+\r
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/cts/rewrite-behind-client-back/data/test4 b/tests/cts/rewrite-behind-client-back/data/test4
new file mode 100644 (file)
index 0000000..d7c10f8
--- /dev/null
@@ -0,0 +1,42 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+</keywords>
+</info>
+
+<reply>
+<data>
+HTTP/1.1 200 OK
+Date: Thu, 22 Jul 2010 11:22:33 GMT
+Content-Length: 9
+
+Blafasel
+</data>
+</reply>
+
+
+<client>
+<server>
+http
+</server>
+<name>
+Client header filter that doesn't match anything. According to Valgrind it triggers a "Conditional jump or move depends on uninitialised value(s)"
+</name>
+<command>
+http:///%HOSTIP:%HTTPPORT/%TESTNUMBER
+</command>
+</client>
+
+<verify>
+<protocol>
+GET /%TESTNUMBER HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+Connection: close\r
+\r
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/cts/rewrite-behind-client-back/data/test5 b/tests/cts/rewrite-behind-client-back/data/test5
new file mode 100644 (file)
index 0000000..82da79d
--- /dev/null
@@ -0,0 +1,44 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+</keywords>
+</info>
+
+<reply>
+<data>
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html
+Content-Length: 29
+
+Not actually used.
+</data>
+</reply>
+
+<proxy-reply>
+<data>
+HTTP/1.1 400 Malformed request after rewriting
+Content-Type: text/plain
+Connection: close
+
+Bad request. Messed up with header filters.
+</data>
+</proxy-reply>
+
+<client>
+<server>
+none
+</server>
+<name>
+Rewrite behind the client's back: unsupported http version
+</name>
+<command>
+http://%HOSTIP/%TESTNUMBER
+</command>
+</client>
+
+<verify>
+</verify>
+</testcase>
diff --git a/tests/cts/rewrite-behind-client-back/privoxy.conf b/tests/cts/rewrite-behind-client-back/privoxy.conf
new file mode 100644 (file)
index 0000000..0630430
--- /dev/null
@@ -0,0 +1,17 @@
+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
+
+actionsfile rewrites.action
+filterfile rewrites.filter
diff --git a/tests/cts/rewrite-behind-client-back/rewrites.action b/tests/cts/rewrite-behind-client-back/rewrites.action
new file mode 100644 (file)
index 0000000..78d3b5f
--- /dev/null
@@ -0,0 +1,14 @@
+{+client-header-filter{http-to-https}}
+/1-upgrade-to-https
+
+{+client-header-filter{truncate-path}}
+/2-remove-this
+
+{+client-header-filter{rewrite-host}}
+/3
+
+{+client-header-filter{non-matching-rewriter}}
+/4
+
+{+client-header-filter{invalid-http-version}}
+/5
diff --git a/tests/cts/rewrite-behind-client-back/rewrites.filter b/tests/cts/rewrite-behind-client-back/rewrites.filter
new file mode 100644 (file)
index 0000000..30f59de
--- /dev/null
@@ -0,0 +1,16 @@
+CLIENT-HEADER-FILTER: http-to-https Upgrade http requests to https behind the client's back. Not actually supported.
+s@^(\w+)\s+http://@$1 https://@i
+
+CLIENT-HEADER-FILTER: truncate-path Removes '-remove-this' from the path
+s@(/\d)-remove-this (HTTP/1.1)@$1 $2@i
+
+CLIENT-HEADER-FILTER: rewrite-host Replaces the host with the one specified in the path
+s@GET .*/(\d)-(\d+\.\d+\.\d+\.\d+\:\d+) (HTTP/1.1)@GET http://$2/$1 $3@i
+
+# Results in Conditional jump or move depends on uninitialised value(s)?
+CLIENT-HEADER-FILTER: non-matching-rewriter Does not actually match
+s@/-@@
+
+CLIENT-HEADER-FILTER: invalid-http-version Rewrites the request line with an invalid HTTP version
+s@HTTP/1.1@HTTP/9000@
+