1#!/usr/bin/env perl
2
3use strict;
4use warnings;
5
6use HTTPTest;
7
8
9###############################################################################
10
11my $page1 = "Hello, world!\n";
12my $page2 = "Goodbye, Sam.\n";
13my $page3 = "Page three.\n";
14my $page4 = "Page four.\n";
15my $page5 = "Page five.\n";
16my $page6 = "Page six.\n";
17
18# code, msg, headers, content
19my %urls = (
20    '/one.txt' => {
21        code => "200",
22        msg => "Ok",
23        headers => {
24            "Content-type" => "text/plain",
25            "Set-Cookie" => "foo=bar",
26        },
27        content => $page1,
28    },
29    '/two.txt' => {
30        code => "200",
31        msg => "Ok",
32        content => $page2,
33        request_headers => {
34            "Cookie" => qr|foo=bar|,
35        },
36    },
37# remove the cookie 'foo'
38    '/three.txt' => {
39        code => "200",
40        msg => "Ok",
41        headers => {
42            "Content-type" => "text/plain",
43            "Set-Cookie" => "foo=; Expires=Sun, 06 Nov 1994 08:49:37 GMT",
44        },
45        content => $page3,
46    },
47    '/four.txt' => {
48        code => "200",
49        msg => "Ok",
50        content => $page4,
51        request_headers => {
52            "!Cookie" => qr|foo=|,
53        },
54    },
55# try to set a cookie 'foo' with mismatching domain
56# see RFC 6265 5.3.6: ignore the cookie if it doesn't domain-match
57    '/five.txt' => {
58        code => "200",
59        msg => "Ok",
60        headers => {
61            "Content-type" => "text/plain",
62            "Set-Cookie" => "foo=bar; domain=.example.com",
63        },
64        content => $page5,
65    },
66    '/six.txt' => {
67        code => "200",
68        msg => "Ok",
69        content => $page6,
70        request_headers => {
71            "!Cookie" => qr|foo=bar|,
72        },
73    },
74);
75
76my $cmdline = $WgetTest::WGETPATH . " http://localhost:{{port}}/one.txt"
77    . " http://localhost:{{port}}/two.txt" . " http://localhost:{{port}}/three.txt"
78    . " http://localhost:{{port}}/four.txt" . " http://localhost:{{port}}/five.txt"
79	 . " http://localhost:{{port}}/six.txt";
80
81my $expected_error_code = 0;
82
83my %expected_downloaded_files = (
84    'one.txt' => {
85        content => $page1,
86    },
87    'two.txt' => {
88        content => $page2,
89    },
90    'three.txt' => {
91        content => $page3,
92    },
93    'four.txt' => {
94        content => $page4,
95    },
96    'five.txt' => {
97        content => $page5,
98    },
99    'six.txt' => {
100        content => $page6,
101    },
102);
103
104###############################################################################
105
106my $the_test = HTTPTest->new (input => \%urls,
107                              cmdline => $cmdline,
108                              errcode => $expected_error_code,
109                              output => \%expected_downloaded_files);
110exit $the_test->run();
111
112# vim: et ts=4 sw=4
113