Debian Codegraph @

testenv/Test--rejected-log.py

raw
1 #!/usr/bin/env python3
2 from sys import exit
3 from test.http_test import HTTPTest
4 from misc.wget_file import WgetFile
5
6 """
7 This test executed Wget in recursive mode with a rejected log outputted.
8 """
9 ############# File Definitions ###############################################
10 mainpage = """
11 <html>
12 <head>
13 <title>Main Page</title>
14 </head>
15 <body>
16 <p>
17 Recurse to a <a href="http://localhost:{{port}}/secondpage.html">second page</a>.
18 </p>
19 </body>
20 </html>
21 """
22
23 secondpage = """
24 <html>
25 <head>
26 <title>Second Page</title>
27 </head>
28 <body>
29 <p>
30 Recurse to a <a href="http://localhost:{{port}}/thirdpage.html">third page</a>.
31 Try the blacklisted <a href="http://localhost:{{port}}/index.html">main page</a>.
32 </p>
33 </body>
34 </html>
35 """
36
37 thirdpage = """
38 <html>
39 <head>
40 <title>Third Page</title>
41 </head>
42 <body>
43 <p>
44 Try a hidden <a href="http://localhost:{{port}}/dummy.txt">dummy file</a>.
45 Try to leave to <a href="http://no.such.domain/">another domain</a>.
46 </p>
47 </body>
48 </html>
49 """
50
51 robots = """
52 User-agent: *
53 Disallow: /dummy.txt
54 """
55
56 log = """\
57 REASON\tU_URL\tU_SCHEME\tU_HOST\tU_PORT\tU_PATH\tU_PARAMS\tU_QUERY\tU_FRAGMENT\tP_URL\tP_SCHEME\tP_HOST\tP_PORT\tP_PATH\tP_PARAMS\tP_QUERY\tP_FRAGMENT
58 BLACKLIST\thttp%3A//localhost%3A{{port}}/index.html\tSCHEME_HTTP\tlocalhost\t{{port}}\tindex.html\t\t\t\thttp%3A//localhost%3A{{port}}/secondpage.html\tSCHEME_HTTP\tlocalhost\t{{port}}\tsecondpage.html\t\t\t
59 ROBOTS\thttp%3A//localhost%3A{{port}}/dummy.txt\tSCHEME_HTTP\tlocalhost\t{{port}}\tdummy.txt\t\t\t\thttp%3A//localhost%3A{{port}}/thirdpage.html\tSCHEME_HTTP\tlocalhost\t{{port}}\tthirdpage.html\t\t\t
60 SPANNEDHOST\thttp%3A//no.such.domain/\tSCHEME_HTTP\tno.such.domain\t80\t\t\t\t\thttp%3A//localhost%3A{{port}}/thirdpage.html\tSCHEME_HTTP\tlocalhost\t{{port}}\tthirdpage.html\t\t\t
61 """
62
63 dummyfile = "Don't care."
64
65
66 index_html = WgetFile ("index.html", mainpage)
67 secondpage_html = WgetFile ("secondpage.html", secondpage)
68 thirdpage_html = WgetFile ("thirdpage.html", thirdpage)
69 robots_txt = WgetFile ("robots.txt", robots)
70 dummy_txt = WgetFile ("dummy.txt", dummyfile)
71 log_csv = WgetFile ("log.csv", log)
72
73 WGET_OPTIONS = "-nd -r --rejected-log log.csv"
74 WGET_URLS = [["index.html"]]
75
76 Files = [[index_html, secondpage_html, thirdpage_html, robots_txt, dummy_txt]]
77
78 ExpectedReturnCode = 0
79 ExpectedDownloadedFiles = [index_html, secondpage_html, thirdpage_html, robots_txt, log_csv]
80
81 ################ Pre and Post Test Hooks #####################################
82 pre_test = {
83 "ServerFiles" : Files
84 }
85 test_options = {
86 "WgetCommands" : WGET_OPTIONS,
87 "Urls" : WGET_URLS
88 }
89 post_test = {
90 "ExpectedFiles" : ExpectedDownloadedFiles,
91 "ExpectedRetcode" : ExpectedReturnCode
92 }
93
94 err = HTTPTest (
95 pre_hook=pre_test,
96 test_params=test_options,
97 post_hook=post_test
98 ).begin ()
99
100 exit (err)