Bug 1366071 - Add check in talos tp6 to ensure mitmproxy certificate was installed successfully; r=jmaher
MozReview-Commit-ID: 8wRtSSQ5SEp
--- a/testing/mozharness/mozharness/mozilla/firefox/autoconfig.py
+++ b/testing/mozharness/mozharness/mozilla/firefox/autoconfig.py
@@ -26,16 +26,25 @@ def write_autoconfig_files(fx_install_di
autoconfig_contents - autoconfig.js content to refer to .cfg gile
'''
with open(_cfg_file_path(fx_install_dir), 'w') as fd:
fd.write(cfg_contents)
with open(_autoconfig_path(fx_install_dir), 'w') as fd:
fd.write(autoconfig_contents)
+def read_autoconfig_file(fx_install_dir):
+ ''' Read autoconfig file that modifies Firefox startup
+
+ fx_install_dir - path to Firefox installation
+ '''
+ with open(_cfg_file_path(fx_install_dir), 'r') as fd:
+ return fd.read()
+
+
def _autoconfig_path(fx_install_dir):
platform = platform_name()
if platform in ('win32', 'win64'):
return os.path.join(fx_install_dir,
'defaults', 'pref', 'autoconfig.js')
elif platform in ('linux', 'linux64'):
return os.path.join(fx_install_dir,
'defaults/pref/autoconfig.js')
--- a/testing/talos/talos/mitmproxy/mitmproxy.py
+++ b/testing/talos/talos/mitmproxy/mitmproxy.py
@@ -66,35 +66,48 @@ def _read_certificate(certificate_path):
''' Return the certificate's hash from the certificate file.'''
# NOTE: mitmproxy's certificates do not exist until one of its binaries
# has been executed once on the host
with open(certificate_path, 'r') as fd:
contents = fd.read()
return ''.join(contents.splitlines()[1:-1])
-def is_mitmproxy_cert_installed():
+def is_mitmproxy_cert_installed(browser_install):
"""Verify mitmxproy CA cert was added to Firefox"""
- # TODO: Bug 1366071
+ from mozharness.mozilla.firefox.autoconfig import read_autoconfig_file
+ try:
+ # read autoconfig file, confirm mitmproxy cert is in there
+ certificate = _read_certificate(DEFAULT_CERT_PATH)
+ contents = read_autoconfig_file(browser_install)
+ if (MITMPROXY_SETTINGS % {'cert': certificate}) in contents:
+ LOG.info("Verified mitmproxy CA certificate is installed in Firefox")
+ else:
+ LOG.info("Firefox autoconfig file contents:")
+ LOG.info(contents)
+ return False
+ except:
+ LOG.info("Failed to read Firefox autoconfig file, when verifying CA certificate install")
+ return False
return True
def install_mitmproxy_cert(mitmproxy_proc, browser_path, scripts_path):
"""Install the CA certificate generated by mitmproxy, into Firefox"""
LOG.info("Installing mitmxproxy CA certficate into Firefox")
# browser_path is exe, we want install dir
browser_install = os.path.dirname(browser_path)
# on macosx we need to remove the last folders 'Content/MacOS'
if mozinfo.os == 'mac':
browser_install = browser_install[:-14]
LOG.info('Calling configure_mitmproxy with browser folder: %s' % browser_install)
configure_mitmproxy(browser_install, scripts_path)
# cannot continue if failed to add CA cert to Firefox, need to check
- if not is_mitmproxy_cert_installed():
+ if not is_mitmproxy_cert_installed(browser_install):
LOG.error('Aborting: failed to install mitmproxy CA cert into Firefox')
stop_mitmproxy_playback(mitmproxy_proc)
sys.exit()
def start_mitmproxy_playback(mitmdump_path,
mitmproxy_recording_path,
mitmproxy_recordings_list,