Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hardcoded paths to macOS frameworks for Big Sur compatibility. #1905

Merged
merged 9 commits into from
Jul 19, 2020
28 changes: 14 additions & 14 deletions src/urllib3/contrib/_securetransport/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from __future__ import absolute_import

import platform
from ctypes.util import find_library
from ctypes import (
c_void_p,
c_int32,
Expand All @@ -47,26 +46,27 @@
from ctypes import CDLL, POINTER, CFUNCTYPE


security_path = find_library("Security")
sheagcraig marked this conversation as resolved.
Show resolved Hide resolved
if not security_path:
raise ImportError("The library Security could not be found")


core_foundation_path = find_library("CoreFoundation")
if not core_foundation_path:
raise ImportError("The library CoreFoundation could not be found")


version = platform.mac_ver()[0]
pquentin marked this conversation as resolved.
Show resolved Hide resolved
version_info = tuple(map(int, version.split(".")))
if version_info < (10, 8):
if platform.system() != "Darwin" or version_info < (10, 8):
sheagcraig marked this conversation as resolved.
Show resolved Hide resolved
raise OSError(
"Only OS X 10.8 and newer are supported, not %s.%s"
% (version_info[0], version_info[1])
)

Security = CDLL(security_path, use_errno=True)
CoreFoundation = CDLL(core_foundation_path, use_errno=True)
security_path = "/System/Library/Frameworks/Security.framework/Security"
core_foundation_path = (
"/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation"
)
try:
Security = CDLL(security_path, use_errno=True)
except OSError:
raise ImportError("The library {} failed to load.".format(security_path))
try:
CoreFoundation = CDLL(core_foundation_path, use_errno=True)
except OSError:
raise ImportError("The library {} failed to load.".format(core_foundation_path))


Boolean = c_bool
CFIndex = c_long
Expand Down
26 changes: 26 additions & 0 deletions test/contrib/test_securetransport_big_sur.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
import mock
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this test script now :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIth the changes to retain the pre-Big Sur behavior, do it still make sense to take the test out?



class TestSecureTransportBigSur(object):
"""
Tests for macOS Big Sur's dynamic linker
"""

@mock.patch("platform.mac_ver", return_value=("10.16", ("", "", ""), "x86_64"))
def test_import_current_version(self, mock_mac_ver):
try:
import urllib3.contrib.securetransport as securetransport

except ImportError:
securetransport = None
assert securetransport

@mock.patch("platform.mac_ver", return_value=("11.0", ("", "", ""), "x86_64"))
def test_import_future_version(self, mock_mac_ver):
try:
import urllib3.contrib.securetransport as securetransport

except ImportError:
securetransport = None
assert securetransport