From 1c934e67ded41ac9f57e4ded727d9ed2bd745464 Mon Sep 17 00:00:00 2001 From: Darshit Shah Date: Sat, 16 Mar 2024 19:12:31 +0100 Subject: [PATCH] Add a new testcase for pathconf truncation * testenv/Test-recursive-pathmax.py: Add a new testcase. This test tries to check that Wget allows downloading long filenames as far as allowed by the OS and filesystem. --- testenv/Test-recursive-pathmax.py | 79 +++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 testenv/Test-recursive-pathmax.py diff --git a/testenv/Test-recursive-pathmax.py b/testenv/Test-recursive-pathmax.py new file mode 100755 index 00000000..f5b75f26 --- /dev/null +++ b/testenv/Test-recursive-pathmax.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python3 + +import random +import string +import os +from sys import exit +from test.http_test import HTTPTest +from test.base_test import HTTP +from misc.wget_file import WgetFile + +""" + Basic test of --recursive. +""" +############# File Definitions ############################################### + +max_path_len = os.pathconf(os.getcwd(), 'PC_PATH_MAX') +max_name_len = os.pathconf(os.getcwd(), 'PC_NAME_MAX') + +# 19 is a magic number. See CHOMP_BUFFER in url.c to have an understanding of where it comes from +long_filename = 'deeper/than/' + ''.join(random.choices(string.ascii_lowercase, k=(max_name_len - 19))) + +# Since this filename is one larger than the CHOMP_BUFFER, it should cause Wget to truncate the filename when saving it +# to disk. +very_long_filename = 'deeper/than/' + ''.join(random.choices(string.ascii_lowercase, k=(max_name_len - 18))) + +File1 = f""" +text +text +text +""" +File2 = "With lemon or cream?" +File3 = "Surely you're joking Mr. Feynman" +File4 = "This filename will be truncated" + +File1_File = WgetFile("index.html", File1) +File2_File = WgetFile("a/File2.html", File2) +File3_File = WgetFile(long_filename, File3) +File4_File = WgetFile(very_long_filename, File4) +File4saved_File = WgetFile(very_long_filename[:-1], File4) + +WGET_OPTIONS = "--recursive --no-host-directories" +WGET_URLS = [[""]] + +Servers = [HTTP] + +Files = [[File1_File, File2_File, File3_File, File4_File]] +Existing_Files = [] + +ExpectedReturnCode = 0 +ExpectedDownloadedFiles = [File1_File, File2_File, File3_File, File4saved_File] +Request_List = [["GET /", + "GET /robots.txt", + "GET /a/File2.html", + f"GET /{long_filename}", + f"GET /{very_long_filename}"]] + +################ Pre and Post Test Hooks ##################################### +pre_test = { + "ServerFiles" : Files, + "LocalFiles" : Existing_Files +} +test_options = { + "WgetCommands" : WGET_OPTIONS, + "Urls" : WGET_URLS +} +post_test = { + "ExpectedFiles" : ExpectedDownloadedFiles, + "ExpectedRetcode" : ExpectedReturnCode, + "FilesCrawled" : Request_List +} + +err = HTTPTest ( + pre_hook=pre_test, + test_params=test_options, + post_hook=post_test, + protocols=Servers +).begin () + +exit (err)