wget/testenv
Darshit Shah 1c934e67de 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.
2024-03-16 19:14:57 +01:00
..
certs Fix typos detected by codespell (via contrib/spell-checker) 2018-12-28 18:58:15 +01:00
conf * testenv/conf/expected_files.py: Aesthetic changes only. Format file with black 2024-02-19 18:27:32 +05:30
exc Support conditional GET in testenv server. 2015-05-22 11:08:30 +02:00
misc New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
server testenv: fix for Python 3.12 2023-07-16 14:08:30 +02:00
test * testenv/test/base_test.py: Rename valgrind-suppression-ssl -> valgrind-suppressions-ssl 2021-04-11 19:41:03 +02:00
Makefile.am * Update copyright year to 2024 2024-02-19 18:33:43 +05:30
README cfg.mk: Replace uses of filesystem with file system 2023-05-11 01:03:23 +02:00
test_css_url.py Add new test to ensure CSS url() encoding 2023-05-16 00:11:25 +02:00
Test-416.py Add new test for 416 responses 2017-12-11 14:48:01 +01:00
Test-504.py Set X flags for python tests 2016-04-15 21:36:51 +02:00
Test--convert-links--content-on-error.py Set X flags for python tests 2016-04-15 21:36:51 +02:00
Test--https-crl.py Fix usage of Magic number of tests 2020-12-28 01:54:16 +01:00
Test--https.py testenv/Test--https.py: Fix missing import 2020-12-28 02:10:10 +01:00
Test--rejected-log.py Fix python test suite for GnuTLS 3.5.12+ 2017-07-09 11:39:05 +02:00
Test--spider-r.py Fix python test suite for GnuTLS 3.5.12+ 2017-07-09 11:39:05 +02:00
Test-auth-basic-fail.py Fix typos found by codespell 2020-02-20 16:21:33 +01:00
Test-auth-basic-netrc-pass-given.py Fix typos found by codespell 2020-02-20 16:21:33 +01:00
Test-auth-basic-netrc-user-given.py Fix typos found by codespell 2020-02-20 16:21:33 +01:00
Test-auth-basic-netrc.py Fix typos found by codespell 2020-02-20 16:21:33 +01:00
Test-auth-basic-no-netrc-fail.py Fix typos found by codespell 2020-02-20 16:21:33 +01:00
Test-auth-basic.py Fix typos found by codespell 2020-02-20 16:21:33 +01:00
Test-auth-both.py Fix typos in comments 2017-04-01 19:38:09 +02:00
Test-auth-digest.py Set X flags for python tests 2016-04-15 21:36:51 +02:00
Test-auth-no-challenge-url.py Set X flags for python tests 2016-04-15 21:36:51 +02:00
Test-auth-no-challenge.py Set X flags for python tests 2016-04-15 21:36:51 +02:00
Test-auth-retcode.py Set X flags for python tests 2016-04-15 21:36:51 +02:00
Test-auth-with-content-disposition.py Set X flags for python tests 2016-04-15 21:36:51 +02:00
Test-c-full.py Set X flags for python tests 2016-04-15 21:36:51 +02:00
Test-condget.py Fix typos found by codespell 2020-02-20 16:21:33 +01:00
Test-Content-disposition-2.py Set X flags for python tests 2016-04-15 21:36:51 +02:00
Test-Content-disposition.py Fix typos detected by codespell (via contrib/spell-checker) 2018-12-28 18:58:15 +01:00
Test-cookie-401.py Set X flags for python tests 2016-04-15 21:36:51 +02:00
Test-cookie-domain-mismatch.py Set X flags for python tests 2016-04-15 21:36:51 +02:00
Test-cookie-expires.py Set X flags for python tests 2016-04-15 21:36:51 +02:00
Test-cookie.py Set X flags for python tests 2016-04-15 21:36:51 +02:00
Test-Head.py Set X flags for python tests 2016-04-15 21:36:51 +02:00
Test-hsts.py Fix usage of Magic number of tests 2020-12-28 01:54:16 +01:00
Test-https-k.py Add tests for --convert-links option 2024-02-19 18:27:38 +05:30
Test-k.py Add tests for --convert-links option 2024-02-19 18:27:38 +05:30
Test-metalink-http-baddigest.py Bugfix: Detect malformed base64 Metalink/HTTP Digest header 2016-09-30 19:44:06 +02:00
Test-metalink-http-quoted.py Bugfix: Remove surrounding quotes from Metalink/HTTP key's value 2016-09-30 19:44:05 +02:00
Test-metalink-http-xml-trust-name.py New: --trust-server-names saves Metalink/HTTP xml files using the "name" field 2016-09-30 19:44:06 +02:00
Test-metalink-http-xml-trust.py New option --metalink-index to process Metalink application/metalink4+xml 2016-09-30 19:44:06 +02:00
Test-metalink-http-xml-type-content.py New: --metalink-over-http Content-Type/Disposition Metalink/XML processing 2016-09-30 19:44:06 +02:00
Test-metalink-http-xml-type-trust-content.py New: --metalink-over-http Content-Type/Disposition Metalink/XML processing 2016-09-30 19:44:06 +02:00
Test-metalink-http-xml-type-trust.py New: --metalink-over-http Content-Type/Disposition Metalink/XML processing 2016-09-30 19:44:06 +02:00
Test-metalink-http-xml-type.py New: --metalink-over-http Content-Type/Disposition Metalink/XML processing 2016-09-30 19:44:06 +02:00
Test-metalink-http-xml.py New option --metalink-index to process Metalink application/metalink4+xml 2016-09-30 19:44:06 +02:00
Test-metalink-http.py Use python .replace instead than re.sub in Metalink tests 2016-09-19 05:56:40 +02:00
Test-metalink-xml-abspath-trust.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-abspath.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-absprefix-trust.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-absprefix.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-continue.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-emptyprefix-trust.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-homepath-trust.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-homepath.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-homeprefix-trust.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-homeprefix.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-nohash.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-nourls.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-prefix-trust.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-prefix.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-relpath-trust.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-relpath.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-relprefix-trust.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-relprefix.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-size.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-trust.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-metalink-xml-urlbreak.py Bugfix: Process Metalink/XML url strings containing white spaces and CRLF 2016-09-30 19:44:05 +02:00
Test-metalink-xml.py New: Metalink/XML v3 python class, update tests to use this class 2016-09-30 19:44:06 +02:00
Test-missing-scheme-retval.py Add new Test for missing scheme behavior 2016-06-03 10:16:40 +02:00
Test-no_proxy-env.py Fix issues from syntax-check 2022-02-26 16:20:30 +01:00
Test-O.py Set X flags for python tests 2016-04-15 21:36:51 +02:00
Test-Parallel-Proto.py Set X flags for python tests 2016-04-15 21:36:51 +02:00
Test-pinnedpubkey-der-https.py Fix usage of Magic number of tests 2020-12-28 01:54:16 +01:00
Test-pinnedpubkey-der-no-check-https.py Fix usage of Magic number of tests 2020-12-28 01:54:16 +01:00
Test-pinnedpubkey-hash-https.py Fix usage of Magic number of tests 2020-12-28 01:54:16 +01:00
Test-pinnedpubkey-hash-no-check-fail-https.py Fix usage of Magic number of tests 2020-12-28 01:54:16 +01:00
Test-pinnedpubkey-pem-fail-https.py Fix usage of Magic number of tests 2020-12-28 01:54:16 +01:00
Test-pinnedpubkey-pem-https.py Fix usage of Magic number of tests 2020-12-28 01:54:16 +01:00
Test-Post.py Set X flags for python tests 2016-04-15 21:36:51 +02:00
Test-Proto.py Corrections and amplifications to test documentation 2016-09-02 17:44:10 +02:00
Test-recursive-basic.py * testenv/Test-recursive-basic.py: Check crawled files 2017-05-16 11:20:57 +02:00
Test-recursive-include.py Parse 'srcset' HTML attr for 'source' HTML tag. 2024-01-27 19:50:13 +01:00
Test-recursive-pathmax.py Add a new testcase for pathconf truncation 2024-03-16 19:14:57 +01:00
Test-recursive-redirect.py Amend redirection behavior 2016-10-07 11:49:07 +02:00
Test-redirect-crash.py Set X flags for python tests 2016-04-15 21:36:51 +02:00
Test-redirect.py Add tests for recursion and redirection. 2016-09-02 17:46:36 +02:00
Test-reserved-chars.py Set X flags for python tests 2016-04-15 21:36:51 +02:00
valgrind-suppressions-ssl Fix testenv valgrind suppression 2021-04-11 19:09:45 +02:00

