1#!/usr/bin/env python3 2 3from sys import exit 4from misc.metalinkv3_xml import Metalinkv3_XML 5 6""" 7 This is to test if Metalink/XML forbids absolute paths. 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 ############################################### 19wrong_file = "Ouch!" 20 21File1 = "Would you like some Tea?" 22File1_lowPref = "Do not take this" 23 24File2 = "This is gonna be good" 25File2_lowPref = "Not this one too" 26 27File3 = "A little more, please" 28File3_lowPref = "That's just too much" 29 30File4 = "Maybe a biscuit?" 31File4_lowPref = "No, thanks" 32 33File5 = "More Tea...?" 34File5_lowPref = "I have to go..." 35 36############# Metalink/XML ################################################### 37Meta = 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 57# location : metalink:url location (default 'no location field') 58# preference : metalink:url preference (default 999999) 59 60XmlName = "test.metalink" 61 62Meta.xml ( 63 # Metalink/XML file name 64 XmlName, 65 # file_name, save_name, content, size, hash_sha256 66 ["/File1", None, 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", "File2", File2, None, True, 73 ["wrong_file", wrong_file, "http", None, 35], 74 ["404", None, "http", None, 40], 75 ["File2_lowPref", File2_lowPref, "http", None, 25], 76 ["File2", File2, "http", None, 30]], 77 ["/File3", None, 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", None, File4, None, True, 83 ["wrong_file", wrong_file, "http", None, 35], 84 ["404", None, "http", None, 40], 85 ["File4_lowPref", File4_lowPref, "http", None, 25], 86 ["File4", File4, "http", None, 30]], 87 ["File5", "File5", 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 94Meta.print_meta () 95 96err = Meta.http_test ( 97 "--trust-server-names " + \ 98 "--input-metalink " + XmlName, 0 99) 100 101exit (err) 102