Debian Codegraph @

testenv/Test-pinnedpubkey-hash-https.py

raw
1 #!/usr/bin/env python3
2 from sys import exit
3 from test.http_test import HTTPTest
4 from test.base_test import HTTPS, SKIP_TEST
5 from misc.wget_file import WgetFile
6 import os
7
8 """
9 This test ensures that Wget can download files from HTTPS Servers
10 """
11 if os.getenv('SSL_TESTS') is None:
12 exit (SKIP_TEST)
13
14 ############# File Definitions ###############################################
15 File1 = "Would you like some Tea?"
16 File2 = "With lemon or cream?"
17 File3 = "Sure you're joking Mr. Feynman"
18
19 A_File = WgetFile ("File1", File1)
20 B_File = WgetFile ("File2", File2)
21 C_File = WgetFile ("File3", File3)
22
23 CERTDIR = os.path.abspath(os.path.join(os.getenv('srcdir', '.'), 'certs'))
24 CAFILE = CERTDIR + '/ca-cert.pem'
25 KEYFILE = CERTDIR + '/server-pubkey-sha256.base64'
26 with open(KEYFILE, 'r') as f:
27 KEY = f.read().replace('\n', '')
28 WGET_OPTIONS = "--pinnedpubkey=sha256//" + KEY + " --ca-certificate=" + CAFILE
29 WGET_URLS = [["File1", "File2"]]
30
31 Files = [[A_File, B_File]]
32 Existing_Files = [C_File]
33
34 Servers = [HTTPS]
35
36 ExpectedReturnCode = 0
37 ExpectedDownloadedFiles = [A_File, B_File, C_File]
38
39 ################ Pre and Post Test Hooks #####################################
40 pre_test = {
41 "ServerFiles" : Files,
42 "LocalFiles" : Existing_Files
43 }
44 test_options = {
45 "WgetCommands" : WGET_OPTIONS,
46 "Urls" : WGET_URLS
47 }
48 post_test = {
49 "ExpectedFiles" : ExpectedDownloadedFiles,
50 "ExpectedRetcode" : ExpectedReturnCode
51 }
52
53 err = HTTPTest (
54 pre_hook=pre_test,
55 test_params=test_options,
56 post_hook=post_test,
57 protocols=Servers
58 ).begin ()
59
60 exit (err)