Skip to content

Commit

Permalink
Add more unit testing
Browse files Browse the repository at this point in the history
-Flushed out unit testing for revoke and resume dates of group connection templates through user and group profile extraction.

Signed-off-by: Elijah Swift <elijah.swift@ibm.com>
  • Loading branch information
ElijahSwiftIBM committed Mar 4, 2024
1 parent 53dd1a6 commit c4329a5
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 10 deletions.
12 changes: 8 additions & 4 deletions pyracf/common/security_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,15 +609,19 @@ def __make_connection_traits(self, traits_dict: dict) -> dict:
}
template_dict = {}
if traits_dict["resumeDate"] is not None:
resume_date = datetime.strptime(traits_dict["resumeDate"], "%y.%j").date()
date = datetime.now()
resume_date = datetime.strptime(
traits_dict["resumeDate"], "%m/%d/%Y"
).date()
date = datetime.today().date()
if resume_date <= date:
template_dict["base:resume"] = True
else:
template_dict["base:resume"] = resume_date.strftime("%m/%d/%y")
if traits_dict["revokeDate"] is not None:
revoke_date = datetime.strptime(traits_dict["revokeDate"], "%y.%j").date()
traits_dict["revokeDate"] = True
revoke_date = datetime.strptime(
traits_dict["revokeDate"], "%m/%d/%Y"
).date()
date = datetime.today().date()
if revoke_date <= date:
template_dict["base:revoke"] = True
else:
Expand Down
24 changes: 24 additions & 0 deletions tests/group/test_group_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,30 @@ def get_sample(sample_file: str) -> Union[str, bytes]:
},
},
]
TEST_EXTRACT_GROUP_CONNECTION_TEMPLATE_PAST_DATES_TRAITS = [
{
"userid": "eswift",
"group": "testgrp0",
"traits": {
"base:revoke": True,
"base:resume": True,
"base:group_authority": "use",
"base:universal_access": None,
"base:special": True,
},
},
{
"userid": "leonard",
"group": "testgrp0",
"traits": {
"base:revoke": True,
"base:resume": True,
"base:group_authority": "use",
"base:universal_access": None,
"base:operations": True,
},
},
]

# Delete Group
TEST_DELETE_GROUP_REQUEST_XML = get_sample("delete_group_request.xml")
Expand Down
27 changes: 22 additions & 5 deletions tests/group/test_group_result_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,28 @@ def test_group_admin_can_build_template_connection_success_xml(
call_racf_mock.return_value = (
TestGroupConstants.TEST_EXTRACT_GROUP_RESULT_BASE_ONLY_SUCCESS_XML
)
template = self.group_admin.extract(
"testgrp0", segments=["omvs"], connection_template=True
)
print(template)
self.assertEqual(
template,
self.group_admin.extract(
"testgrp0", segments=["omvs"], connection_template=True
),
TestGroupConstants.TEST_EXTRACT_GROUP_CONNECTION_TEMPLATE_TRAITS,
)

def test_group_admin_can_build_template_connection_success_with_past_dates_xml(
self,
call_racf_mock: Mock,
):
extract_group_xml = (
TestGroupConstants.TEST_EXTRACT_GROUP_RESULT_BASE_ONLY_SUCCESS_XML
)
extract_group_xml = extract_group_xml.replace(
"<message> REVOKE DATE=NONE RESUME DATE=NONE</message>",
"<message> REVOKE DATE=23.340 RESUME DATE=23.360</message>",
)
call_racf_mock.return_value = extract_group_xml
self.assertEqual(
self.group_admin.extract(
"testgrp0", segments=["omvs"], connection_template=True
),
TestGroupConstants.TEST_EXTRACT_GROUP_CONNECTION_TEMPLATE_PAST_DATES_TRAITS,
)
12 changes: 12 additions & 0 deletions tests/user/test_user_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,18 @@ def get_sample(sample_file: str) -> Union[str, bytes]:
"traits": {"base:group_authority": "use", "base:owner": "leonard"},
}
]
TEST_EXTRACT_USER_CONNECTION_TEMPLATE_FUTURE_DATES_TRAITS = [
{
"userid": "squidwrd",
"group": "SYS1",
"traits": {
"base:group_authority": "use",
"base:owner": "leonard",
"base:revoke": "05/30/50",
"base:resume": "07/19/50",
},
}
]

# Delete User
TEST_DELETE_USER_REQUEST_XML = get_sample("delete_user_request.xml")
Expand Down
20 changes: 19 additions & 1 deletion tests/user/test_user_result_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ def test_user_admin_can_parse_extract_user_base_only_installation_data_success_x
TestUserConstants.TEST_EXTRACT_USER_RESULT_BASE_ONLY_INST_DATA_SUCCESS_XML
)
result = self.user_admin.extract("squidwrd")
print(result)
self.assertEqual(
result,
TestUserConstants.TEST_EXTRACT_USER_RESULT_BASE_ONLY_INST_DATA_SUCCESS_JSON,
Expand Down Expand Up @@ -569,3 +568,22 @@ def test_user_admin_can_build_template_connection_success_xml(
),
TestUserConstants.TEST_EXTRACT_USER_CONNECTION_TEMPLATE_TRAITS,
)

def test_user_admin_can_build_template_connection_success_with_future_dates_xml(
self,
call_racf_mock: Mock,
):
extract_user_xml = (
TestUserConstants.TEST_EXTRACT_USER_RESULT_BASE_OMVS_TSO_REVOKE_RESUME_XML
)
extract_user_xml = extract_user_xml.replace(
"<message> REVOKE DATE=NONE RESUME DATE=NONE</message>",
"<message> REVOKE DATE=50.150 RESUME DATE=50.200</message>",
)
call_racf_mock.return_value = extract_user_xml
self.assertEqual(
self.user_admin.extract(
"squidwrd", segments=["omvs", "tso"], connection_template=True
),
TestUserConstants.TEST_EXTRACT_USER_CONNECTION_TEMPLATE_FUTURE_DATES_TRAITS,
)

0 comments on commit c4329a5

Please sign in to comment.