Debian Codegraph @

testenv/Test-metalink-xml-nourls.py

raw
1 #!/usr/bin/env python3
2
3 from sys import exit
4 from misc.metalinkv3_xml import Metalinkv3_XML
5
6 """
7 This is to test Metalink/XML with unknown url types.
8
9 With --trust-server-names, trust the metalink:file names.
10
11 Without --trust-server-names, don't trust the metalink:file names:
12 use the basename of --input-metalink, and add a sequential number
13 (e.g. .#1, .#2, etc.).
14
15 Strip the directory from unsafe paths.
16 """
17
18 ############# File Definitions ###############################################
19 wrong_file = "Ouch!"
20
21 File1 = "Would you like some Tea?"
22 File1_lowPref = "Do not take this"
23
24 File2 = "This is gonna be good"
25 File2_lowPref = "Not this one too"
26
27 File3 = "A little more, please"
28 File3_lowPref = "That's just too much"
29
30 File4 = "Maybe a biscuit?"
31 File4_lowPref = "No, thanks"
32
33 File5 = "More Tea...?"
34 File5_lowPref = "I have to go..."
35
36 ############# Metalink/XML ###################################################
37 Meta = Metalinkv3_XML()
38
39 # file_name: metalink:file "name" field
40 # save_name: metalink:file save name, if None the file is rejected
41 # content : metalink:file content
42 #
43 # size:
44 # True auto-compute size
45 # None no <size></size>
46 # any use this size
47 #
48 # hash_sha256:
49 # False no <verification></verification>
50 # True auto-compute sha256
51 # None no <hash></hash>
52 # any use this hash
53 #
54 # srv_file : metalink:url server file
55 # srv_content: metalink:url server file content, if None the file doesn't exist
56 # utype : metalink:url type (http, ftp, etc.)
57 # location : metalink:url location (default 'no location field')
58 # preference : metalink:url preference (default 999999)
59
60 XmlName = "test.metalink"
61
62 Meta.xml (
63 # Metalink/XML file name
64 XmlName,
65 # file_name, save_name, content, size, hash_sha256
66 ["File1", XmlName + ".#1", File1, None, True,
67 # srv_file, srv_content, utype, location, preference
68 ["wrong_file", wrong_file, "http", None, 35],
69 ["404", None, "http", None, 40],
70 ["File1_lowPref", File1_lowPref, "http", None, 25],
71 ["File1", File1, "http", None, 30]],
72 ["File2", None, File2, None, True,
73 ["wrong_file", wrong_file, "unknown", None, 35],
74 ["404", None, "unknown", None, 40],
75 ["File2_lowPref", File2_lowPref, "unknown", None, 25],
76 ["File2", File2, "unknown", None, 30]],
77 ["File3", XmlName + ".#3", File3, None, True,
78 ["wrong_file", wrong_file, "http", None, 35],
79 ["404", None, "http", None, 40],
80 ["File3_lowPref", File3_lowPref, "http", None, 25],
81 ["File3", File3, "http", None, 30]],
82 ["File4", XmlName + ".#4", File4, None, True,
83 ["wrong_file", wrong_file, "unknown", None, 35],
84 ["404", None, "unknown", None, 40],
85 ["File4_lowPref", File4_lowPref, "unknown", None, 25],
86 ["File4", File4, "http", None, 30]],
87 ["File5", XmlName + ".#5", File5, None, True,
88 ["wrong_file", wrong_file, "http", None, 35],
89 ["404", None, "http", None, 40],
90 ["File5_lowPref", File5_lowPref, "http", None, 25],
91 ["File5", File5, "http", None, 30]],
92 )
93
94 Meta.print_meta ()
95
96 err = Meta.http_test (
97 "--input-metalink " + XmlName, 1
98 )
99
100 exit (err)