summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2023-03-16 01:05:33 -0400
committerGitHub <noreply@github.com>2023-03-16 13:05:33 +0800
commit8882c3c88d082f29b66fd2e72cb92273da96c427 (patch)
treec82d222726a8b58aa2834649e2d65a90a6d3da67 /tests
parentd6866c82b48283ee773054ba95b76b5f315ee556 (diff)
downloadcryptography-8882c3c88d082f29b66fd2e72cb92273da96c427.tar.gz
Support handling OpenSSL errors from Rust code (#8530)
Diffstat (limited to 'tests')
-rw-r--r--tests/hazmat/bindings/test_openssl.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py
index 0721fc09a..c80753bd0 100644
--- a/tests/hazmat/bindings/test_openssl.py
+++ b/tests/hazmat/bindings/test_openssl.py
@@ -5,6 +5,7 @@
import pytest
from cryptography.exceptions import InternalError
+from cryptography.hazmat.bindings._rust import openssl as rust_openssl
from cryptography.hazmat.bindings.openssl.binding import (
Binding,
_consume_errors,
@@ -95,7 +96,7 @@ class TestOpenSSL:
-1,
)
b._register_osrandom_engine()
- assert _consume_errors(b.lib) == []
+ assert _consume_errors() == []
def test_version_mismatch(self):
with pytest.raises(ImportError):
@@ -106,3 +107,26 @@ class TestOpenSSL:
_legacy_provider_error(False)
_legacy_provider_error(True)
+
+ def test_rust_internal_error(self):
+ with pytest.raises(InternalError) as exc_info:
+ rust_openssl.raise_openssl_error()
+
+ assert len(exc_info.value.err_code) == 0
+
+ b = Binding()
+ b.lib.ERR_put_error(
+ b.lib.ERR_LIB_EVP,
+ b.lib.EVP_F_EVP_ENCRYPTFINAL_EX,
+ b.lib.EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH,
+ b"",
+ -1,
+ )
+ with pytest.raises(InternalError) as exc_info:
+ rust_openssl.raise_openssl_error()
+
+ error = exc_info.value.err_code[0]
+ assert error.lib == b.lib.ERR_LIB_EVP
+ assert error.reason == b.lib.EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH
+ if not b.lib.CRYPTOGRAPHY_IS_BORINGSSL:
+ assert b"data not multiple of block length" in error.reason_text