From: Bob Halley Date: Thu, 18 Jun 2020 16:11:16 +0000 (-0700) Subject: further improve entropy coverage X-Git-Tag: v2.0.0rc1~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=861468e8a11b6269c1a4446f331857795d598e4b;p=thirdparty%2Fdnspython.git further improve entropy coverage --- diff --git a/dns/entropy.py b/dns/entropy.py index fd848418..086bba78 100644 --- a/dns/entropy.py +++ b/dns/entropy.py @@ -113,7 +113,7 @@ pool = EntropyPool() try: system_random = random.SystemRandom() -except Exception: +except Exception: # pragma: no cover system_random = None def random_16(): diff --git a/tests/test_entropy.py b/tests/test_entropy.py index 061f0770..828bb685 100644 --- a/tests/test_entropy.py +++ b/tests/test_entropy.py @@ -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)