Skip to content

Commit

Permalink
further cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Elijah Swift <elijah.swift@ibm.com>
  • Loading branch information
ElijahSwiftIBM committed Aug 17, 2023
1 parent 5c0dab7 commit 04abaa8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 51 deletions.
3 changes: 2 additions & 1 deletion pyracf/common/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def log_xml(
"""Indent and colorize XML string and log it to the console."""
if isinstance(xml_string, bytes):
xml_string = xml_string.decode(encoding="utf-8")
xml_string = self.redact_request_xml(xml_string, secret_traits)
if secret_traits:
xml_string = self.redact_request_xml(xml_string, secret_traits)
indented_xml_string = self.__indent_xml(xml_string)
colorized_indented_xml_string = self.__colorize_xml(indented_xml_string)
self.log_debug(header_message, colorized_indented_xml_string)
Expand Down
9 changes: 4 additions & 5 deletions pyracf/common/security_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ class SecurityAdmin:
"""Base Class for RACF Administration Interface."""

_valid_segment_traits = {}
_common_base_traits_data_set_generic = {}
__secret_traits = {}

__logger = Logger()

def __init__(
Expand Down Expand Up @@ -150,12 +147,12 @@ def _make_request(
secret_traits=self.__secret_traits,
)
if self.__generate_requests_only:
request = self.__logger.redact_request_xml(
request_xml = self.__logger.redact_request_xml(
security_request.dump_request_xml(encoding="utf-8"),
secret_traits=self.__secret_traits,
)
self.__clear_state(security_request)
return request
return request_xml
result_xml = self.__logger.redact_result_xml(
self.__irrsmo00.call_racf(
security_request.dump_request_xml(), irrsmo00_precheck
Expand All @@ -164,6 +161,8 @@ def _make_request(
)
self.__clear_state(security_request)
if self.__debug:
# No need to redact anything here since the raw result dictionary
# already has secrets redacted when passed to logger
self.__logger.log_xml("Result XML", result_xml)
results = SecurityResult(result_xml)
if self.__debug:
Expand Down
15 changes: 0 additions & 15 deletions tests/user/test_user_debug_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def test_add_user_request_debug_log_works_on_success(
)
success_log = self.ansi_escape.sub("", stdout.getvalue())
self.assertEqual(success_log, TestUserConstants.TEST_ADD_USER_SUCCESS_LOG)
self.assertNotIn(self.test_password, success_log)

def test_add_user_request_debug_log_works_on_error(
self,
Expand Down Expand Up @@ -81,7 +80,6 @@ def test_add_user_request_debug_log_passwords_get_redacted_on_success(
self.assertEqual(
success_log, TestUserConstants.TEST_ADD_USER_PASSWORD_SUCCESS_LOG
)
self.assertNotIn(self.test_password, success_log)

def test_add_user_request_debug_log_passwords_get_redacted_on_error(
self,
Expand All @@ -101,7 +99,6 @@ def test_add_user_request_debug_log_passwords_get_redacted_on_error(
pass
error_log = self.ansi_escape.sub("", stdout.getvalue())
self.assertEqual(error_log, TestUserConstants.TEST_ADD_USER_PASSWORD_ERROR_LOG)
self.assertNotIn(self.test_password, error_log)

def test_add_user_request_debug_log_passphrases_get_redacted_on_success(
self,
Expand All @@ -120,7 +117,6 @@ def test_add_user_request_debug_log_passphrases_get_redacted_on_success(
self.assertEqual(
success_log, TestUserConstants.TEST_ADD_USER_PASSPHRASE_SUCCESS_LOG
)
self.assertNotIn(self.test_passphrase, success_log)

def test_add_user_request_debug_log_passphrases_get_redacted_on_error(
self,
Expand All @@ -142,7 +138,6 @@ def test_add_user_request_debug_log_passphrases_get_redacted_on_error(
self.assertEqual(
error_log, TestUserConstants.TEST_ADD_USER_PASSPHRASE_ERROR_LOG
)
self.assertNotIn(self.test_passphrase, error_log)

def test_add_user_request_debug_log_passphrases_and_passwords_get_redacted_on_success(
self,
Expand All @@ -162,8 +157,6 @@ def test_add_user_request_debug_log_passphrases_and_passwords_get_redacted_on_su
success_log,
TestUserConstants.TEST_ADD_USER_PASSPHRASE_AND_PASSWORD_SUCCESS_LOG,
)
self.assertNotIn(self.test_passphrase, success_log)
self.assertNotIn(self.test_password, success_log)

def test_add_user_request_debug_log_passphrases_and_passwords_get_redacted_on_error(
self,
Expand All @@ -185,8 +178,6 @@ def test_add_user_request_debug_log_passphrases_and_passwords_get_redacted_on_er
self.assertEqual(
error_log, TestUserConstants.TEST_ADD_USER_PASSPHRASE_AND_PASSWORD_ERROR_LOG
)
self.assertNotIn(self.test_passphrase, error_log)
self.assertNotIn(self.test_password, error_log)

def test_add_user_request_debug_log_password_xml_tags_not_redacted_on_success(
self,
Expand Down Expand Up @@ -245,9 +236,6 @@ def test_add_user_request_debug_log_additional_secret_added_get_redacted_on_succ
success_log,
TestUserConstants.TEST_ADD_USER_ADDITIONAL_SECRET_ADDED_SUCCESS_LOG,
)
self.assertNotIn(
TestUserConstants.TEST_ADD_USER_REQUEST_TRAITS["omvs:uid"], success_log
)

def test_add_user_request_debug_log_additional_secret_added_get_redacted_on_error(
self,
Expand All @@ -268,9 +256,6 @@ def test_add_user_request_debug_log_additional_secret_added_get_redacted_on_erro
self.assertEqual(
error_log, TestUserConstants.TEST_ADD_USER_ADDITIONAL_SECRET_ADDED_ERROR_LOG
)
self.assertNotIn(
TestUserConstants.TEST_ADD_USER_REQUEST_TRAITS["omvs:uid"], error_log
)

# ============================================================================
# Extract User
Expand Down
30 changes: 0 additions & 30 deletions tests/user/test_user_result_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ def test_user_admin_password_redacted_add_user_success_xml(
result,
TestUserConstants.TEST_ADD_USER_PASSWORD_RESULT_SUCCESS_DICTIONARY,
)
result_str = str(result)
self.assertNotIn(self.test_password, result_str)
self.assertNotIn("(" + " " * len(self.test_password) + ")", result_str)

# Error in environment, SQUIDWRD already added/exists
def test_user_admin_password_redacted_add_user_error_xml(
Expand All @@ -179,9 +176,6 @@ def test_user_admin_password_redacted_add_user_error_xml(
exception.exception.result,
TestUserConstants.TEST_ADD_USER_PASSWORD_RESULT_ERROR_DICTIONARY,
)
result_str = str(exception.exception.result)
self.assertNotIn(self.test_password, result_str)
self.assertNotIn("(" + " " * len(self.test_password) + ")", result_str)

def test_user_admin_passphrase_redacted_add_user_success_xml(
self,
Expand All @@ -198,9 +192,6 @@ def test_user_admin_passphrase_redacted_add_user_success_xml(
result,
TestUserConstants.TEST_ADD_USER_PASSPHRASE_RESULT_SUCCESS_DICTIONARY,
)
result_str = str(result)
self.assertNotIn(self.test_passphrase, result_str)
self.assertNotIn("(" + " " * (len(self.test_passphrase) + 2) + ")", result_str)

# Error in environment, SQUIDWRD already added/exists
def test_user_admin_passphrase_redacted_add_user_error_xml(
Expand All @@ -219,9 +210,6 @@ def test_user_admin_passphrase_redacted_add_user_error_xml(
exception.exception.result,
TestUserConstants.TEST_ADD_USER_PASSPHRASE_RESULT_ERROR_DICTIONARY,
)
result_str = str(exception.exception.result)
self.assertNotIn(self.test_passphrase, result_str)
self.assertNotIn("(" + " " * (len(self.test_passphrase) + 2) + ")", result_str)

def test_user_admin_passphrase_and_password_redacted_add_user_success_xml(
self,
Expand All @@ -238,11 +226,6 @@ def test_user_admin_passphrase_and_password_redacted_add_user_success_xml(
result,
TestUserConstants.TEST_ADD_USER_PASSPHRASE_AND_PASSWORD_RESULT_SUCCESS_DICTIONARY,
)
result_str = str(result)
self.assertNotIn(self.test_passphrase, result_str)
self.assertNotIn(self.test_password, result_str)
self.assertNotIn("(" + " " * (len(self.test_passphrase) + 2) + ")", result_str)
self.assertNotIn("(" + " " * len(self.test_password) + ")", result_str)

def test_user_admin_password_message_not_redacted_add_user_success_xml(
self,
Expand All @@ -259,10 +242,6 @@ def test_user_admin_password_message_not_redacted_add_user_success_xml(
result,
TestUserConstants.TEST_ADD_USER_PASSWORD_RESULT_SUCCESS_DICTIONARY,
)
result_str = str(result)
self.assertNotIn("(" + self.simple_password + ")", result_str)
self.assertNotIn("(" + " " * len(self.simple_password) + ")", result_str)
self.assertIn(self.simple_password, result_str)

# Error in environment, SQUIDWRD already added/exists
def test_user_admin_password_message_not_redacted_add_user_error_xml(
Expand All @@ -281,10 +260,6 @@ def test_user_admin_password_message_not_redacted_add_user_error_xml(
exception.exception.result,
TestUserConstants.TEST_ADD_USER_PASSWORD_RESULT_ERROR_DICTIONARY,
)
result_str = str(exception.exception.result)
self.assertNotIn("(" + self.simple_password + ")", result_str)
self.assertNotIn("(" + " " * len(self.simple_password) + ")", result_str)
self.assertIn(self.simple_password, result_str)

# Error in environment, SQUIDWRD already added/exists
def test_user_admin_passphrase_and_password_redacted_add_user_error_xml(
Expand All @@ -303,11 +278,6 @@ def test_user_admin_passphrase_and_password_redacted_add_user_error_xml(
exception.exception.result,
TestUserConstants.TEST_ADD_USER_PASSPHRASE_AND_PASSWORD_RESULT_ERROR_DICTIONARY,
)
result_str = str(exception.exception.result)
self.assertNotIn(self.test_passphrase, result_str)
self.assertNotIn(self.test_password, result_str)
self.assertNotIn("(" + " " * (len(self.test_passphrase) + 2) + ")", result_str)
self.assertNotIn("(" + " " * len(self.test_password) + ")", result_str)

# ============================================================================
# Delete User
Expand Down

0 comments on commit 04abaa8

Please sign in to comment.