]> sjero.net Git - wget/blob - tests/Test-cookies.px
Fix build when libpsl is not available
[wget] / tests / Test-cookies.px
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use HTTPTest;
7
8
9 ###############################################################################
10
11 my $page1 = "Hello, world!\n";
12 my $page2 = "Goodbye, Sam.\n";
13 my $page3 = "Page three.\n";
14 my $page4 = "Page four.\n";
15 my $page5 = "Page five.\n";
16 my $page6 = "Page six.\n";
17
18 # code, msg, headers, content
19 my %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
76 my $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
81 my $expected_error_code = 0;
82
83 my %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
106 my $the_test = HTTPTest->new (name => "Test-cookies",
107                               input => \%urls,
108                               cmdline => $cmdline,
109                               errcode => $expected_error_code,
110                               output => \%expected_downloaded_files);
111 exit $the_test->run();
112
113 # vim: et ts=4 sw=4
114