From a7b3ab256bba9627cc7e995d7e779a09bcfea0b6 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Fri, 26 Mar 2021 07:06:07 +0100 Subject: [PATCH] Add test scenario client-body-filter Sponsored by: Privoxy project funds collected at SPI --- .../client-body-filter.action | 8 +++ .../client-body-filter.filter | 8 +++ tests/cts/client-body-filter/data/test1 | 49 ++++++++++++++ tests/cts/client-body-filter/data/test10 | 44 +++++++++++++ tests/cts/client-body-filter/data/test11 | 49 ++++++++++++++ tests/cts/client-body-filter/data/test12 | 65 +++++++++++++++++++ tests/cts/client-body-filter/data/test2 | 49 ++++++++++++++ tests/cts/client-body-filter/data/test3 | 49 ++++++++++++++ tests/cts/client-body-filter/data/test4 | 50 ++++++++++++++ tests/cts/client-body-filter/data/test5 | 49 ++++++++++++++ tests/cts/client-body-filter/data/test6 | 49 ++++++++++++++ tests/cts/client-body-filter/data/test7 | 49 ++++++++++++++ tests/cts/client-body-filter/data/test8 | 49 ++++++++++++++ tests/cts/client-body-filter/data/test9 | 64 ++++++++++++++++++ tests/cts/client-body-filter/privoxy.conf | 24 +++++++ 15 files changed, 655 insertions(+) create mode 100644 tests/cts/client-body-filter/client-body-filter.action create mode 100644 tests/cts/client-body-filter/client-body-filter.filter create mode 100644 tests/cts/client-body-filter/data/test1 create mode 100644 tests/cts/client-body-filter/data/test10 create mode 100644 tests/cts/client-body-filter/data/test11 create mode 100644 tests/cts/client-body-filter/data/test12 create mode 100644 tests/cts/client-body-filter/data/test2 create mode 100644 tests/cts/client-body-filter/data/test3 create mode 100644 tests/cts/client-body-filter/data/test4 create mode 100644 tests/cts/client-body-filter/data/test5 create mode 100644 tests/cts/client-body-filter/data/test6 create mode 100644 tests/cts/client-body-filter/data/test7 create mode 100644 tests/cts/client-body-filter/data/test8 create mode 100644 tests/cts/client-body-filter/data/test9 create mode 100644 tests/cts/client-body-filter/privoxy.conf 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 @@ + + + +HTTP +HTTP POST +client-body-filter + + + + + +HTTP/1.1 200 OK +Connection: close +Content-Type: text/html +X-Connection: swsclose + +Received your input. + + + + + +http + + +Replace whole request body with client-body-filter{blafasel-to-bumfidel} + + +proxy + + +-d blafasel http://%HOSTIP:%HTTPPORT/%TESTNUMBER + + + + + +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 + + + 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 @@ + + + +HTTP +HTTP POST +client-body-filter + + + + + +HTTP/1.1 200 OK +Connection: close +Content-Type: text/html +X-Connection: swsclose + +Received your input. + + + + + +http + + +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) + + +proxy + +# 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. + +-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 + + + + + +400 + + + 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 @@ + + + +HTTP +HTTP POST +client-body-filter + + + + + +HTTP/1.1 200 OK +Connection: close +Content-Type: text/html +X-Connection: swsclose + +Received your input. + + + + + +http + + +Applying client-body-filter{blafasel-to-bumfidel} to large client request slowly while the server times out quickly (XXX: not properly implemented) + + +proxy + + +--limit-rate 1000 -d "blafasel%repeat[5000 x padding]%" http://%HOSTIP:%HTTPPORT/%TESTNUMBER + + + + + +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]% + + + 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 @@ + + + +HTTP +HTTP POST +client-body-filter + + + + + +HTTP/1.1 200 OK +Connection: close +Content-Type: text/html +X-Connection: swsclose + +Received your first request. + + +HTTP/1.1 200 OK +Connection: close +Content-Type: text/html +X-Connection: swsclose + +Received your second request. + + + + + +http + + +Attempt to apply client-body-filter{blafasel-to-bumfidel} to client request that is too large to buffer. + + +proxy + +# 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. + +http://%HOSTIP:%HTTPPORT/first-request/%TESTNUMBER --next -d "blafasel%repeat[20000 x padding]%" http://%HOSTIP:%HTTPPORT/second-request/%TESTNUMBER + + + + + +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]% + + + 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 @@ + + + +HTTP +HTTP POST +client-body-filter + + + + + +HTTP/1.1 200 OK +Connection: close +Content-Type: text/html +X-Connection: swsclose + +Received your input. + + + + + +http + + +Modify parts of the client body with client-body-filter{blafasel-to-bumfidel} + + +proxy + + +-d "foo blafasel bar" http://%HOSTIP:%HTTPPORT/%TESTNUMBER + + + + + +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 + + + 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 @@ + + + +HTTP +HTTP POST +client-body-filter + + + + + +HTTP/1.1 200 OK +Connection: close +Content-Type: text/html +X-Connection: swsclose + +Received your input. + + + + + +http + + +Apply client-body-filter{blafasel-to-bumfidel} to request that does not contain blafasel + + +proxy + + +-d "foo bar" http://%HOSTIP:%HTTPPORT/%TESTNUMBER + + + + + +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 + + + 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 @@ + + + +HTTP +HTTP POST +client-body-filter + + + + + +HTTP/1.1 200 OK +Connection: close +Content-Type: text/html + +Received your input. + +Will keep the connection open despite the "Connection: Close" header. + + + + + +http + + +Using client-body-filter{blafasel-to-bumfidel} with server connection that times out after delivering the response + + +proxy + + +-d "blafasel" http://%HOSTIP:%HTTPPORT/%TESTNUMBER + + + + + +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 + + + 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 @@ + + + +HTTP +HTTP POST +client-body-filter + + + + + +HTTP/1.1 200 OK +Connection: close +Content-Type: text/html +X-Connection: swsclose + +Received your input. + + + + + +http + + +Applying client-body-filter{blafasel-to-bumfidel} to client request that is too large to read at once + + +proxy + + +-d "blafasel%repeat[5000 x padding]%" http://%HOSTIP:%HTTPPORT/%TESTNUMBER + + + + + +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]% + + + 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 @@ + + + +HTTP +HTTP POST +client-body-filter + + + + + +HTTP/1.1 200 OK +Connection: close +Content-Type: text/html +X-Connection: swsclose + +Received your input. + + + + + +http + + +Applying client-body-filter{blafasel-to-bumfidel} to client request that is too large to read at once and arrives slowly + + +proxy + + +--limit-rate 4k -d "blafasel%repeat[5000 x padding]%" http://%HOSTIP:%HTTPPORT/%TESTNUMBER + + + + + +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]% + + + 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 @@ + + + +HTTP +HTTP POST +client-body-filter + + + + + +HTTP/1.1 200 OK +Connection: close +Content-Type: text/html +X-Connection: swsclose + +Received your input. + + + + + +http + + +Two filters applied to client request reusing the already filtered content + + +proxy + + +-d "blafasel" http://%HOSTIP:%HTTPPORT/bumfidel-to-tralala/%TESTNUMBER + + + + + +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 + + + 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 @@ + + + +HTTP +HTTP POST +client-body-filter + + + + + +HTTP/1.1 200 OK +Connection: close +Content-Type: text/html +X-Connection: swsclose + +Received your input. + + + + + +http + + +Three filters applied to client request reusing the already filtered content. Last filter does not modify content. + + +proxy + + +-d "blafasel" http://%HOSTIP:%HTTPPORT/bumfidel-to-tralala/empty-body/%TESTNUMBER + + + + + +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 + + + 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 @@ + + + +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 + + + + + +HTTP/1.1 200 OK +Connection: close +Content-Type: text/html + +Received your input. + + + + + +HTTP/1.1 200 Connection established + +HTTP/1.1 200 OK +Connection: close +Content-Type: text/html + +Received your input. + + + + + +http + + +Attempt to apply client-body-filter{blafasel-to-bumfidel} to client request without Content-Length header + + +proxy + + +--limit-rate 1000 -d "blafasel%repeat[5000 x padding]%" -H "Content-Length:" http://%HOSTIP:%HTTPPORT/%TESTNUMBER + + + + + +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]% + + + 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 -- 2.39.2