diff options
author | Georg Brandl <georg@python.org> | 2012-02-20 18:54:16 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2012-02-20 18:54:16 (GMT) |
commit | 2daf6ae2495c862adf8bc717bfe9964081ea0b10 (patch) | |
tree | ebd7efe668e4f7842c6d51bdbde47b00f92a57db /Lib/test/test_descr.py | |
parent | ec1712a1662282c909b4cd4cc0c7486646bc9246 (diff) | |
download | cpython-2daf6ae2495c862adf8bc717bfe9964081ea0b10.zip cpython-2daf6ae2495c862adf8bc717bfe9964081ea0b10.tar.gz cpython-2daf6ae2495c862adf8bc717bfe9964081ea0b10.tar.bz2 |
Issue #13703: add a way to randomize the hash values of basic types (str, bytes, datetime)
in order to make algorithmic complexity attacks on (e.g.) web apps much more complicated.
The environment variable PYTHONHASHSEED and the new command line flag -R control this
behavior.
Diffstat (limited to 'Lib/test/test_descr.py')
-rw-r--r-- | Lib/test/test_descr.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 0ce85f0..077f5da 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -4300,8 +4300,18 @@ class DictProxyTests(unittest.TestCase): def test_repr(self): # Testing dict_proxy.__repr__ + def sorted_dict_repr(repr_): + # Given the repr of a dict, sort the keys + assert repr_.startswith('{') + assert repr_.endswith('}') + kvs = repr_[1:-1].split(', ') + return '{' + ', '.join(sorted(kvs)) + '}' dict_ = {k: v for k, v in self.C.__dict__.items()} - self.assertEqual(repr(self.C.__dict__), 'dict_proxy({!r})'.format(dict_)) + repr_ = repr(self.C.__dict__) + self.assert_(repr_.startswith('dict_proxy(')) + self.assert_(repr_.endswith(')')) + self.assertEqual(sorted_dict_repr(repr_[len('dict_proxy('):-len(')')]), + sorted_dict_repr('{!r}'.format(dict_))) class PTypesLongInitTest(unittest.TestCase): |