To check wget for NOT sending a request header, I patched HTTPServer.pm.
Here is an example taken from the patched Test-cookies.px (see below):
...
request_headers => {
"!Cookie" => qr|foo=bar|,
},
...
That means: return an error, if there is a Cookie request header that contains
foo=bar. (I hope, I understood that perl stuff correctly).
I am not perl programmer, so maybe my changes are suboptimal. Please someone
check that.
Then, I expanded Test-cookies.px to delete the session cookie by using an
outdated 'Expires' tag. (works fine).
Also included is a test for testing the ignorance of a non-matching domain in
the Set-Cookie header. (wget fails, but shouldn't due to RFC 6265 5.3.6).
wget just replaces that foreign domain with the domain from the request-uri.
Should things like that go to the bug tracker ? (There are so many open issues
for so long time that I am unshure about that.)
Regards, Tim
From 52433c758c416e1f448ffe743c6cf502b4be4c5a Mon Sep 17 00:00:00 2001
From: Tim Ruehsen <[email protected]>
Date: Fri, 9 Nov 2012 15:51:23 +0100
Subject: [PATCH 2/2] check cookie deletion and cookie domain matching
---
tests/Test-cookies.px | 57 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 56 insertions(+), 1 deletion(-)
diff --git a/tests/Test-cookies.px b/tests/Test-cookies.px
index a4b9125..ac7da56 100755
--- a/tests/Test-cookies.px
+++ b/tests/Test-cookies.px
@@ -10,6 +10,10 @@ use HTTPTest;
my $page1 = "Hello, world!\n";
my $page2 = "Goodbye, Sam.\n";
+my $page3 = "Page three.\n";
+my $page4 = "Page four.\n";
+my $page5 = "Page five.\n";
+my $page6 = "Page six.\n";
# code, msg, headers, content
my %urls = (
@@ -30,10 +34,49 @@ my %urls = (
"Cookie" => qr|foo=bar|,
},
},
+# remove the cookie 'foo'
+ '/three.txt' => {
+ code => "200",
+ msg => "Ok",
+ headers => {
+ "Content-type" => "text/plain",
+ "Set-Cookie" => "foo=; Expires=Sun, 06 Nov 1994 08:49:37 GMT",
+ },
+ content => $page3,
+ },
+ '/four.txt' => {
+ code => "200",
+ msg => "Ok",
+ content => $page4,
+ request_headers => {
+ "!Cookie" => qr|foo=|,
+ },
+ },
+# try to set a cookie 'foo' with mismatching domain
+# see RFC 6265 5.3.6: ignore the cookie if it doesn't domain-match
+ '/five.txt' => {
+ code => "200",
+ msg => "Ok",
+ headers => {
+ "Content-type" => "text/plain",
+ "Set-Cookie" => "foo=bar; domain=.example.com",
+ },
+ content => $page5,
+ },
+ '/six.txt' => {
+ code => "200",
+ msg => "Ok",
+ content => $page6,
+ request_headers => {
+ "!Cookie" => qr|foo=bar|,
+ },
+ },
);
my $cmdline = $WgetTest::WGETPATH . " http://localhost:{{port}}/one.txt"
- . " http://localhost:{{port}}/two.txt";
+ . " http://localhost:{{port}}/two.txt" . " http://localhost:{{port}}/three.txt"
+ . " http://localhost:{{port}}/four.txt" . " http://localhost:{{port}}/five.txt"
+ . " http://localhost:{{port}}/six.txt";
my $expected_error_code = 0;
@@ -44,6 +87,18 @@ my %expected_downloaded_files = (
'two.txt' => {
content => $page2,
},
+ 'three.txt' => {
+ content => $page3,
+ },
+ 'four.txt' => {
+ content => $page4,
+ },
+ 'five.txt' => {
+ content => $page5,
+ },
+ 'six.txt' => {
+ content => $page6,
+ },
);
###############################################################################
--
1.7.10.4
From 6df4298e93f54ef6a284f5e58666c6158f472fed Mon Sep 17 00:00:00 2001
From: Tim Ruehsen <[email protected]>
Date: Fri, 9 Nov 2012 15:50:03 +0100
Subject: [PATCH 1/2] added check for must-not-match request-header
---
tests/HTTPServer.pm | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/tests/HTTPServer.pm b/tests/HTTPServer.pm
index 627c102..065ea1e 100644
--- a/tests/HTTPServer.pm
+++ b/tests/HTTPServer.pm
@@ -218,12 +218,24 @@ sub verify_request_headers {
return 1 unless exists $url_rec->{'request_headers'};
for my $hdrname (keys %{$url_rec->{'request_headers'}}) {
- my $rhdr = $req->header ($hdrname);
+ my $must_not_match;
my $ehdr = $url_rec->{'request_headers'}{$hdrname};
- unless (defined $rhdr && $rhdr =~ $ehdr) {
- $rhdr = '' unless defined $rhdr;
- print STDERR "\n*** Mismatch on $hdrname: $rhdr =~ $ehdr\n";
- return undef;
+ if ($must_not_match = ($hdrname =~ /^!(\w+)/)) {
+ $hdrname = $1;
+ }
+ my $rhdr = $req->header ($hdrname);
+ if ($must_not_match) {
+ if (defined $rhdr && $rhdr =~ $ehdr) {
+ $rhdr = '' unless defined $rhdr;
+ print STDERR "\n*** Match forbidden $hdrname: $rhdr =~ $ehdr\n";
+ return undef;
+ }
+ } else {
+ unless (defined $rhdr && $rhdr =~ $ehdr) {
+ $rhdr = '' unless defined $rhdr;
+ print STDERR "\n*** Mismatch on $hdrname: $rhdr =~ $ehdr\n";
+ return undef;
+ }
}
}
--
1.7.10.4