diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ae532223..ff164f9b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,6 +21,7 @@ jobs: matrix: os: [ubuntu-latest, macos-latest, windows-latest] python-version: [3.6, 3.7, 3.8, 3.9, "3.10.0-rc.2"] + pyopenssl: [0, 1] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 @@ -33,8 +34,12 @@ jobs: python -m pip install --upgrade pip wheel python -m pip install --upgrade '.[dev]' python -m pytest --verbose ./httpie ./tests + env: + HTTPIE_TEST_WITH_PYOPENSSL: ${{ matrix.pyopenssl }} - name: Linux & Mac setup if: matrix.os != 'windows-latest' run: | make install make test + env: + HTTPIE_TEST_WITH_PYOPENSSL: ${{ matrix.pyopenssl }} diff --git a/setup.py b/setup.py index acde80a0..22c14212 100644 --- a/setup.py +++ b/setup.py @@ -19,6 +19,7 @@ dev_require = [ 'flake8-deprecated', 'flake8-mutable', 'flake8-tuple', + 'pyopenssl', 'pytest-cov', 'twine', 'wheel', diff --git a/tests/conftest.py b/tests/conftest.py index ff79ed17..a65df162 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,6 @@ +import os import socket + import pytest from pytest_httpbin import certs @@ -41,3 +43,19 @@ def httpbin_with_chunked_support(_httpbin_with_chunked_support_available): if _httpbin_with_chunked_support_available: return HTTPBIN_WITH_CHUNKED_SUPPORT pytest.skip(f'{HTTPBIN_WITH_CHUNKED_SUPPORT_DOMAIN} not resolvable') + + +@pytest.fixture(autouse=True, scope='session') +def pyopenssl_inject(): + """ + Injects `pyOpenSSL` module to make sure `requests` will use it. + + """ + if os.getenv('HTTPIE_TEST_WITH_PYOPENSSL', '0') == '1': + try: + import urllib3.contrib.pyopenssl + urllib3.contrib.pyopenssl.inject_into_urllib3() + except ModuleNotFoundError: + pytest.fail('Missing "pyopenssl" module.') + + yield diff --git a/tests/test_ssl.py b/tests/test_ssl.py index 7b3807d9..e7192448 100644 --- a/tests/test_ssl.py +++ b/tests/test_ssl.py @@ -1,11 +1,14 @@ +import os +import ssl + import pytest import pytest_httpbin.certs import requests.exceptions -import ssl import urllib3 from httpie.ssl import AVAILABLE_SSL_VERSION_ARG_MAPPING, DEFAULT_SSL_CIPHERS from httpie.status import ExitStatus + from .utils import HTTP_OK, TESTS_ROOT, http @@ -17,6 +20,7 @@ try: ssl_errors = ( requests.exceptions.SSLError, OpenSSL.SSL.Error, + ValueError, # TODO: Remove with OSS-65 ) except ImportError: ssl_errors = ( @@ -54,6 +58,8 @@ def test_ssl_version(httpbin_secure, ssl_version): root = root.__context__ if isinstance(root, ssl.SSLError) and root.reason == "TLSV1_ALERT_PROTOCOL_VERSION": pytest.skip(f'Unsupported TLS version: {ssl_version}') + elif 'No such protocol' in str(e): # TODO: Remove with OSS-65 + pytest.skip(f'Unsupported TLS version: {ssl_version}') else: raise @@ -149,3 +155,13 @@ def test_ciphers_none_can_be_selected(httpbin_secure): # # http: error: Error: [('SSL routines', '(UNKNOWN)SSL_internal', 'no cipher match')] assert 'cipher' in r.stderr + + +def test_pyopenssl_presence(): + using_pyopenssl = os.getenv('HTTPIE_TEST_WITH_PYOPENSSL', '0') + if using_pyopenssl == '0': + assert not urllib3.util.ssl_.IS_PYOPENSSL + assert not urllib3.util.IS_PYOPENSSL + else: + assert urllib3.util.ssl_.IS_PYOPENSSL + assert urllib3.util.IS_PYOPENSSL