From 0c280ca6847d7fbb616f152bb6cffd5b4d74452d Mon Sep 17 00:00:00 2001 From: Luca Guerra Date: Fri, 23 Sep 2022 09:35:04 +0000 Subject: [PATCH] new(tests): add uid/gid test Signed-off-by: Luca Guerra --- userspace/libsinsp/test/sinsp.ut.cpp | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/userspace/libsinsp/test/sinsp.ut.cpp b/userspace/libsinsp/test/sinsp.ut.cpp index 59eff8d868..fbfaad54b4 100644 --- a/userspace/libsinsp/test/sinsp.ut.cpp +++ b/userspace/libsinsp/test/sinsp.ut.cpp @@ -584,3 +584,43 @@ TEST_F(sinsp_with_test_input, spawn_process) // check that pname is taken from the parent process ASSERT_EQ(get_field_as_string(evt, "proc.pname"), "init"); } + +// test user tracking with setuid +TEST_F(sinsp_with_test_input, setuid_setgid) +{ + add_default_init_thread(); + open_inspector(); + sinsp_evt* evt; + + // set a new user ID + evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_SETUID_E, 1, 500); + // check that upon entry we have the default user ID + ASSERT_EQ(get_field_as_string(evt, "user.uid"), "0"); + + // check that the user ID is updated if the call is successful + evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_SETUID_X, 1, 0); + ASSERT_EQ(get_field_as_string(evt, "user.uid"), "500"); + + // set a new group ID + evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_SETGID_E, 1, 600); + // check that upon entry we have the default group ID + ASSERT_EQ(get_field_as_string(evt, "group.gid"), "0"); + + // check that the group ID is updated if the call is successful + evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_SETGID_X, 1, 0); + ASSERT_EQ(get_field_as_string(evt, "group.gid"), "600"); + + // check that the new user ID and group ID are retained + evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_SETUID_E, 1, 0); + ASSERT_EQ(get_field_as_string(evt, "user.uid"), "500"); + ASSERT_EQ(get_field_as_string(evt, "group.gid"), "600"); + + // check that the user ID is not updated after an unsuccessful setuid call + evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_SETUID_X, 1, (int64_t) -1); + ASSERT_EQ(get_field_as_string(evt, "user.uid"), "500"); + + // same for group ID + add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_SETGID_E, 1, 0); + evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_SETGID_X, 1, (int64_t) -1); + ASSERT_EQ(get_field_as_string(evt, "group.gid"), "600"); +}