This document describes the working of the GNU Wget Test Suite.

Install Instructions:
================================================================================

This Test Suite exploits the Parallel Test Harness available in GNU Autotools.
Since it uses features from a relatively recent version of Autotools, the minimum
required version as been bumped up to 1.11.
Run the './configure' command to generate the Makefile and then run 'make check'
to execute the Test Suite. Use the '-j n' option with 'make check' to execute
n tests simultaneously.

Structure:
================================================================================

    * server: This package contains custom programmatically configurable servers
    (both HTTP and FTP) for testing Wget. The HTTP server runs an instance of
    Python's http.server module. The FTP server is to be implemented.

    * test: This package contains the test case classes for HTTP and FTP. The
    test case classes includes methods for initializing and cleaning up of the
    test environment.

    * Test-Proto.py: This is a prototype Test Case file. The file defines all
    the acceptable elements and their uses. Typically, one must copy this file
    and edit it for writing Test Cases.

    * exc: This package contains custom exception classes used in this test
    suite.

    * conf: This package contains the configuration classes for servers to be
    configured with.

    * misc: This package contains several helper modules used in this test
    suite.
        - colour_terminal.py: A custom module for printing coloured output to
        the terminal. Currently it only supports 4 colours in a *nix
        environment.
        - wget_file.py: Module which contains WgetFile, which is a file data
        container object.

