Skip to content

Commit

Permalink
[1.2.0] Completed Milestones for 1.2.0 release
Browse files Browse the repository at this point in the history
* [Issue #18] Changed Whitelist/Blacklist to Allowlist/Blocklist, Refactored Code, Improved Testing Code, Improved README.md grammar

* [Issue #3] Introduced logic to check size of response. Refactored decorator exception handling.

* [Issue #4] Introduced a function to collapse the output data and used this in the cfnresponse function

* [1.2.0rc1] Documentation Pass to improve README.md

* [Issue #2] Implemented Unit Tests

* [Issue #21] Added the response headers for troubleshooting to the debug log output
  • Loading branch information
taylorb-syd committed Feb 15, 2023
1 parent 6134f3d commit c416b40
Show file tree
Hide file tree
Showing 12 changed files with 576 additions and 287 deletions.
122 changes: 83 additions & 39 deletions README.md

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions accustom/Exceptions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

# Bring exceptions into the root of the submodule
"""
Bring exceptions into the root of the submodule
"""

from .exceptions import CannotApplyRuleToStandaloneRedactionConfig
from .exceptions import ConflictingValue
from .exceptions import NoPhysicalResourceIdException
from .exceptions import InvalidResponseStatusException
from .exceptions import DataIsNotDictException
from .exceptions import FailedToSendResponseException
from .exceptions import NotValidRequestObjectException
from accustom.Exceptions.exceptions import CannotApplyRuleToStandaloneRedactionConfig
from accustom.Exceptions.exceptions import ConflictingValue
from accustom.Exceptions.exceptions import NoPhysicalResourceIdException
from accustom.Exceptions.exceptions import InvalidResponseStatusException
from accustom.Exceptions.exceptions import DataIsNotDictException
from accustom.Exceptions.exceptions import FailedToSendResponseException
from accustom.Exceptions.exceptions import NotValidRequestObjectException
from accustom.Exceptions.exceptions import ResponseTooLongException
46 changes: 31 additions & 15 deletions accustom/Exceptions/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,64 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

""" Exceptions for the accustom library.
"""
Exceptions for the accustom library.
These are the exceptions that can be returned by accustom
"""


class CannotApplyRuleToStandaloneRedactionConfig(Exception):
"""Indicates that a second rule set was attempted to be applied to a standalone"""
def __init__(self, *args, **kwargs):
Exception.__init__(self, *args, **kwargs)

def __init__(self, *args):
Exception.__init__(self, *args)


class ConflictingValue(Exception):
"""Indicates that there is already a record with this value"""
def __init__(self, *args, **kwargs):
Exception.__init__(self, *args, **kwargs)

def __init__(self, *args):
Exception.__init__(self, *args)


class NoPhysicalResourceIdException(Exception):
"""Indicates that there was no valid value to use for PhysicalResourceId"""
def __init__(self, *args, **kwargs):
Exception.__init__(self, *args, **kwargs)

def __init__(self, *args):
Exception.__init__(self, *args)


class InvalidResponseStatusException(Exception):
"""Indicates that there response code was not SUCCESS or FAILED"""
def __init__(self, *args, **kwargs):
Exception.__init__(self, *args, **kwargs)

def __init__(self, *args):
Exception.__init__(self, *args)


class DataIsNotDictException(Exception):
"""Indicates that a Dictionary was not passed as Data"""
def __init__(self, *args, **kwargs):
Exception.__init__(self, *args, **kwargs)

def __init__(self, *args):
Exception.__init__(self, *args)


class FailedToSendResponseException(Exception):
"""Indicates there was a problem sending the response"""
def __init__(self, *args, **kwargs):
Exception.__init__(self, *args, **kwargs)

def __init__(self, *args):
Exception.__init__(self, *args)


class NotValidRequestObjectException(Exception):
"""Indicates that the event passed in is not a valid Request Object"""
def __init__(self, *args, **kwargs):
Exception.__init__(self, *args, **kwargs)

def __init__(self, *args):
Exception.__init__(self, *args)


class ResponseTooLongException(Exception):
"""Indicates that the produced response exceeds 4096 bytes and thus is too long"""

def __init__(self, *args):
Exception.__init__(self, *args)
11 changes: 7 additions & 4 deletions accustom/Testing/test_constants.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

"""
Testing of the "constant" library
"""
from accustom import Status
from accustom import RequestType
from accustom import RedactMode

from unittest import TestCase, main as umain
from unittest import TestCase, main as ut_main


class StatusTests(TestCase):
Expand Down Expand Up @@ -35,11 +38,11 @@ def test_allowlist(self):
self.assertEqual('allow', RedactMode.ALLOWLIST)

def test_blacklist(self):
self.assertEqual('black', RedactMode.BLACKLIST)
self.assertEqual('block', RedactMode.BLACKLIST)

def test_whitelist(self):
self.assertEqual('white', RedactMode.WHITELIST)
self.assertEqual('allow', RedactMode.WHITELIST)


if __name__ == '__main__':
umain()
ut_main()
16 changes: 14 additions & 2 deletions accustom/Testing/test_redaction.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

"""
Testing of "redaction" library
"""
from accustom import RedactionRuleSet
from accustom import RedactionConfig
from accustom import StandaloneRedactionConfig
from accustom import RedactMode
from accustom.Exceptions import CannotApplyRuleToStandaloneRedactionConfig
import logging

from unittest import TestCase, main as umain
from unittest import TestCase, main as ut_main

REDACTED_STRING = '[REDACTED]'
NOT_REDACTED_STRING = 'NotRedacted'
Expand All @@ -27,6 +30,7 @@ def test_init(self):
def test_invalid_init(self):
# This test ignores the setUp Resources
with self.assertRaises(TypeError):
# noinspection PyTypeChecker
RedactionRuleSet(0)

def test_default_regex(self):
Expand All @@ -38,6 +42,7 @@ def test_adding_regex(self):

def test_adding_invalid_regex(self):
with self.assertRaises(TypeError):
# noinspection PyTypeChecker
self.ruleSet.add_property_regex(0)

def test_adding_property(self):
Expand All @@ -46,9 +51,11 @@ def test_adding_property(self):

def test_adding_invalid_property(self):
with self.assertRaises(TypeError):
# noinspection PyTypeChecker
self.ruleSet.add_property(0)


# noinspection DuplicatedCode
class RedactionConfigTests(TestCase):

def setUp(self):
Expand Down Expand Up @@ -90,8 +97,10 @@ def test_invalid_input_values(self):
with self.assertRaises(TypeError):
RedactionConfig(redactMode='somestring')
with self.assertRaises(TypeError):
# noinspection PyTypeChecker
RedactionConfig(redactMode=0)
with self.assertRaises(TypeError):
# noinspection PyTypeChecker
RedactionConfig(redactResponseURL=0)

def test_structure(self):
Expand Down Expand Up @@ -346,6 +355,7 @@ def test_oldproperties2(self):
self.assertEqual(REDACTED_STRING, revent['OldResourceProperties']['DoNotDelete'])


# noinspection DuplicatedCode
class StandaloneRedactionConfigTests(TestCase):

def setUp(self):
Expand Down Expand Up @@ -387,8 +397,10 @@ def test_invalid_input_values(self):
with self.assertRaises(TypeError):
StandaloneRedactionConfig(self.ruleSetDefault, redactMode='somestring')
with self.assertRaises(TypeError):
# noinspection PyTypeChecker
StandaloneRedactionConfig(self.ruleSetDefault, redactMode=0)
with self.assertRaises(TypeError):
# noinspection PyTypeChecker
StandaloneRedactionConfig(self.ruleSetDefault, redactResponseURL=0)
with self.assertRaises(CannotApplyRuleToStandaloneRedactionConfig):
rc = StandaloneRedactionConfig(self.ruleSetDefault)
Expand Down Expand Up @@ -523,4 +535,4 @@ def test_oldproperties(self):


if __name__ == '__main__':
umain()
ut_main()
Loading

0 comments on commit c416b40

Please sign in to comment.