This is an automated email from the ASF dual-hosted git repository. brondsem pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/allura.git
The following commit(s) were added to refs/heads/master by this push: new 471b602 better exception handling inside function and added basic test 471b602 is described below commit 471b602c647e84f2563cf0a61eb148e64f7c5bea Author: Guillermo Cruz <guillermo.c...@slashdotmedia.com> AuthorDate: Tue Oct 5 15:13:37 2021 -0600 better exception handling inside function and added basic test --- Allura/allura/lib/security.py | 2 +- Allura/allura/tests/test_security.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Allura/allura/lib/security.py b/Allura/allura/lib/security.py index 4ff62f7..7f852d2 100644 --- a/Allura/allura/lib/security.py +++ b/Allura/allura/lib/security.py @@ -579,7 +579,7 @@ class HIBPClient(object): result = cls.scan_response(resp, sha_1) except Exception as ex: - six.reraise(HIBPClientError, ex, sys.exc_info()[2]) + raise HIBPClientError from ex if result: raise HIBPCompromisedCredentials(result, sha_1_first_5) diff --git a/Allura/allura/tests/test_security.py b/Allura/allura/tests/test_security.py index c4cc7e8..dc890b3 100644 --- a/Allura/allura/tests/test_security.py +++ b/Allura/allura/tests/test_security.py @@ -18,7 +18,7 @@ from __future__ import unicode_literals from __future__ import absolute_import from tg import tmpl_context as c -from alluratest.tools import assert_equal +from alluratest.tools import assert_equal, assert_raises from ming.odm import ThreadLocalODMSession from allura.tests import decorators as td @@ -27,7 +27,9 @@ from allura.tests import TestController from allura.lib.security import Credentials, all_allowed, has_access from allura import model as M from forgewiki import model as WM - +from allura.lib.security import HIBPClientError, HIBPClient +from mock import Mock, patch +from requests.exceptions import Timeout def _allow(obj, role, perm): obj.acl.insert(0, M.ACE.allow(role._id, perm)) @@ -47,6 +49,12 @@ def _add_to_group(user, role): Credentials.get().clear() +@patch('allura.lib.security.requests.get', side_effect=Timeout()) +def test_check_breached_password(r_get): + with assert_raises(HIBPClientError): + HIBPClient.check_breached_password('qwerty') + + class TestSecurity(TestController): validate_skip = True