-
Notifications
You must be signed in to change notification settings - Fork 81
/
test_cli.py
92 lines (74 loc) · 3.1 KB
/
test_cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
import sys
import tempfile
import unittest
from pshtt.models import Domain, Endpoint
from pshtt import pshtt as _pshtt
from pshtt.cli import to_csv
class FakeSuffixList(object):
def get_public_suffix(self, hostname, *args, **kwargs):
return hostname
# Artificially setup the the preload and suffix lists
# This should be irrelevant after #126 is decided upon / merged
_pshtt.suffix_list = FakeSuffixList()
_pshtt.preload_list = []
_pshtt.preload_pending = []
class TestToCSV(unittest.TestCase):
@classmethod
def setUpClass(cls):
base_domain = 'example.com'
domain = Domain(base_domain)
domain.http = Endpoint("http", "root", base_domain)
domain.httpwww = Endpoint("http", "www", base_domain)
domain.https = Endpoint("https", "root", base_domain)
domain.httpswww = Endpoint("https", "www", base_domain)
cls.results = _pshtt.result_for(domain)
cls.temp_filename = os.path.join(tempfile.gettempdir(), 'results.csv')
@unittest.skipIf(sys.version_info[0] < 3, 'Python 3 test only')
def test_no_results(self):
to_csv([], self.temp_filename)
with open(self.temp_filename) as fh:
content = fh.read()
expected = ','.join(_pshtt.HEADERS) + '\n'
self.assertEqual(content, expected)
@unittest.skipIf(sys.version_info[0] < 3, 'Python 3 test only')
def test_single_result(self):
to_csv([self.results], self.temp_filename)
with open(self.temp_filename) as fh:
content = fh.read()
domain_data = [
('Domain', 'example.com'),
('Base Domain', 'example.com'),
('Canonical URL', 'http://example.com'),
('Live', 'False'),
('Redirect', 'False'),
('Redirect To', ''),
('Valid HTTPS', 'False'),
('Defaults to HTTPS', 'False'),
('Downgrades HTTPS', 'False'),
('Strictly Forces HTTPS', 'False'),
('HTTPS Bad Chain', 'False'),
('HTTPS Bad Hostname', 'False'),
('HTTPS Expired Cert', 'False'),
('HTTPS Self Signed Cert', 'False'),
('HSTS', 'False'),
('HSTS Header', ''),
('HSTS Max Age', ''),
('HSTS Entire Domain', 'False'),
('HSTS Preload Ready', 'False'),
('HSTS Preload Pending', 'False'),
('HSTS Preloaded', 'False'),
('Base Domain HSTS Preloaded', 'False'),
('Domain Supports HTTPS', 'False'),
('Domain Enforces HTTPS', 'False'),
('Domain Uses Strong HSTS', 'False'),
('Unknown Error', 'False'),
]
header = ','.join(t[0] for t in domain_data)
values = ','.join(t[1] for t in domain_data)
expected = header + '\n' + values + '\n'
self.assertEqual(content, expected)
# Sanity check that this hard coded data has the same headers as defined
# in the package. This should never fail, as the above assert should
# catch any changes in the header columns.
self.assertEqual(header, ','.join(_pshtt.HEADERS))