summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2021-05-02 07:47:45 (GMT)
committerGitHub <noreply@github.com>2021-05-02 07:47:45 (GMT)
commit91554e4c5ca3c762998296522f854a7166ba84f0 (patch)
treeaa6e08eedef59c4a4d5c750ed60e5d463f05a4ad /Lib/test
parentfd0bc7e7f4f2c7de98a1ebc7ad1ef65b8f8f7ad6 (diff)
downloadcpython-91554e4c5ca3c762998296522f854a7166ba84f0.zip
cpython-91554e4c5ca3c762998296522f854a7166ba84f0.tar.gz
cpython-91554e4c5ca3c762998296522f854a7166ba84f0.tar.bz2
bpo-43908: Mark ssl, hash, and hmac types as immutable (GH-25792)
Signed-off-by: Christian Heimes <christian@python.org>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_hashlib.py9
-rw-r--r--Lib/test/test_hmac.py3
-rw-r--r--Lib/test/test_ssl.py19
3 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
index a515d3a..ad2ed69 100644
--- a/Lib/test/test_hashlib.py
+++ b/Lib/test/test_hashlib.py
@@ -926,6 +926,15 @@ class HashLibTestCase(unittest.TestCase):
):
HASHXOF()
+ def test_readonly_types(self):
+ for algorithm, constructors in self.constructors_to_test.items():
+ # all other types have DISALLOW_INSTANTIATION
+ for constructor in constructors:
+ hash_type = type(constructor())
+ with self.subTest(hash_type=hash_type):
+ with self.assertRaisesRegex(TypeError, "immutable type"):
+ hash_type.value = False
+
class KDFTests(unittest.TestCase):
diff --git a/Lib/test/test_hmac.py b/Lib/test/test_hmac.py
index 22d74e9..964acd0 100644
--- a/Lib/test/test_hmac.py
+++ b/Lib/test/test_hmac.py
@@ -444,6 +444,9 @@ class ConstructorTestCase(unittest.TestCase):
):
C_HMAC()
+ with self.assertRaisesRegex(TypeError, "immutable type"):
+ C_HMAC.value = None
+
@unittest.skipUnless(sha256_module is not None, 'need _sha256')
def test_with_sha256_module(self):
h = hmac.HMAC(b"key", b"hash this!", digestmod=sha256_module.sha256)
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
index f2b26c4..acb64f1 100644
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -345,6 +345,25 @@ class BasicSocketTests(unittest.TestCase):
ssl.OP_NO_TLSv1_2
self.assertEqual(ssl.PROTOCOL_TLS, ssl.PROTOCOL_SSLv23)
+ def test_ssl_types(self):
+ ssl_types = [
+ _ssl._SSLContext,
+ _ssl._SSLSocket,
+ _ssl.MemoryBIO,
+ _ssl.Certificate,
+ _ssl.SSLSession,
+ _ssl.SSLError,
+ ]
+ for ssl_type in ssl_types:
+ with self.subTest(ssl_type=ssl_type):
+ with self.assertRaisesRegex(TypeError, "immutable type"):
+ ssl_type.value = None
+ with self.assertRaisesRegex(
+ TypeError,
+ "cannot create '_ssl.Certificate' instances"
+ ):
+ _ssl.Certificate()
+
def test_private_init(self):
with self.assertRaisesRegex(TypeError, "public constructor"):
with socket.socket() as s: