Skip to content

Commit

Permalink
Add check for irrsmo00_result_buffer_size.
Browse files Browse the repository at this point in the history
Signed-off-by: Leonard Carcaramo <lcarcaramo@ibm.com>
  • Loading branch information
lcarcaramo committed Feb 8, 2024
1 parent 8dc5509 commit dabd403
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pyracf/common/security_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
37 changes: 37 additions & 0 deletions tests/common/test_class_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dabd403

Please sign in to comment.