]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
further improve entropy coverage
authorBob Halley <halley@dnspython.org>
Thu, 18 Jun 2020 16:11:16 +0000 (09:11 -0700)
committerBob Halley <halley@dnspython.org>
Thu, 18 Jun 2020 16:11:16 +0000 (09:11 -0700)
dns/entropy.py
tests/test_entropy.py

index fd8484189b3c523c394b70b335fc6010bec2f3a7..086bba787d4d2466f714b7400591b1b8f52c192a 100644 (file)
@@ -113,7 +113,7 @@ pool = EntropyPool()
 
 try:
     system_random = random.SystemRandom()
-except Exception:
+except Exception:  # pragma: no cover
     system_random = None
 
 def random_16():
index 061f0770e7cc68426aea36ebe445df51b5004d69..828bb68549c753f84320512f7d8f13813e1d9182 100644 (file)
@@ -37,3 +37,19 @@ class EntropyTestCase(unittest.TestCase):
         self.assertTrue(0 <= v <= 65535)
         v = dns.entropy.between(10, 50)
         self.assertTrue(10 <= v <= 50)
+
+
+class EntropyForcePoolTestCase(unittest.TestCase):
+
+    def setUp(self):
+        self.saved_system_random = dns.entropy.system_random
+        dns.entropy.system_random = None
+
+    def tearDown(self):
+        dns.entropy.system_random = self.saved_system_random
+
+    def test_functions(self):
+        v = dns.entropy.random_16()
+        self.assertTrue(0 <= v <= 65535)
+        v = dns.entropy.between(10, 50)
+        self.assertTrue(10 <= v <= 50)