Patchwork [1,of,4,V2] ssl: extract function that returns dummycert path on Apple python

login
register
mail settings
Submitter Yuya Nishihara
Date March 12, 2015, 3:41 p.m.
Message ID <7ed8cbb3b76b9e15940e.1426174914@mimosa>
Download mbox | patch
Permalink /patch/8021/
State Accepted
Commit 922e087ba158cead5ca55a9c3260c4777e963296
Headers show

Comments

Yuya Nishihara - March 12, 2015, 3:41 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1425475621 -32400
#      Wed Mar 04 22:27:01 2015 +0900
# Node ID 7ed8cbb3b76b9e15940e967d4620c2eac028fad1
# Parent  f29939bf06ff33ec50a1647f9048af25ee20a702
ssl: extract function that returns dummycert path on Apple python

This function will be the condition to switch DISABLEOSXDUMMYCERT in
test-https.t.

Patch

diff --git a/mercurial/sslutil.py b/mercurial/sslutil.py
--- a/mercurial/sslutil.py
+++ b/mercurial/sslutil.py
@@ -129,6 +129,13 @@  def _plainapplepython():
     return (exe.startswith('/usr/bin/python') or
             exe.startswith('/system/library/frameworks/python.framework/'))
 
+def _defaultcacerts():
+    if _plainapplepython():
+        dummycert = os.path.join(os.path.dirname(__file__), 'dummycert.pem')
+        if os.path.exists(dummycert):
+            return dummycert
+    return None
+
 def sslkwargs(ui, host):
     kws = {}
     hostfingerprint = ui.config('hostfingerprints', host)
@@ -139,9 +146,9 @@  def sslkwargs(ui, host):
         cacerts = util.expandpath(cacerts)
         if not os.path.exists(cacerts):
             raise util.Abort(_('could not find web.cacerts: %s') % cacerts)
-    elif cacerts is None and _plainapplepython():
-        dummycert = os.path.join(os.path.dirname(__file__), 'dummycert.pem')
-        if os.path.exists(dummycert):
+    elif cacerts is None:
+        dummycert = _defaultcacerts()
+        if dummycert:
             ui.debug('using %s to enable OS X system CA\n' % dummycert)
             ui.setconfig('web', 'cacerts', dummycert, 'dummy')
             cacerts = dummycert