Commit f52c5472 authored by Gregory P. Smith's avatar Gregory P. Smith

Consistently raise a TypeError when a non str is passed to hashlib.new

regardless of which of the two implementations of new is used.
parent d41e5a95
...@@ -88,7 +88,7 @@ def __get_builtin_constructor(name): ...@@ -88,7 +88,7 @@ def __get_builtin_constructor(name):
except ImportError: except ImportError:
pass # no extension module, this hash is unsupported. pass # no extension module, this hash is unsupported.
raise ValueError('unsupported hash type %s' % name) raise ValueError('unsupported hash type ' + name)
def __get_openssl_constructor(name): def __get_openssl_constructor(name):
......
...@@ -111,12 +111,8 @@ class HashLibTestCase(unittest.TestCase): ...@@ -111,12 +111,8 @@ class HashLibTestCase(unittest.TestCase):
issubset(hashlib.algorithms_available)) issubset(hashlib.algorithms_available))
def test_unknown_hash(self): def test_unknown_hash(self):
try: self.assertRaises(ValueError, hashlib.new, 'spam spam spam spam spam')
hashlib.new('spam spam spam spam spam') self.assertRaises(TypeError, hashlib.new, 1)
except ValueError:
pass
else:
self.assertTrue(0 == "hashlib didn't reject bogus hash name")
def test_get_builtin_constructor(self): def test_get_builtin_constructor(self):
get_builtin_constructor = hashlib.__dict__[ get_builtin_constructor = hashlib.__dict__[
...@@ -135,6 +131,7 @@ class HashLibTestCase(unittest.TestCase): ...@@ -135,6 +131,7 @@ class HashLibTestCase(unittest.TestCase):
sys.modules['_md5'] = _md5 sys.modules['_md5'] = _md5
else: else:
del sys.modules['_md5'] del sys.modules['_md5']
self.assertRaises(TypeError, get_builtin_constructor, 3)
def test_hexdigest(self): def test_hexdigest(self):
for name in self.supported_hash_names: for name in self.supported_hash_names:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment