Skip to content

Commit 20e6fa3

Browse files
committed
Add a couple additional tests
1 parent 1b8d2b3 commit 20e6fa3

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

usr/lib/python3/dist-packages/privleap/tests/run_test.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3328,6 +3328,51 @@ def privleapd_invalid_ascii_test(idx_str: str) -> bool:
33283328
return False
33293329

33303330

3331+
def privleapd_control_msg_mismatch_test(bogus: str) -> bool:
3332+
"""
3333+
Test how privleapd handles receiving a comm message on the control socket.
3334+
"""
3335+
3336+
if bogus != "":
3337+
return False
3338+
discard_privleapd_stderr()
3339+
control_session: PrivleapSession = PrivleapSession(is_control_session=True)
3340+
assert control_session.backend_socket is not None
3341+
# pylint: disable=protected-access
3342+
# Same rationale as for leaprun_server_invalid_msg_seq_test
3343+
control_session._PrivleapSession__send_msg( # type: ignore [attr-defined]
3344+
PrivleapCommClientSignalMsg("test-act-free")
3345+
)
3346+
control_session.close_session()
3347+
if not compare_privleapd_stderr(
3348+
PlTestData.privleapd_control_msg_mismatch_lines
3349+
):
3350+
return False
3351+
return True
3352+
3353+
3354+
def privleapd_comm_msg_mismatch_test(bogus: str) -> bool:
3355+
"""
3356+
Test how privleapd handles receiving a control message on the comm socket.
3357+
"""
3358+
3359+
if bogus != "":
3360+
return False
3361+
comm_session: PrivleapSession = PrivleapSession("privleaptestone")
3362+
assert comm_session.backend_socket is not None
3363+
# pylint: disable=protected-access
3364+
# Same rationale as for privleapd_control_msg_mismatch_test
3365+
comm_session._PrivleapSession__send_msg( # type: ignore [attr-defined]
3366+
PrivleapControlClientCreateMsg("wha")
3367+
)
3368+
comm_session.close_session()
3369+
if not compare_privleapd_stderr(
3370+
PlTestData.privleapd_comm_msg_mismatch_lines
3371+
):
3372+
return False
3373+
return True
3374+
3375+
33313376
def privleapd_send_random_garbage_test(bogus: str) -> bool:
33323377
"""
33333378
Test how privleapd handles a comm client that sends pseudorandom data.
@@ -4123,6 +4168,18 @@ def run_privleapd_tests() -> None:
41234168
f"Test privleapd invalid ASCII handling (iteration {i+1})",
41244169
)
41254170
# ---
4171+
privleapd_assert_function(
4172+
privleapd_control_msg_mismatch_test,
4173+
"",
4174+
"Test privleapd control message mismatch handling",
4175+
)
4176+
# ---
4177+
privleapd_assert_function(
4178+
privleapd_comm_msg_mismatch_test,
4179+
"",
4180+
"Test privleapd comm message mismatch handling",
4181+
)
4182+
# ---
41264183
privleapd_assert_command(["/usr/bin/privleapd", "-C"], exit_code=0)
41274184
# ---
41284185
privleapd_assert_command(

usr/lib/python3/dist-packages/privleap/tests/run_test_util.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,3 +1525,14 @@ class PlTestData:
15251525
+ "by account 'XXX_USERNAME_XXX' completed",
15261526
]
15271527
)
1528+
privleapd_control_msg_mismatch_lines: list[str] = [
1529+
"handle_control_session: ERROR: Could not get message from control client!\n",
1530+
"Traceback (most recent call last):\n",
1531+
"ValueError: Invalid message type 'SIGNAL' for socket\n",
1532+
]
1533+
privleapd_comm_msg_mismatch_lines: list[str] = [
1534+
"get_client_initial_msg: ERROR: Could not get message from client run by account "
1535+
+ "'privleaptestone'!\n",
1536+
"Traceback (most recent call last):\n",
1537+
"ValueError: Invalid message type 'CREATE' for socket\n",
1538+
]

0 commit comments

Comments
 (0)