Esempio n. 1
0
  def test_redaction_rule_works(self):
    rule = RedactionRule('password='******'password="******"', 'password="******"')

    test_strings = [
        ('message', 'message'),
        ('password="******"', 'password="******"'),
        ('before password="******" after', 'before password="******" after'),
    ]

    for message, redacted_message in test_strings:
      assert_equal(rule.redact(message), redacted_message)
Esempio n. 2
0
  def test_non_redacted_string_returns_same_string(self):
    rule = RedactionRule('password='******'password="******"', 'password="******"')

    message = 'message'
    assert_true(rule.redact(message) is message)
Esempio n. 3
0
    def test_redact_statements(self):
        old_policies = redaction.global_redaction_engine.policies
        redaction.global_redaction_engine.policies = [
            RedactionPolicy([
                RedactionRule('', 'ssn=\d{3}-\d{2}-\d{4}', 'ssn=XXX-XX-XXXX'),
            ])
        ]

        logfilter.add_log_redaction_filter_to_logger(
            redaction.global_redaction_engine, logging.root)

        sensitive_query = 'SELECT "ssn=123-45-6789"'
        redacted_query = 'SELECT "ssn=XXX-XX-XXXX"'
        nonsensitive_query = 'SELECT "hello"'

        snippets = [
            {
                'status': 'ready',
                'viewSettings': {
                    'sqlDialect': True,
                    'snippetImage': '/static/beeswax/art/icon_beeswax_48.png',
                    'placeHolder':
                    'Example: SELECT * FROM tablename, or press CTRL + space',
                    'aceMode': 'ace/mode/hive'
                },
                'id': '10a29cda-063f-1439-4836-d0c460154075',
                'statement_raw': sensitive_query,
                'statement': sensitive_query,
                'type': 'hive'
            },
            {
                'status': 'ready',
                'viewSettings': {
                    'sqlDialect': True,
                    'snippetImage': '/static/impala/art/icon_impala_48.png',
                    'placeHolder':
                    'Example: SELECT * FROM tablename, or press CTRL + space',
                    'aceMode': 'ace/mode/impala'
                },
                'id': 'e17d195a-beb5-76bf-7489-a9896eeda67a',
                'statement_raw': sensitive_query,
                'statement': sensitive_query,
                'type': 'impala'
            },
            {
                'status': 'ready',
                'viewSettings': {
                    'sqlDialect': True,
                    'snippetImage': '/static/beeswax/art/icon_beeswax_48.png',
                    'placeHolder':
                    'Example: SELECT * FROM tablename, or press CTRL + space',
                    'aceMode': 'ace/mode/hive'
                },
                'id': '10a29cda-063f-1439-4836-d0c460154075',
                'statement_raw': nonsensitive_query,
                'statement': nonsensitive_query,
                'type': 'hive'
            },
        ]

        try:
            self.document2.type = 'notebook'
            self.document2.update_data({'snippets': snippets})
            self.document2.save()
            saved_snippets = self.document2.data_dict['snippets']

            # Make sure redacted queries are redacted.
            assert_equal(redacted_query, saved_snippets[0]['statement'])
            assert_equal(redacted_query, saved_snippets[0]['statement_raw'])
            assert_equal(True, saved_snippets[0]['is_redacted'])

            assert_equal(redacted_query, saved_snippets[1]['statement'])
            assert_equal(redacted_query, saved_snippets[1]['statement_raw'])
            assert_equal(True, saved_snippets[1]['is_redacted'])

            # Make sure unredacted queries are not redacted.
            assert_equal(nonsensitive_query, saved_snippets[2]['statement'])
            assert_equal(nonsensitive_query,
                         saved_snippets[2]['statement_raw'])
            assert_false('is_redacted' in saved_snippets[2])
        finally:
            redaction.global_redaction_engine.policies = old_policies
Esempio n. 4
0
    def test_non_redacted_string_returns_same_string(self):
        rule = RedactionRule('password='******'password="******"', 'password="******"')

        message = 'message'
        assert_true(rule.redact(message) is message)