Add tests for rewrite behind the client's back with https
authorFabian Keil <fk@fabiankeil.de>
Sun, 10 Jan 2021 03:37:16 +0000 (04:37 +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-https/data/test1 [new file with mode: 0644]
tests/cts/rewrite-behind-client-back-https/data/test2 [new file with mode: 0644]
tests/cts/rewrite-behind-client-back-https/data/test3 [new file with mode: 0644]
tests/cts/rewrite-behind-client-back-https/data/test4 [new file with mode: 0644]
tests/cts/rewrite-behind-client-back-https/data/test5 [new file with mode: 0644]
tests/cts/rewrite-behind-client-back-https/privoxy.conf [new file with mode: 0644]
tests/cts/rewrite-behind-client-back-https/rewrites.action [new file with mode: 0644]
tests/cts/rewrite-behind-client-back-https/rewrites.filter [new file with mode: 0644]

diff --git a/tests/cts/rewrite-behind-client-back-https/data/test1 b/tests/cts/rewrite-behind-client-back-https/data/test1
new file mode 100644 (file)
index 0000000..53ee678
--- /dev/null
@@ -0,0 +1,48 @@
+<testcase>
+<info>
+<keywords>
+HTTPS
+HTTP GET
+</keywords>
+</info>
+
+<reply>
+<data>
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html
+Content-Length: 18
+
+Here's your data.
+</data>
+</reply>
+
+<proxy-reply>
+<data>
+HTTP/1.1 200 Connection established
+
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html
+Content-Length: 18
+
+Here's your data.
+</data>
+</proxy-reply>
+
+
+<client>
+<server>
+http
+</server>
+<name>
+Rewrite behind the client's back: Downgrade from https to http
+</name>
+<command>
+--insecure https://%HOSTIP/%TESTNUMBER-downgrade-to-http-%HOSTIP:%HTTPPORT
+</command>
+</client>
+
+<verify>
+</verify>
+</testcase>
diff --git a/tests/cts/rewrite-behind-client-back-https/data/test2 b/tests/cts/rewrite-behind-client-back-https/data/test2
new file mode 100644 (file)
index 0000000..a8f1094
--- /dev/null
@@ -0,0 +1,54 @@
+<testcase>
+<info>
+<keywords>
+HTTPS
+HTTP GET
+</keywords>
+</info>
+
+<reply>
+<data>
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html
+Content-Length: 18
+
+Here's your data.
+</data>
+</reply>
+
+<proxy-reply>
+<data>
+HTTP/1.1 200 Connection established
+
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html
+Content-Length: 18
+
+Here's your data.
+</data>
+</proxy-reply>
+
+<client>
+<server>
+https
+</server>
+<name>
+Rewrite path behind the client's back
+</name>
+<command>
+--insecure https://%HOSTIP:%HTTPSPORT/%TESTNUMBER-remove-this
+</command>
+</client>
+
+<verify>
+<protocol>
+GET /%TESTNUMBER HTTP/1.1\r
+Host: %HOSTIP:%HTTPSPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+\r
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/cts/rewrite-behind-client-back-https/data/test3 b/tests/cts/rewrite-behind-client-back-https/data/test3
new file mode 100644 (file)
index 0000000..6c49f64
--- /dev/null
@@ -0,0 +1,55 @@
+<testcase>
+<info>
+<keywords>
+HTTPS
+HTTP GET
+</keywords>
+</info>
+
+<reply>
+<data>
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html
+Content-Length: 18
+
+Here's your data.
+</data>
+</reply>
+
+<proxy-reply>
+<data>
+HTTP/1.1 200 Connection established
+
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html
+Content-Length: 18
+
+Here's your data.
+</data>
+</proxy-reply>
+
+
+<client>
+<server>
+https
+</server>
+<name>
+Rewrite host behind the client's back
+</name>
+<command>
+--insecure https://www.example.org/%TESTNUMBER-%HOSTIP:%HTTPSPORT
+</command>
+</client>
+
+<verify>
+<protocol>
+GET /%TESTNUMBER HTTP/1.1\r
+Host: www.example.org\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+\r
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/cts/rewrite-behind-client-back-https/data/test4 b/tests/cts/rewrite-behind-client-back-https/data/test4
new file mode 100644 (file)
index 0000000..2375271
--- /dev/null
@@ -0,0 +1,54 @@
+<testcase>
+<info>
+<keywords>
+HTTPS
+HTTP GET
+</keywords>
+</info>
+
+<reply>
+<data>
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html
+Content-Length: 18
+
+Here's your data.
+</data>
+</reply>
+
+<proxy-reply>
+<data>
+HTTP/1.1 200 Connection established
+
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html
+Content-Length: 18
+
+Here's your data.
+</data>
+</proxy-reply>
+
+<client>
+<server>
+https
+</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>
+--insecure https:///%HOSTIP:%HTTPSPORT/%TESTNUMBER
+</command>
+</client>
+
+<verify>
+<protocol>
+GET /%TESTNUMBER HTTP/1.1\r
+Host: %HOSTIP:%HTTPSPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+\r
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/cts/rewrite-behind-client-back-https/data/test5 b/tests/cts/rewrite-behind-client-back-https/data/test5
new file mode 100644 (file)
index 0000000..2e6bd11
--- /dev/null
@@ -0,0 +1,47 @@
+<testcase>
+<info>
+<keywords>
+HTTPS
+HTTP GET
+</keywords>
+</info>
+
+<reply>
+<data>
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html
+Content-Length: 18
+
+Here's your data.
+</data>
+</reply>
+
+<proxy-reply>
+<data>
+HTTP/1.1 200 Connection established
+
+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: unsupporte http version
+</name>
+<command>
+--insecure https://%HOSTIP/%TESTNUMBER
+</command>
+</client>
+
+<verify>
+</verify>
+</testcase>
diff --git a/tests/cts/rewrite-behind-client-back-https/privoxy.conf b/tests/cts/rewrite-behind-client-back-https/privoxy.conf
new file mode 100644 (file)
index 0000000..8fb261e
--- /dev/null
@@ -0,0 +1,26 @@
+listen-address 127.0.0.1:9119
+
+ca-directory          ../ca-directory
+ca-cert-file          privoxy-test-cacert.crt
+ca-key-file           privoxy-test-cakey.pem
+ca-password           blafasel
+# We don't check certificate anyway
+trusted-cas-file      privoxy-test-cacert.crt
+
+certificate-directory ../certs
+
+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-https/rewrites.action b/tests/cts/rewrite-behind-client-back-https/rewrites.action
new file mode 100644 (file)
index 0000000..2623552
--- /dev/null
@@ -0,0 +1,17 @@
+{+https-inspection +ignore-certificate-errors}
+/
+
+{+client-header-filter{https-to-http}}
+/1-downgrade-to-http
+
+{+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-https/rewrites.filter b/tests/cts/rewrite-behind-client-back-https/rewrites.filter
new file mode 100644 (file)
index 0000000..a644255
--- /dev/null
@@ -0,0 +1,16 @@
+CLIENT-HEADER-FILTER: https-to-http Downgrade protocol to http
+s@^(\w+) (/\d-downgrade-to-http)-(\d+\.\d+\.\d+\.\d+\:\d+)@$1 http://$3$2@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 https://$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@
+