From: Fabian Keil <fk@fabiankeil.de>
Date: Fri, 26 Mar 2021 06:06:07 +0000 (+0100)
Subject: Add test scenario client-body-filter
X-Git-Tag: v_4_0_0~92
X-Git-Url: http://www.privoxy.org/gitweb/%22https:/faq/@default-cgi@/static/git.html?a=commitdiff_plain;h=a7b3ab256bba9627cc7e995d7e779a09bcfea0b6;p=privoxy.git

Add test scenario client-body-filter

Sponsored by: Privoxy project funds collected at SPI
---

diff --git a/tests/cts/client-body-filter/client-body-filter.action b/tests/cts/client-body-filter/client-body-filter.action
new file mode 100644
index 00000000..40cf7820
--- /dev/null
+++ b/tests/cts/client-body-filter/client-body-filter.action
@@ -0,0 +1,8 @@
+{+client-body-filter{blafasel-to-bumfidel}}
+/
+
+{+client-body-filter{bumfidel-to-tralala}}
+/bumfidel-to-tralala
+
+{+client-body-filter{empty-body}}
+/.*/empty-body/
diff --git a/tests/cts/client-body-filter/client-body-filter.filter b/tests/cts/client-body-filter/client-body-filter.filter
new file mode 100644
index 00000000..ecc3798a
--- /dev/null
+++ b/tests/cts/client-body-filter/client-body-filter.filter
@@ -0,0 +1,8 @@
+CLIENT-BODY-FILTER: blafasel-to-bumfidel Changes "blafasel" to "bumfidel"
+s@blafasel@bumfidel@
+
+CLIENT-BODY-FILTER: bumfidel-to-tralala Changes "bumfidel" to "tralala"
+s@bumfidel@tralala@
+
+CLIENT-BODY-FILTER: empty-body Only applies to empty content bodies
+s@^$@empty-body detected that there was no data@
diff --git a/tests/cts/client-body-filter/data/test1 b/tests/cts/client-body-filter/data/test1
new file mode 100644
index 00000000..cfb7b268
--- /dev/null
+++ b/tests/cts/client-body-filter/data/test1
@@ -0,0 +1,49 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP POST
+client-body-filter
+</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>
+Replace whole request body with client-body-filter{blafasel-to-bumfidel}
+</name>
+<features>
+proxy
+</features>
+<command>
+-d blafasel http://%HOSTIP:%HTTPPORT/%TESTNUMBER
+</command>
+</client>
+
+<verify>
+<protocol nonewline="yes">
+POST /%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+User-Agent: curl/%VERSION
+Accept: */*
+Content-Length: 8
+Content-Type: application/x-www-form-urlencoded
+Connection: close
+
+bumfidel
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/cts/client-body-filter/data/test10 b/tests/cts/client-body-filter/data/test10
new file mode 100644
index 00000000..d09d568e
--- /dev/null
+++ b/tests/cts/client-body-filter/data/test10
@@ -0,0 +1,44 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP POST
+client-body-filter
+</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>
+Attempt to apply client-body-filter{blafasel-to-bumfidel} to client request that does not completely arrive in time. (XXX: Privoxy sends a "Connection failed" message instead of a timeout message which would be more appropriate)
+</name>
+<features>
+proxy
+</features>
+# Sending the first request to appease the test framework.
+# We mainly care about the second request where we overwrite the Content-Length
+# header with an incorrect value so curl sends less data than Privoxy expects.
+<command>
+-s http://%HOSTIP:%HTTPPORT/first-request/%TESTNUMBER --next -s --write-out '%{stderr}%{response_code}\n' --limit-rate 5000 -d "blafasel%repeat[100 x padding]%" -H "Content-Length: 10000" http://%HOSTIP:%HTTPPORT/second-request/%TESTNUMBER
+</command>
+</client>
+
+<verify>
+<stderr>
+400
+</stderr>
+</verify>
+</testcase>
diff --git a/tests/cts/client-body-filter/data/test11 b/tests/cts/client-body-filter/data/test11
new file mode 100644
index 00000000..8cc8b618
--- /dev/null
+++ b/tests/cts/client-body-filter/data/test11
@@ -0,0 +1,49 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP POST
+client-body-filter
+</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>
+Applying client-body-filter{blafasel-to-bumfidel} to large client request slowly while the server times out quickly (XXX: not properly implemented)
+</name>
+<features>
+proxy
+</features>
+<command>
+--limit-rate 1000 -d "blafasel%repeat[5000 x padding]%" http://%HOSTIP:%HTTPPORT/%TESTNUMBER
+</command>
+</client>
+
+<verify>
+<protocol nonewline="yes">
+POST /%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+User-Agent: curl/%VERSION
+Accept: */*
+Content-Length: 35008
+Content-Type: application/x-www-form-urlencoded
+Connection: close
+
+bumfidel%repeat[5000 x padding]%
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/cts/client-body-filter/data/test12 b/tests/cts/client-body-filter/data/test12
new file mode 100644
index 00000000..8db65fde
--- /dev/null
+++ b/tests/cts/client-body-filter/data/test12
@@ -0,0 +1,65 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP POST
+client-body-filter
+</keywords>
+</info>
+
+<reply>
+<data>
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html
+X-Connection: swsclose
+
+Received your first request.
+</data>
+<data1>
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html
+X-Connection: swsclose
+
+Received your second request.
+</data1>
+</reply>
+
+<client>
+<server>
+http
+</server>
+<name>
+Attempt to apply client-body-filter{blafasel-to-bumfidel} to client request that is too large to buffer.
+</name>
+<features>
+proxy
+</features>
+# Sending the first request to appease the test framework.
+# We mainly care about the second request which is too large for Privoxy to buffer it.
+<command>
+http://%HOSTIP:%HTTPPORT/first-request/%TESTNUMBER --next -d "blafasel%repeat[20000 x padding]%" http://%HOSTIP:%HTTPPORT/second-request/%TESTNUMBER
+</command>
+</client>
+
+<verify>
+<protocol nonewline="yes">
+GET /first-request/%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+User-Agent: curl/%VERSION
+Accept: */*
+Connection: close
+
+POST /second-request/%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+User-Agent: curl/%VERSION
+Accept: */*
+Content-Length: 140008
+Content-Type: application/x-www-form-urlencoded
+Connection: close
+
+blafasel%repeat[20000 x padding]%
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/cts/client-body-filter/data/test2 b/tests/cts/client-body-filter/data/test2
new file mode 100644
index 00000000..830424a6
--- /dev/null
+++ b/tests/cts/client-body-filter/data/test2
@@ -0,0 +1,49 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP POST
+client-body-filter
+</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>
+Modify parts of the client body with client-body-filter{blafasel-to-bumfidel}
+</name>
+<features>
+proxy
+</features>
+<command>
+-d "foo blafasel bar" http://%HOSTIP:%HTTPPORT/%TESTNUMBER
+</command>
+</client>
+
+<verify>
+<protocol nonewline="yes">
+POST /%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+User-Agent: curl/%VERSION
+Accept: */*
+Content-Length: 16
+Content-Type: application/x-www-form-urlencoded
+Connection: close
+
+foo bumfidel bar
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/cts/client-body-filter/data/test3 b/tests/cts/client-body-filter/data/test3
new file mode 100644
index 00000000..606cdc5f
--- /dev/null
+++ b/tests/cts/client-body-filter/data/test3
@@ -0,0 +1,49 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP POST
+client-body-filter
+</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>
+Apply client-body-filter{blafasel-to-bumfidel} to request that does not contain blafasel
+</name>
+<features>
+proxy
+</features>
+<command>
+-d "foo bar" http://%HOSTIP:%HTTPPORT/%TESTNUMBER
+</command>
+</client>
+
+<verify>
+<protocol nonewline="yes">
+POST /%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+User-Agent: curl/%VERSION
+Accept: */*
+Content-Length: 7
+Content-Type: application/x-www-form-urlencoded
+Connection: close
+
+foo bar
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/cts/client-body-filter/data/test4 b/tests/cts/client-body-filter/data/test4
new file mode 100644
index 00000000..47249c05
--- /dev/null
+++ b/tests/cts/client-body-filter/data/test4
@@ -0,0 +1,50 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP POST
+client-body-filter
+</keywords>
+</info>
+
+<reply>
+<data>
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html
+
+Received your input.
+
+Will keep the connection open despite the "Connection: Close" header.
+</data>
+</reply>
+
+<client>
+<server>
+http
+</server>
+<name>
+Using client-body-filter{blafasel-to-bumfidel} with server connection that times out after delivering the response
+</name>
+<features>
+proxy
+</features>
+<command>
+-d "blafasel" http://%HOSTIP:%HTTPPORT/%TESTNUMBER
+</command>
+</client>
+
+<verify>
+<protocol nonewline="yes">
+POST /%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+User-Agent: curl/%VERSION
+Accept: */*
+Content-Length: 8
+Content-Type: application/x-www-form-urlencoded
+Connection: close
+
+bumfidel
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/cts/client-body-filter/data/test5 b/tests/cts/client-body-filter/data/test5
new file mode 100644
index 00000000..3a750165
--- /dev/null
+++ b/tests/cts/client-body-filter/data/test5
@@ -0,0 +1,49 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP POST
+client-body-filter
+</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>
+Applying client-body-filter{blafasel-to-bumfidel} to client request that is too large to read at once
+</name>
+<features>
+proxy
+</features>
+<command>
+-d "blafasel%repeat[5000 x padding]%" http://%HOSTIP:%HTTPPORT/%TESTNUMBER
+</command>
+</client>
+
+<verify>
+<protocol nonewline="yes">
+POST /%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+User-Agent: curl/%VERSION
+Accept: */*
+Content-Length: 35008
+Content-Type: application/x-www-form-urlencoded
+Connection: close
+
+bumfidel%repeat[5000 x padding]%
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/cts/client-body-filter/data/test6 b/tests/cts/client-body-filter/data/test6
new file mode 100644
index 00000000..cae9dd19
--- /dev/null
+++ b/tests/cts/client-body-filter/data/test6
@@ -0,0 +1,49 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP POST
+client-body-filter
+</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>
+Applying client-body-filter{blafasel-to-bumfidel} to client request that is too large to read at once and arrives slowly
+</name>
+<features>
+proxy
+</features>
+<command>
+--limit-rate 4k -d "blafasel%repeat[5000 x padding]%" http://%HOSTIP:%HTTPPORT/%TESTNUMBER
+</command>
+</client>
+
+<verify>
+<protocol nonewline="yes">
+POST /%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+User-Agent: curl/%VERSION
+Accept: */*
+Content-Length: 35008
+Content-Type: application/x-www-form-urlencoded
+Connection: close
+
+bumfidel%repeat[5000 x padding]%
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/cts/client-body-filter/data/test7 b/tests/cts/client-body-filter/data/test7
new file mode 100644
index 00000000..7402be50
--- /dev/null
+++ b/tests/cts/client-body-filter/data/test7
@@ -0,0 +1,49 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP POST
+client-body-filter
+</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>
+Two filters applied to client request reusing the already filtered content
+</name>
+<features>
+proxy
+</features>
+<command>
+-d "blafasel" http://%HOSTIP:%HTTPPORT/bumfidel-to-tralala/%TESTNUMBER
+</command>
+</client>
+
+<verify>
+<protocol nonewline="yes">
+POST /bumfidel-to-tralala/%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+User-Agent: curl/%VERSION
+Accept: */*
+Content-Length: 7
+Content-Type: application/x-www-form-urlencoded
+Connection: close
+
+tralala
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/cts/client-body-filter/data/test8 b/tests/cts/client-body-filter/data/test8
new file mode 100644
index 00000000..76acb0f7
--- /dev/null
+++ b/tests/cts/client-body-filter/data/test8
@@ -0,0 +1,49 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP POST
+client-body-filter
+</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>
+Three filters applied to client request reusing the already filtered content. Last filter does not modify content.
+</name>
+<features>
+proxy
+</features>
+<command>
+-d "blafasel" http://%HOSTIP:%HTTPPORT/bumfidel-to-tralala/empty-body/%TESTNUMBER
+</command>
+</client>
+
+<verify>
+<protocol nonewline="yes">
+POST /bumfidel-to-tralala/empty-body/%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+User-Agent: curl/%VERSION
+Accept: */*
+Content-Length: 7
+Content-Type: application/x-www-form-urlencoded
+Connection: close
+
+tralala
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/cts/client-body-filter/data/test9 b/tests/cts/client-body-filter/data/test9
new file mode 100644
index 00000000..a8371025
--- /dev/null
+++ b/tests/cts/client-body-filter/data/test9
@@ -0,0 +1,64 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP POST
+client-body-filter
+# This test currently doesn't work. Privoxy shuffles the data
+# to the server and once that's done the connection times out.
+# Sending no Content-Length header is an error but truncating the
+# request still doesn't seem ideal. Probably Privoxy should reject
+# the request instead of forwarding it.
+skip
+</keywords>
+</info>
+
+<reply>
+<data>
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html
+
+Received your input.
+</data>
+</reply>
+
+<proxy-reply>
+<data>
+HTTP/1.1 200 Connection established
+
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html
+
+Received your input.
+</data>
+</proxy-reply>
+
+<client>
+<server>
+http
+</server>
+<name>
+Attempt to apply client-body-filter{blafasel-to-bumfidel} to client request without Content-Length header
+</name>
+<features>
+proxy
+</features>
+<command>
+--limit-rate 1000 -d "blafasel%repeat[5000 x padding]%" -H "Content-Length:" http://%HOSTIP:%HTTPPORT/%TESTNUMBER
+</command>
+</client>
+
+<verify>
+<protocol nonewline="yes">
+POST /%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+User-Agent: curl/%VERSION
+Accept: */*
+Content-Type: application/x-www-form-urlencoded
+
+bumfidel%repeat[5000 x padding]%
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/cts/client-body-filter/privoxy.conf b/tests/cts/client-body-filter/privoxy.conf
new file mode 100644
index 00000000..fcab848c
--- /dev/null
+++ b/tests/cts/client-body-filter/privoxy.conf
@@ -0,0 +1,24 @@
+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 client-body-filter.action
+filterfile client-body-filter.filter
+
+socket-timeout 3
+
+templdir ../../../templates/
+
+# Reduce buffer limit so tests can reach it sooner.
+buffer-limit 100