Working:
================================================================================

The Test Files are valid Python scripts and the default mask for them is 755.
A singular Test must be invoked in the following manner, with the current
directory being the testenv directory:
$ ./python3 <Name of Test File>      OR
$ ./<Name of Test File>
The script will then initialize the various elements and pass them to an object
of the respective Test Class. A directory with the name <Test name>-test will be
created and the PWD will be changed to this directory. The server is then
spawned with the required configuration elements. A blocking call to Wget is
made with the command line arguments specified in the Test Case along with the
list of URLs that it must download. The server is killed once Wget returns and
the following checks are used to determine the pass/fail status of the test:
    * Return Code: The Exit code of Wget is matched against the expected Exit
    Code as mentioned in the Test Case File.
    * Downloaded Files: Check whether the expected downloaded files exist on
    disk.
    * File Content: Test whether the file contents were correctly downloaded by
    Wget and not corrupted mid-way.
    * Excess Files: Check to see whether any unexpected files were downloaded
    by Wget.

Exit Codes:
===============================================================================

Following is a list of Exit Status Codes for the tests:
*   0  Test Successful
*  66  Errors/Warnings Reported by Thread Sanitizer (If built with -fsanitize)
*  77  Test Skipped
*  99  Hard Error
* 100  Test Failed

Tests are skipped when they are either not supported by the platform, or Wget
is not compiled with support for that feature. This feature has not yet been
implemented.

Hard Errors occur when there are problems with the Environment code. Hard
Error reporting is currently not enabled and all errors are reported as
failures.

All exceptions should ideally be handled gracefully. If you see any unhandled
exceptions, please file a bug report at <bug-wget@gnu.org>

Environment Variables:
================================================================================

* SERVER_WAIT: Set this environment variable with a value for the number of
  seconds the test should sleep between invoking the server and calling the Wget
  executable. This is used when one would like to test a different version of
  the executable or for running the test through external utilities like gdb and
  valgrind.
