| 1 |
#!/usr/bin/env python3 |
| 2 |
from sys import exit |
| 3 |
from test.http_test import HTTPTest |
| 4 |
from misc.wget_file import WgetFile |
| 5 |
|
| 6 |
""" |
| 7 |
This test ensures Wget uses credentials from .netrc for Basic Authorization Negotiation. |
| 8 |
In this case we test that .netrc credentials are used in case no user |
| 9 |
login and no password is given on the command line. |
| 10 |
Also, we ensure that Wget saves the host after a successful auth and |
| 11 |
doesn't wait for a challenge the second time. |
| 12 |
""" |
| 13 |
############# File Definitions ############################################### |
| 14 |
File1 = "I am an invisible man." |
| 15 |
File2 = "I too am an invisible man." |
| 16 |
|
| 17 |
User = "Sauron" |
| 18 |
Password = "TheEye" |
| 19 |
|
| 20 |
File1_rules = { |
| 21 |
"Authentication" : { |
| 22 |
"Type" : "Basic", |
| 23 |
"User" : User, |
| 24 |
"Pass" : Password |
| 25 |
} |
| 26 |
} |
| 27 |
File2_rules = { |
| 28 |
"ExpectHeader" : { |
| 29 |
"Authorization" : "Basic U2F1cm9uOlRoZUV5ZQ==" |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
Netrc = "machine localhost\n\tlogin {0}\n\tpassword {1}".format(User, Password) |
| 34 |
|
| 35 |
A_File = WgetFile ("File1", File1, rules=File1_rules) |
| 36 |
B_File = WgetFile ("File2", File2, rules=File2_rules) |
| 37 |
Netrc_File = WgetFile (".netrc", Netrc) |
| 38 |
|
| 39 |
WGET_URLS = [["File1", "File2"]] |
| 40 |
|
| 41 |
Files = [[A_File, B_File]] |
| 42 |
LocalFiles = [Netrc_File] |
| 43 |
|
| 44 |
ExpectedReturnCode = 0 |
| 45 |
ExpectedDownloadedFiles = [A_File, B_File, Netrc_File] |
| 46 |
|
| 47 |
################ Pre and Post Test Hooks ##################################### |
| 48 |
pre_test = { |
| 49 |
"ServerFiles" : Files, |
| 50 |
"LocalFiles" : LocalFiles |
| 51 |
} |
| 52 |
test_options = { |
| 53 |
"Urls" : WGET_URLS |
| 54 |
} |
| 55 |
post_test = { |
| 56 |
"ExpectedFiles" : ExpectedDownloadedFiles, |
| 57 |
"ExpectedRetcode" : ExpectedReturnCode |
| 58 |
} |
| 59 |
|
| 60 |
err = HTTPTest ( |
| 61 |
pre_hook=pre_test, |
| 62 |
test_params=test_options, |
| 63 |
post_hook=post_test |
| 64 |
).begin () |
| 65 |
|
| 66 |
exit (err) |