@mock.patch('st2common.logging.formatters.MASKED_ATTRIBUTES_BLACKLIST', MOCK_MASKED_ATTRIBUTES_BLACKLIST)
def test_format_blacklisted_attributes_are_masked(self):
    formatter = GelfLogFormatter()
    mock_message = 'test message 1'
    record = MockRecord()
    record.msg = mock_message
    record._blacklisted_1 = 'test value 1'
    record._blacklisted_2 = 'test value 2'
    record._blacklisted_3 = {'key1': 'val1', 'blacklisted_1': 'val2', 'key3': 'val3'}
    record._foo1 = 'bar'
    message = formatter.format(record=record)
    parsed = json.loads(message)
    self.assertEqual(parsed['_blacklisted_1'], MASKED_ATTRIBUTE_VALUE)
    self.assertEqual(parsed['_blacklisted_2'], MASKED_ATTRIBUTE_VALUE)
    self.assertEqual(parsed['_blacklisted_3']['key1'], 'val1')
    self.assertEqual(parsed['_blacklisted_3']['blacklisted_1'], MASKED_ATTRIBUTE_VALUE)
    self.assertEqual(parsed['_blacklisted_3']['key3'], 'val3')
    self.assertEqual(parsed['_foo1'], 'bar')
    self.assertEqual(record._blacklisted_1, 'test value 1')
    self.assertEqual(record._blacklisted_2, 'test value 2')
    self.assertEqual(record._blacklisted_3['key1'], 'val1')
    self.assertEqual(record._blacklisted_3['blacklisted_1'], 'val2')
    self.assertEqual(record._blacklisted_3['key3'], 'val3')
@mock.patch('st2common.logging.formatters.MASKED_ATTRIBUTES_BLACKLIST', MOCK_MASKED_ATTRIBUTES_BLACKLIST)
def test_format_blacklisted_attributes_are_masked(self):
    formatter = GelfLogFormatter()
    mock_message = 'test message 1'
    record = MockRecord()
    record.msg = mock_message
    record._blacklisted_1 = 'test value 1'
    record._blacklisted_2 = 'test value 2'
    record._blacklisted_3 = {'key1': 'val1', 'blacklisted_1': 'val2', 'key3': 'val3'}
    record._foo1 = 'bar'
    message = formatter.format(record=record)
    parsed = json.loads(message)
    self.assertEqual(parsed['_blacklisted_1'], MASKED_ATTRIBUTE_VALUE)
    self.assertEqual(parsed['_blacklisted_2'], MASKED_ATTRIBUTE_VALUE)
    self.assertEqual(parsed['_blacklisted_3']['key1'], 'val1')
    self.assertEqual(parsed['_blacklisted_3']['blacklisted_1'], MASKED_ATTRIBUTE_VALUE)
    self.assertEqual(parsed['_blacklisted_3']['key3'], 'val3')
    self.assertEqual(parsed['_foo1'], 'bar')
    self.assertEqual(record._blacklisted_1, 'test value 1')
    self.assertEqual(record._blacklisted_2, 'test value 2')
    self.assertEqual(record._blacklisted_3['key1'], 'val1')
    self.assertEqual(record._blacklisted_3['blacklisted_1'], 'val2')
    self.assertEqual(record._blacklisted_3['key3'], 'val3')