OXIESEC PANEL
- Current Dir:
/
/
opt
/
gsutil
/
third_party
/
urllib3
/
test
/
contrib
Server IP: 2a02:4780:11:1594:0:ef5:22d7:a
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
06/17/2024 08:00:39 AM
rwxr-xr-x
📄
__init__.py
0 bytes
06/17/2024 08:00:39 AM
rw-r--r--
📄
duplicate_san.pem
1.23 KB
06/17/2024 08:00:39 AM
rw-r--r--
📁
emscripten
-
06/17/2024 08:00:39 AM
rwxr-xr-x
📄
test_pyopenssl.py
2.95 KB
06/17/2024 08:00:39 AM
rw-r--r--
📄
test_pyopenssl_dependencies.py
1.94 KB
06/17/2024 08:00:39 AM
rw-r--r--
📄
test_socks.py
25.32 KB
06/17/2024 08:00:39 AM
rw-r--r--
Editing: test_pyopenssl_dependencies.py
Close
from __future__ import annotations from unittest.mock import Mock, patch import pytest try: from urllib3.contrib.pyopenssl import extract_from_urllib3, inject_into_urllib3 except ImportError: pass def setup_module() -> None: try: from urllib3.contrib.pyopenssl import inject_into_urllib3 inject_into_urllib3() except ImportError as e: pytest.skip(f"Could not import PyOpenSSL: {e!r}") def teardown_module() -> None: try: from urllib3.contrib.pyopenssl import extract_from_urllib3 extract_from_urllib3() except ImportError: pass class TestPyOpenSSLInjection: """ Tests for error handling in pyopenssl's 'inject_into urllib3' """ def test_inject_validate_fail_cryptography(self) -> None: """ Injection should not be supported if cryptography is too old. """ try: with patch("cryptography.x509.extensions.Extensions") as mock: del mock.get_extension_for_class with pytest.raises(ImportError): inject_into_urllib3() finally: # `inject_into_urllib3` is not supposed to succeed. # If it does, this test should fail, but we need to # clean up so that subsequent tests are unaffected. extract_from_urllib3() def test_inject_validate_fail_pyopenssl(self) -> None: """ Injection should not be supported if pyOpenSSL is too old. """ try: return_val = Mock() del return_val._x509 with patch("OpenSSL.crypto.X509", return_value=return_val): with pytest.raises(ImportError): inject_into_urllib3() finally: # `inject_into_urllib3` is not supposed to succeed. # If it does, this test should fail, but we need to # clean up so that subsequent tests are unaffected. extract_from_urllib3()