File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 66
77# our stuff
88from secure_logger .conf import settings
9+ from secure_logger .exceptions import SecureLoggerConfigurationError
910from secure_logger .masked_dict import masked_dict2str
1011
1112
@@ -17,6 +18,14 @@ def secure_logger(
1718):
1819 """Top level decorator, for defining input parameters."""
1920
21+ logging_levels = list (settings .logging_levels )
22+ if log_level not in logging_levels :
23+ raise SecureLoggerConfigurationError (f"Invalid logging level: { log_level } . Valid values are: { logging_levels } " )
24+ if indent < 0 :
25+ raise SecureLoggerConfigurationError (f"Invalid indentation value: { indent } . Valid values are: 0 or greater." )
26+ if message == "" :
27+ raise SecureLoggerConfigurationError (f"Invalid redaction message: { message } . Must be a non-empty string." )
28+
2029 def decorate (func ):
2130 """
2231 Decorate a Python a class, a class method, or a function.
Original file line number Diff line number Diff line change 1010
1111from secure_logger .conf import settings
1212from secure_logger .decorators import secure_logger
13+ from secure_logger .exceptions import SecureLoggerConfigurationError
1314from secure_logger .masked_dict import masked_dict , masked_dict2str
1415
1516
@@ -166,6 +167,26 @@ def test_class_method_with_custom_params(self):
166167
167168 self .assertEqual (cm .output [0 ][0 :100 ], expected_output [0 :100 ])
168169
170+ def test_method_with_illegal_decorator_input (self ):
171+ """Test class method with illegal decorator input."""
172+
173+ def create_mock_class ():
174+ """Create a mock class with illegal decorator input."""
175+
176+ class MockClass :
177+ """Mock class with illegal decorator input."""
178+
179+ @secure_logger (indent = - 1 )
180+ def decorator_with_invalid_params (self ):
181+ """Test class input parameter as objects."""
182+
183+ return MockClass ()
184+
185+ self .assertRaises (
186+ SecureLoggerConfigurationError ,
187+ create_mock_class ,
188+ )
189+
169190
170191class TestClassDecorator (unittest .TestCase ):
171192 """Test class logging."""
You can’t perform that action at this time.
0 commit comments