* NO_CLEANUP: Do not remove the temporary files created by the test.
  This will prevent the ${testname}-test directory from being deleted
* VALGRIND_TESTS: If this variable is set and contains the valgrind command line,
  the test suite will execute all the tests via this command.
  If it is set to "1", valgrind memcheck is enabled with hard coded options.
  This variable is set by ./configure --enable-valgrind-tests.
* SSL_TESTS: This must be set to run any https tests.
* WGET_PATH: Set this environment variable to a path to wget binary on which you
  want to run tests. This is useful for OS distributions, which want to reuse
  upstream tests for testing wget build that they distribute. If the variable is
  not set, the "../src/wget" binary is used by tests.


File Structure:
================================================================================

The test case files are Python scripts. It is believed that Python is a simple
yet elegant language and should be easy for everyone to comprehend. This test
suite is written with the objective of making it easy to write new tests. The
structure has been kept as intuitive as possible and should not require much
effort to get accustomed to.

All Test Files MUST begin with the following Three Lines:
#!/usr/bin/python3
from sys import exit
from WgetTest import {HTTPTest|FTPTest}
from misc.wget_file import WgetFile

It is recommended that a small description of the Test Case is provided next.
This would be very helpful to future contributors.

Each File in the Test must be represented as a WgetFile object. The WgetFile
Class has the following prototype:
WgetFile (str name, str contents, str timestamp, dict rules)
None except name is a mandatory parameter, one may pass only those parameters
that are required by the File object.

The timestamp string should be in a format: "YYYY-MM-DD HH:MM:SS" in UTC zone.
The rules object is a dictionary element, with the key as the Rule Name and
value as the Rule Data. In most cases, the Rule Data is another dictionary.

Various variables used consistently across all tests are:
    * WGET_OPTIONS: The command line string passed to Wget upon invocation. This
    string may contain URLs, like in the case where in-URL authentication is
    used. Variable names passed like {{var_name}} will be replaced by the
    contents of the variable self.var_name before being passed to Wget
    * WGET_URLS: This is a list of filenames which will be appended as the URLs
    to Wget during invocation. This is a list of lists, where WGET_URLS[0]
    represents the list of Filenames called from Server[0], WGET_URLS[1] is a
    list of files downloaded from Server[2], etc.  They must be relative URLs,
    i.e., not start with "/".
    * Files: This variable defines the files that exist in the Server's
    file system. The Files variable is a list of lists of WgetFile objects.
    This means that File[0] is a list of WgetFile objects that lie on Server[0],
    File[1] a list of files on Server[1] and so on.
    * Existing_Files: This is a list of files that already exist in the
    directory from which Wget is invoked.
    * ExpectedReturnCode: The Exit Code expected to be returned by Wget after
    the test.
    * ExpectedDownloadedFiles: A list of files that are expected in the local
    directory after Wget has finished executing. This does not include the files
    already existing before Wget was launched and must be mentioned again.
    * Request_List: An unordered list of Requests that each server must receive.
    This too is a list of lists and follows the same convention as others above.

Both, the HTTPTest and FTPTest modules have the same prototype:
{
    pre_hook,
    test_options,
    post_hook,
    protocols
}
the three hooks should be Python dict objects and protocols should be a list of
protocols, like [HTTP, HTTPS].

Valid File Rules:
================================================================================

This section lists the currently supported File Rules and their structure.

    * Authentication: Used when a File must require Authorization for access.
    The value for this key is the following dictionary:
    |-->Type        :   Basic|Digest|Both|Both_inline
    |-->User        :   <Username>
    --->Pass        :   <Password>

    * ExpectHeader  : The following Headers MUST exist in every Request for the
    File. The value for this key is a dictionary object where each header is
    represented as:
    |-->Header Name :   <Header Data>

    * RejectHeader  : This list of Headers must NEVER occur in a request. It
    uses the same value format as ExpectHeader.

    * SendHeader    : This list of Headers will be sent in EVERY response to a
    request for the respective file. It follows the same value format as
    ExpectHeader. Additionally you can specify a list of strings as <Header Data>
    if you want the header repeated with multiple values.

    * Response      : The HTTP Response Code to send to a request for this File.
    The value is an Integer that represents a valid HTTP Response Code.

