1#!/usr/bin/env python3
2from sys import exit
3from test.http_test import HTTPTest
4from misc.wget_file import WgetFile
5
6"""
7    This test ensures Wget's Basic Authorization Negotiation.
8    Also, we ensure that Wget saves the host after a successful auth and
9    doesn't wait for a challenge the second time.
10"""
11############# File Definitions ###############################################
12File1 = "I am an invisible man."
13File2 = "I too am an invisible man."
14
15File1_rules = {
16    "Authentication"    : {
17        "Type"          : "Basic",
18        "User"          : "Sauron",
19        "Pass"          : "TheEye"
20    }
21}
22File2_rules = {
23    "ExpectHeader"      : {
24        "Authorization" : "Basic U2F1cm9uOlRoZUV5ZQ=="
25    }
26}
27A_File = WgetFile ("File1", File1, rules=File1_rules)
28B_File = WgetFile ("File2", File2, rules=File2_rules)
29
30WGET_OPTIONS = "--user=Sauron --password=TheEye"
31WGET_URLS = [["File1", "File2"]]
32
33Files = [[A_File, B_File]]
34
35ExpectedReturnCode = 0
36ExpectedDownloadedFiles = [A_File, B_File]
37
38################ Pre and Post Test Hooks #####################################
39pre_test = {
40    "ServerFiles"       : Files
41}
42test_options = {
43    "WgetCommands"      : WGET_OPTIONS,
44    "Urls"              : WGET_URLS
45}
46post_test = {
47    "ExpectedFiles"     : ExpectedDownloadedFiles,
48    "ExpectedRetcode"   : ExpectedReturnCode
49}
50
51err = HTTPTest (
52                pre_hook=pre_test,
53                test_params=test_options,
54                post_hook=post_test
55).begin ()
56
57exit (err)
58