Merge "indicate that sensitive messages can be disabled"
This commit is contained in:
commit
fa7812e3d4
@ -119,11 +119,14 @@ class PKITokenExpected(Error):
|
||||
|
||||
class SecurityError(Error):
|
||||
"""Avoids exposing details of security failures, unless in debug mode."""
|
||||
amendment = _('(Disable debug mode to suppress these details.)')
|
||||
|
||||
def _build_message(self, message, **kwargs):
|
||||
"""Only returns detailed messages in debug mode."""
|
||||
if CONF.debug:
|
||||
return message or self.message_format % kwargs
|
||||
return _('%(message)s %(amendment)s') % {
|
||||
'message': message or self.message_format % kwargs,
|
||||
'amendment': self.amendment}
|
||||
else:
|
||||
return self.message_format % kwargs
|
||||
|
||||
|
@ -133,7 +133,10 @@ class UnexpectedExceptionTestCase(ExceptionTestCase):
|
||||
|
||||
e = subclass(debug_info=self.exc_str)
|
||||
expected = subclass.debug_message_format % {'debug_info': self.exc_str}
|
||||
self.assertEqual(expected, six.text_type(e))
|
||||
translated_amendment = six.text_type(exception.SecurityError.amendment)
|
||||
self.assertEqual(
|
||||
expected + six.text_type(' ') + translated_amendment,
|
||||
six.text_type(e))
|
||||
|
||||
def test_unexpected_error_custom_message_no_debug(self):
|
||||
self.config_fixture.config(debug=False)
|
||||
@ -144,8 +147,10 @@ class UnexpectedExceptionTestCase(ExceptionTestCase):
|
||||
def test_unexpected_error_custom_message_debug(self):
|
||||
self.config_fixture.config(debug=True)
|
||||
e = exception.UnexpectedError(self.exc_str)
|
||||
self.assertEqual(self.exc_str,
|
||||
six.text_type(e))
|
||||
translated_amendment = six.text_type(exception.SecurityError.amendment)
|
||||
self.assertEqual(
|
||||
self.exc_str + six.text_type(' ') + translated_amendment,
|
||||
six.text_type(e))
|
||||
|
||||
|
||||
class SecurityErrorTestCase(ExceptionTestCase):
|
||||
|
Loading…
x
Reference in New Issue
Block a user