From dabd403beab02b894cae051e7f63c5b870bfbf97 Mon Sep 17 00:00:00 2001 From: Leonard Carcaramo Date: Thu, 8 Feb 2024 08:51:35 -0500 Subject: [PATCH] Add check for irrsmo00_result_buffer_size. Signed-off-by: Leonard Carcaramo --- pyracf/common/security_admin.py | 15 +++++++++++ tests/common/test_class_attributes.py | 37 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/pyracf/common/security_admin.py b/pyracf/common/security_admin.py index 60fe383..d916b1f 100644 --- a/pyracf/common/security_admin.py +++ b/pyracf/common/security_admin.py @@ -76,6 +76,21 @@ def __init__( "base:passphrase": "racf:phrase", } if irrsmo00_result_buffer_size: + if ( + not isinstance(irrsmo00_result_buffer_size, int) + or irrsmo00_result_buffer_size < 10000 + ): + raise ValueError( + "IRRSMO00 result buffer size must be an " + + "integer value greater than or equal to '10000'." + ) + elif irrsmo00_result_buffer_size > 100000000: + self._logger.log_warning( + "IRRSMO00 result buffer sizes greater than '100000000' may " + + "result in a 'SIGKILL' signal to be raised, which is NOT " + + "recoverable and will lead to the Python process that " + + "pyRACF is running under to be killed." + ) self.__irrsmo00 = IRRSMO00(result_buffer_size=irrsmo00_result_buffer_size) else: self.__irrsmo00 = IRRSMO00() diff --git a/tests/common/test_class_attributes.py b/tests/common/test_class_attributes.py index 81d9f61..1a69997 100644 --- a/tests/common/test_class_attributes.py +++ b/tests/common/test_class_attributes.py @@ -42,6 +42,43 @@ def test_all_admin_types_support_irrsmo00_result_buffer_size(self): 16384, ) + def test_all_admin_types_raise_value_error_when_irrsmo00_result_buffer_size_is_no_good( + self, + ): + for admin_type in self.admin_types: + with self.assertRaises(ValueError) as exception: + admin_type(irrsmo00_result_buffer_size=9999) + self.assertEqual( + str(exception.exception), + "IRRSMO00 result buffer size must be an " + + "integer value greater than or equal to '10000'.", + ) + with self.assertRaises(ValueError) as exception: + admin_type(irrsmo00_result_buffer_size="Plankton") + self.assertEqual( + str(exception.exception), + "IRRSMO00 result buffer size must be an " + + "integer value greater than or equal to '10000'.", + ) + + @patch("pyracf.common.utilities.logger.Logger.log_warning") + def test_all_admin_type_log_a_warning_when_irrsmo00_result_buffer_size_is_very_large( + self, log_warning_mock: Mock + ): + for admin_type in self.admin_types: + admin_type(irrsmo00_result_buffer_size=100000001) + log_warning_mock.assert_has_calls( + [ + call( + "IRRSMO00 result buffer sizes greater than '100000000' may " + + "result in a 'SIGKILL' signal to be raised, which is NOT " + + "recoverable and will lead to the Python process that " + + "pyRACF is running under to be killed." + ) + ] + * len(self.admin_types) + ) + def test_all_admin_types_support_debug(self): for admin_type in self.admin_types: admin_object = admin_type(debug=True)