Pre Test Hooks:
================================================================================

The Pre-Test Hooks are executed just after starting the server and just before
spawning an instance of the server. These are usually used for setting up the
Test Environment and Server Rules. The currently supported Pre-Test Hooks are:

    * ServerFiles   : A list of WgetFile objects that must exist on the Server
    * LocalFiles    : A list of WgetFile objects that exist locally on disk
    before Wget is executed.

Since pre_test is a dictionary, one may not assume that the hooks will be
executed in the same order as they are defined.

Test Options:
================================================================================

The test_options dictionary defines the commands to be used when the Test is
executed. The currently supported options are:

    * Urls          : A list of the filenames that Wget must attempt to
    download. The complete URL will be created and passed to Wget
    automatically. (alias URLs)
    * WgetCommands  : A string consisting of the various commandline switches
    sent to Wget upon invocation. Any data placed between {{ }} in this string
    will be replaced with the contents of self.<data> before being passed to
    Wget. This is particularly useful for getting the hostname and port for a
    file. While all Download URL's are passed to Urls, a notable exception is
    when in-url authentication is used. In such a case, the URL is specified in
    the WgetCommands string.
    * EnvironmentVariables: A dictionary with key-value items, which will be
    defined as environment variables during the execution of wget command in
    test.

Post-Test Hooks:
================================================================================

These hooks are executed as soon as the call to Wget returns. The post-test
hooks are usually used to run checks on the data, files downloaded, return code,
etc. The following hooks are currently supported:

    * ExpectedRetcode : This is an integer value of the ReturnCode with which
    Wget is expected to exit. (alias ExpectedRetCode)
    * ExpectedFiles   : This is a list of WgetFile objects of the files that
    must exist locally on disk in the Test directory.
    * FilesCrawled    : This requires a list of the Requests that the server is
    expected to receive. The order is un-important since it will vary on the
    parallel-wget branch. This hook is used in tests for Recursive mode to
    ensure that the website is traversed correctly.

Writing New Tests:
================================================================================

See Test-Proto.py for an example of how to write Test Case files. The
recommended method for writing new Test Case files is to copy Test-Proto.py and
modify it to ones needs.

In case you require any functionality that is not currently defined in List of
Rules defined above, you should implement a new class in the conf package. The
file name doesn't matter (though it's better to give it an appropriate name).
The new rule or hook class should be like this:
============================================
from conf import rule


@rule()
class MyNewRule:
    def __init__(self, rule_arg):
        self.rule_arg = rule_arg
        # your rule initialization code goes here
============================================
from conf import hook


@hook()
class MyNewHook:
    def __init__(self, hook_arg):
        self.hook_arg = hook_arg
        # your hook initialization code goes here

    def __call__(self, test_obj):
        # your hook code goes here
============================================

Once a new Test File is created, it must be added to the TESTS variable in
Makefile.am. This way the Test will be executed on running a 'make check'.
If a Test is expected to fail on the current master branch, then the Test should
also be added to the XFAIL_TESTS variable. This will allow expected failures to
pass through. If a test mentioned in the XFAIL_TESTS variable passes, it gets
red-flagged as a XPASS. Currently, tests expected to fail under valgrind are not
explicitly marked as XFAIL. Tests failing under valgrind must always be
considered a blocking error.

Work Remaining:
================================================================================

Some amount of work still remains to be done.
    * Errors in server-side checks need to be handled more explicitly
    * Support parallel-wget branch
        * Support to spawn multiple servers is already in place. Need to handle
        multiple requests to a server simultaneously. Use THreading MixIn.
    * SSL Tests. Use xyne's HTTPS server implementation
    * Complete support for FTP Tests
    * IRI Support. This shouldn't require much effort

Requirements:
================================================================================

1. Python   >= 3.0
2. Automake >= 1.11