1#!/usr/bin/env python3
2from sys import exit
3from test.http_test import HTTPTest
4from misc.wget_file import WgetFile
5import os
6
7# This test caused wget up to 1.16 to crash
8#os.environ["LC_ALL"] = "en_US.UTF-8"
9
10urls = [
11    "File%20formats/Images/SVG,%20Scalable%20Vector%20Graphics/html,%20W3C%20v1.2%20rec%20(tiny)/directory",
12    "File formats/Images/SVG, Scalable Vector Graphics/html, W3C v1.2 rec (tiny)/directory/",
13    "File%20formats/Images/SVG,%20Scalable%20Vector%20Graphics/html,%20W3C%20v1.2%20rec%20(tiny)/directory/somefile.rng",
14    "File%20formats/Images/SVG%2C%20Scalable%20Vector%20Graphics/html%2c%20W3C%20v1.2%20rec%20%28tiny%29/directory/somefile.rng",
15    "File%20formats/Images/SVG%2C%20Scalable%20Vector%20Graphics/html%2c%20W3C%20v1.2%20rec%20%28tiny%29/directory/",
16    "File%20formats/Images/SVG%2C%20Scalable%20Vector%20Graphics/html%2C%20W3C%20v1.2%20rec%20%28tiny%29/directory"]
17
18
19redirected = [
20        "File%20formats/Images/SVG,%20Scalable%20Vector%20Graphics/html,%20W3C%20v1.2%20rec%20(tiny)/directory/"
21]
22
23############# File Definitions ###############################################
24Index = ""
25for i in urls:
26    Index = Index + "<a href='/%s'></a>" % i
27
28File1 = ""
29
30def get_redirect(url):
31    data = {
32        "File%20formats/Images/SVG,%20Scalable%20Vector%20Graphics/html,%20W3C%20v1.2%20rec%20(tiny)/directory" :
33           "File%20formats/Images/SVG,%20Scalable%20Vector%20Graphics/html,%20W3C%20v1.2%20rec%20(tiny)/directory/",
34        "File%20formats/Images/SVG%2C%20Scalable%20Vector%20Graphics/html%2C%20W3C%20v1.2%20rec%20%28tiny%29/directory" :
35           "File%20formats/Images/SVG,%20Scalable%20Vector%20Graphics/html,%20W3C%20v1.2%20rec%20(tiny)/directory/"
36    }
37    dest = data.get(url)
38    if dest:
39        return {"Response"          : 301,
40                "SendHeader" : {"Location" : "/%s" % dest}}
41    return None
42
43
44index_url = "File%20formats/Images/SVG,%20Scalable%20Vector%20Graphics/html,%20W3C%20v1.2%20rec%20(tiny)/index.html"
45Index_File = WgetFile (index_url, Index)
46Files = ([Index_File] + [WgetFile(i, File1, rules=get_redirect(i)) for i in (redirected + urls)])
47
48WGET_OPTIONS = "--recursive -e robots=off"
49
50WGET_URLS = [[index_url]]
51
52ExpectedReturnCode = 0
53
54################ Pre and Post Test Hooks #####################################
55pre_test = {
56    "ServerFiles"       : [Files]
57}
58test_options = {
59    "WgetCommands"      : WGET_OPTIONS,
60    "Urls"              : WGET_URLS
61}
62post_test = {
63    "ExpectedRetcode"   : ExpectedReturnCode,
64}
65
66err = HTTPTest (
67                pre_hook=pre_test,
68                test_params=test_options,
69                post_hook=post_test
70).begin ()
71
72exit (err)
73