Skip to content

Commit

Permalink
Moved cache list creation into its own function
Browse files Browse the repository at this point in the history
This begins work towards a more complete solution for #99, and allows
for the initialize function to be mocked / called separately when
working in tests.
  • Loading branch information
IanLee1521 committed Oct 23, 2017
1 parent 14f41a9 commit b48cb70
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions pshtt/pshtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ def is_hsts_preload_pending(domain):
"unknown".
"""
if preload_pending is None:
return None
initialize_caches()

return domain.domain in preload_pending

Expand All @@ -910,7 +910,7 @@ def is_hsts_preloaded(domain):
"unknown".
"""
if preload_list is None:
return None
initialize_caches()

return domain.domain in preload_list

Expand All @@ -929,7 +929,7 @@ def parent_domain_for(hostname):
If there is no suffix_list available, simply return the hostname
"""
if suffix_list is None:
return hostname
initialize_caches()

return suffix_list.get_public_suffix(hostname)

Expand Down Expand Up @@ -1140,6 +1140,19 @@ def csv_for(results, out_filename):
out_file.close()


def initialize_caches():
# Download HSTS preload list, caches locally.
global preload_list
preload_list = create_preload_list()

# Download HSTS pending preload list. Not cached.
global preload_pending
preload_pending = fetch_preload_pending()

global suffix_list
suffix_list = load_suffix_list()


def inspect_domains(domains, options):
# Override timeout, user agent, preload cache, default CA bundle
global TIMEOUT, USER_AGENT, PRELOAD_CACHE, WEB_CACHE, SUFFIX_CACHE, CA_FILE, STORE
Expand Down Expand Up @@ -1170,16 +1183,7 @@ def inspect_domains(domains, options):
# "Custom" Option from the sslyze output.
STORE = "Custom"

# Download HSTS preload list, caches locally.
global preload_list
preload_list = create_preload_list()

# Download HSTS pending preload list. Not cached.
global preload_pending
preload_pending = fetch_preload_pending()

global suffix_list
suffix_list = load_suffix_list()
initialize_caches()

# For every given domain, get inspect data.
results = []
Expand Down

0 comments on commit b48cb70

Please sign in to comment.