Add test scenario client-body-filter
authorFabian Keil <fk@fabiankeil.de>
Fri, 26 Mar 2021 06:06:07 +0000 (07:06 +0100)
committerFabian Keil <fk@fabiankeil.de>
Wed, 20 Mar 2024 11:38:39 +0000 (12:38 +0100)
Sponsored by: Privoxy project funds collected at SPI

15 files changed:
tests/cts/client-body-filter/client-body-filter.action [new file with mode: 0644]
tests/cts/client-body-filter/client-body-filter.filter [new file with mode: 0644]
tests/cts/client-body-filter/data/test1 [new file with mode: 0644]
tests/cts/client-body-filter/data/test10 [new file with mode: 0644]
tests/cts/client-body-filter/data/test11 [new file with mode: 0644]
tests/cts/client-body-filter/data/test12 [new file with mode: 0644]
tests/cts/client-body-filter/data/test2 [new file with mode: 0644]
tests/cts/client-body-filter/data/test3 [new file with mode: 0644]
tests/cts/client-body-filter/data/test4 [new file with mode: 0644]
tests/cts/client-body-filter/data/test5 [new file with mode: 0644]
tests/cts/client-body-filter/data/test6 [new file with mode: 0644]
tests/cts/client-body-filter/data/test7 [new file with mode: 0644]
tests/cts/client-body-filter/data/test8 [new file with mode: 0644]
tests/cts/client-body-filter/data/test9 [new file with mode: 0644]
tests/cts/client-body-filter/privoxy.conf [new file with mode: 0644]

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 (file)
index 0000000..40cf782
--- /dev/null
@@ -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 (file)
index 0000000..ecc3798
--- /dev/null
@@ -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 (file)
index 0000000..cfb7b26
--- /dev/null
@@ -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\r
+Host: %HOSTIP:%HTTPPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+Content-Length: 8\r
+Content-Type: application/x-www-form-urlencoded\r
+Connection: close\r
+\r
+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 (file)
index 0000000..d09d568
--- /dev/null
@@ -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 (file)
index 0000000..8cc8b61
--- /dev/null
@@ -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\r
+Host: %HOSTIP:%HTTPPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+Content-Length: 35008\r
+Content-Type: application/x-www-form-urlencoded\r
+Connection: close\r
+\r
+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 (file)
index 0000000..8db65fd
--- /dev/null
@@ -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\r
+Host: %HOSTIP:%HTTPPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+Connection: close\r
+\r
+POST /second-request/%TESTNUMBER HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+Content-Length: 140008\r
+Content-Type: application/x-www-form-urlencoded\r
+Connection: close\r
+\r
+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 (file)
index 0000000..830424a
--- /dev/null
@@ -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\r
+Host: %HOSTIP:%HTTPPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+Content-Length: 16\r
+Content-Type: application/x-www-form-urlencoded\r
+Connection: close\r
+\r
+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 (file)
index 0000000..606cdc5
--- /dev/null
@@ -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\r
+Host: %HOSTIP:%HTTPPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+Content-Length: 7\r
+Content-Type: application/x-www-form-urlencoded\r
+Connection: close\r
+\r
+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 (file)
index 0000000..47249c0
--- /dev/null
@@ -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\r
+Host: %HOSTIP:%HTTPPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+Content-Length: 8\r
+Content-Type: application/x-www-form-urlencoded\r
+Connection: close\r
+\r
+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 (file)
index 0000000..3a75016
--- /dev/null
@@ -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\r
+Host: %HOSTIP:%HTTPPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+Content-Length: 35008\r
+Content-Type: application/x-www-form-urlencoded\r
+Connection: close\r
+\r
+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 (file)
index 0000000..cae9dd1
--- /dev/null
@@ -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\r
+Host: %HOSTIP:%HTTPPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+Content-Length: 35008\r
+Content-Type: application/x-www-form-urlencoded\r
+Connection: close\r
+\r
+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 (file)
index 0000000..7402be5
--- /dev/null
@@ -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\r
+Host: %HOSTIP:%HTTPPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+Content-Length: 7\r
+Content-Type: application/x-www-form-urlencoded\r
+Connection: close\r
+\r
+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 (file)
index 0000000..76acb0f
--- /dev/null
@@ -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\r
+Host: %HOSTIP:%HTTPPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+Content-Length: 7\r
+Content-Type: application/x-www-form-urlencoded\r
+Connection: close\r
+\r
+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 (file)
index 0000000..a837102
--- /dev/null
@@ -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\r
+\r
+HTTP/1.1 200 OK\r
+Connection: close\r
+Content-Type: text/html\r
+\r
+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\r
+Host: %HOSTIP:%HTTPPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+Content-Type: application/x-www-form-urlencoded\r
+\r
+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 (file)
index 0000000..fcab848
--- /dev/null
@@ -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