| 1 |
#!/usr/bin/env perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use HTTPTest; |
| 7 |
|
| 8 |
|
| 9 |
############################################################################### |
| 10 |
|
| 11 |
my $mainpage = <<EOF; |
| 12 |
<html> |
| 13 |
<head> |
| 14 |
<title>Main Page</title> |
| 15 |
</head> |
| 16 |
<body> |
| 17 |
<p> |
| 18 |
Some text and a link to a <a href="http://localhost:{{port}}/firstlevel/secondpage.html">second page</a>. |
| 19 |
</p> |
| 20 |
</body> |
| 21 |
</html> |
| 22 |
EOF |
| 23 |
|
| 24 |
my $secondpage = <<EOF; |
| 25 |
<html> |
| 26 |
<head> |
| 27 |
<title>Second Page</title> |
| 28 |
</head> |
| 29 |
<body> |
| 30 |
<p> |
| 31 |
Some text and a link to a <a href="http://localhost:{{port}}/firstlevel/lowerlevel/thirdpage.html">third page</a>. |
| 32 |
</p> |
| 33 |
</body> |
| 34 |
</html> |
| 35 |
EOF |
| 36 |
|
| 37 |
my $thirdpage = <<EOF; |
| 38 |
<html> |
| 39 |
<head> |
| 40 |
<title>Third Page</title> |
| 41 |
</head> |
| 42 |
<body> |
| 43 |
<p> |
| 44 |
Some text and a link to a <a href="http://localhost:{{port}}/higherlevelpage.html">higher level page</a>. |
| 45 |
</p> |
| 46 |
</body> |
| 47 |
</html> |
| 48 |
EOF |
| 49 |
|
| 50 |
my $fourthpage = <<EOF; |
| 51 |
<html> |
| 52 |
<head> |
| 53 |
<title>Fourth Page</title> |
| 54 |
</head> |
| 55 |
<body> |
| 56 |
<p> |
| 57 |
This page is only linked by the higher level page. Therefore, it should not |
| 58 |
be downloaded. |
| 59 |
</p> |
| 60 |
</body> |
| 61 |
</html> |
| 62 |
EOF |
| 63 |
|
| 64 |
my $higherlevelpage = <<EOF; |
| 65 |
<html> |
| 66 |
<head> |
| 67 |
<title>Higher Level Page</title> |
| 68 |
</head> |
| 69 |
<body> |
| 70 |
<p> |
| 71 |
This page is on a higher level in the URL path hierarchy. Therefore, it |
| 72 |
should not be downloaded. Wget should not visit the following link to a |
| 73 |
<a href="http://localhost:{{port}}/firstlevel/fourthpage.html">fourth page</a>. |
| 74 |
</p> |
| 75 |
</body> |
| 76 |
</html> |
| 77 |
EOF |
| 78 |
|
| 79 |
# code, msg, headers, content |
| 80 |
my %urls = ( |
| 81 |
'/firstlevel/index.html' => { |
| 82 |
code => "200", |
| 83 |
msg => "Dontcare", |
| 84 |
headers => { |
| 85 |
"Content-type" => "text/html", |
| 86 |
}, |
| 87 |
content => $mainpage, |
| 88 |
}, |
| 89 |
'/firstlevel/secondpage.html' => { |
| 90 |
code => "200", |
| 91 |
msg => "Dontcare", |
| 92 |
headers => { |
| 93 |
"Content-type" => "text/html", |
| 94 |
}, |
| 95 |
content => $secondpage, |
| 96 |
}, |
| 97 |
'/firstlevel/lowerlevel/thirdpage.html' => { |
| 98 |
code => "200", |
| 99 |
msg => "Dontcare", |
| 100 |
headers => { |
| 101 |
"Content-type" => "text/html", |
| 102 |
}, |
| 103 |
content => $thirdpage, |
| 104 |
}, |
| 105 |
'/firstlevel/fourthpage.html' => { |
| 106 |
code => "200", |
| 107 |
msg => "Dontcare", |
| 108 |
headers => { |
| 109 |
"Content-type" => "text/plain", |
| 110 |
}, |
| 111 |
content => $fourthpage, |
| 112 |
}, |
| 113 |
'/higherlevelpage.html' => { |
| 114 |
code => "200", |
| 115 |
msg => "Dontcare", |
| 116 |
headers => { |
| 117 |
"Content-type" => "text/plain", |
| 118 |
}, |
| 119 |
content => $higherlevelpage, |
| 120 |
}, |
| 121 |
); |
| 122 |
|
| 123 |
my $cmdline = $WgetTest::WGETPATH . " -np -nH -r http://localhost:{{port}}/firstlevel/"; |
| 124 |
|
| 125 |
my $expected_error_code = 0; |
| 126 |
|
| 127 |
my %expected_downloaded_files = ( |
| 128 |
'firstlevel/index.html' => { |
| 129 |
content => $mainpage, |
| 130 |
}, |
| 131 |
'firstlevel/secondpage.html' => { |
| 132 |
content => $secondpage, |
| 133 |
}, |
| 134 |
'firstlevel/lowerlevel/thirdpage.html' => { |
| 135 |
content => $thirdpage, |
| 136 |
}, |
| 137 |
); |
| 138 |
|
| 139 |
############################################################################### |
| 140 |
|
| 141 |
my $the_test = HTTPTest->new (input => \%urls, |
| 142 |
cmdline => $cmdline, |
| 143 |
errcode => $expected_error_code, |
| 144 |
output => \%expected_downloaded_files); |
| 145 |
exit $the_test->run(); |
| 146 |
|
| 147 |
# vim: et ts=4 sw=4 |