コード例 #1
0
 def test_invalid_input_values(self):
     with self.assertRaises(TypeError):
         RedactionConfig(redactMode='somestring')
     with self.assertRaises(TypeError):
         RedactionConfig(redactMode=0)
     with self.assertRaises(TypeError):
         RedactionConfig(redactResponseURL=0)
コード例 #2
0
    def test_redactResponseURL(self):
        rc = RedactionConfig(redactResponseURL=True)
        event = {
            'RequestType': 'Create',
            'RequestId': 'abcded',
            'ResponseURL': 'https://localhost',
            'StackId': 'arn:...',
            'LogicalResourceId': 'Test',
            'ResourceType': 'Custom::Test'
        }
        revent = rc._redact(event)

        self.assertIn('ResponseURL', event)
        self.assertNotIn('ResponseURL', revent)
コード例 #3
0
    def test_blacklist_deprecated(self):
        with self.assertLogs(level=logging.WARNING) as captured:
            rc = RedactionConfig(redactMode=RedactMode.BLACKLIST)

        self.assertEqual(1, len(captured.records), 1)
        self.assertEqual(
            "The usage of RedactMode.BLACKLIST is deprecated, please change to use RedactMode.BLOCKLIST",
            captured.records[0].getMessage())
コード例 #4
0
    def test_structure(self):
        rc = RedactionConfig()
        rc.add_rule_set(self.ruleSetDefault)
        rc.add_rule_set(self.ruleSetCustom)

        self.assertIn('^.*$', rc._redactProperties)
        self.assertIn('^Custom::Test$', rc._redactProperties)
        self.assertIn('^Test$', rc._redactProperties['^.*$'])
        self.assertIn('^Example$', rc._redactProperties['^.*$'])
        self.assertIn('^DeleteMe.*$', rc._redactProperties['^Custom::Test$'])
        self.assertIn('^Custom$', rc._redactProperties['^Custom::Test$'])
コード例 #5
0
    def test_allowlist2(self):
        rc = RedactionConfig(redactMode=RedactMode.ALLOWLIST)
        rc.add_rule_set(self.ruleSetDefault)
        rc.add_rule_set(self.ruleSetCustom)
        event = {
            'RequestType': 'Create',
            'RequestId': 'abcded',
            'ResponseURL': 'https://localhost',
            'StackId': 'arn:...',
            'LogicalResourceId': 'Test',
            'ResourceType': 'Custom::Hello',
            'ResourceProperties': {
                'Test': NOT_REDACTED_STRING,
                'Example': NOT_REDACTED_STRING,
                'Custom': NOT_REDACTED_STRING,
                'DeleteMe1': NOT_REDACTED_STRING,
                'DeleteMe2': NOT_REDACTED_STRING,
                'DoNotDelete': NOT_REDACTED_STRING
            }
        }
        revent = rc._redact(event)

        self.assertEqual(NOT_REDACTED_STRING,
                         event['ResourceProperties']['Test'])
        self.assertEqual(NOT_REDACTED_STRING,
                         revent['ResourceProperties']['Test'])
        self.assertEqual(NOT_REDACTED_STRING,
                         event['ResourceProperties']['Example'])
        self.assertEqual(NOT_REDACTED_STRING,
                         revent['ResourceProperties']['Example'])
        self.assertEqual(NOT_REDACTED_STRING,
                         event['ResourceProperties']['Custom'])
        self.assertEqual(REDACTED_STRING,
                         revent['ResourceProperties']['Custom'])
        self.assertEqual(NOT_REDACTED_STRING,
                         event['ResourceProperties']['DeleteMe1'])
        self.assertEqual(REDACTED_STRING,
                         revent['ResourceProperties']['DeleteMe1'])
        self.assertEqual(NOT_REDACTED_STRING,
                         event['ResourceProperties']['DeleteMe2'])
        self.assertEqual(REDACTED_STRING,
                         revent['ResourceProperties']['DeleteMe2'])
        self.assertEqual(NOT_REDACTED_STRING,
                         event['ResourceProperties']['DoNotDelete'])
        self.assertEqual(REDACTED_STRING,
                         revent['ResourceProperties']['DoNotDelete'])
コード例 #6
0
 def test_input_values(self):
     rc = RedactionConfig(redactMode=RedactMode.ALLOWLIST,
                          redactResponseURL=True)
     self.assertEqual(rc.redactMode, RedactMode.ALLOWLIST)
     self.assertTrue(rc.redactResponseURL)
コード例 #7
0
 def test_defaults(self):
     rc = RedactionConfig()
     self.assertEqual(rc.redactMode, RedactMode.BLOCKLIST)
     self.assertFalse(rc.redactResponseURL)
コード例 #8
0
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

import logging
from accustom import RedactionRuleSet, RedactionConfig, decorator

logging.getLogger().setLevel(logging.DEBUG)

ruleSetDefault = RedactionRuleSet()
ruleSetDefault.add_property_regex('^Test$')
ruleSetDefault.add_property('Example')

ruleSetCustom = RedactionRuleSet('^Custom::Test$')
ruleSetCustom.add_property('Custom')
ruleSetCustom.add_property_regex('^DeleteMe.*$')

rc = RedactionConfig(redactResponseURL=True)
rc.add_rule_set(ruleSetDefault)
rc.add_rule_set(ruleSetCustom)

logger = logging.getLogger(__name__)


@decorator(hideResourceDeleteFailure=True,
           timeoutFunction=False,
           redactConfig=rc)
def handler(event, context):
    # No action actually required since we'll be looking at CW Logs.
    pass