Merge "Mask passwords when logging messages"
This commit is contained in:
commit
b02dd25655
@ -18,6 +18,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
|
from oslo_utils import strutils
|
||||||
|
|
||||||
from oslo_messaging.notify import notifier
|
from oslo_messaging.notify import notifier
|
||||||
|
|
||||||
@ -38,4 +39,4 @@ class LogDriver(notifier._Driver):
|
|||||||
message['event_type']))
|
message['event_type']))
|
||||||
method = getattr(logger, priority.lower(), None)
|
method = getattr(logger, priority.lower(), None)
|
||||||
if method:
|
if method:
|
||||||
method(jsonutils.dumps(message))
|
method(strutils.mask_password(jsonutils.dumps(message)))
|
||||||
|
@ -20,6 +20,7 @@ import uuid
|
|||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
|
from oslo_utils import strutils
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
from stevedore import dispatch
|
from stevedore import dispatch
|
||||||
from stevedore import extension
|
from stevedore import extension
|
||||||
@ -317,6 +318,22 @@ class TestLogNotifier(test_utils.BaseTestCase):
|
|||||||
msg = {'event_type': 'foo'}
|
msg = {'event_type': 'foo'}
|
||||||
driver.notify(None, msg, "sample", None)
|
driver.notify(None, msg, "sample", None)
|
||||||
|
|
||||||
|
def test_mask_passwords(self):
|
||||||
|
# Ensure that passwords are masked with notifications
|
||||||
|
driver = _impl_log.LogDriver(None, None, None)
|
||||||
|
logger = mock.MagicMock()
|
||||||
|
logger.info = mock.MagicMock()
|
||||||
|
message = {'password': 'passw0rd', 'event_type': 'foo'}
|
||||||
|
json_str = jsonutils.dumps(message)
|
||||||
|
mask_str = strutils.mask_password(json_str)
|
||||||
|
|
||||||
|
|
||||||
|
with mock.patch.object(logging, 'getLogger') as gl:
|
||||||
|
gl.return_value = logger
|
||||||
|
driver.notify(None, message, 'info', 0)
|
||||||
|
|
||||||
|
logger.info.assert_called_once_with(mask_str)
|
||||||
|
|
||||||
|
|
||||||
class TestRoutingNotifier(test_utils.BaseTestCase):
|
class TestRoutingNotifier(test_utils.BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user