Skip to content

Commit

Permalink
Add unit test for NSS users/groups
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Aponte <[email protected]>
  • Loading branch information
federico-sysdig authored and poiana committed Jun 14, 2024
1 parent 3e4c26b commit 19b6911
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions userspace/libsinsp/test/user.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ class usergroup_manager_host_root_test : public sinsp_with_test_input

{
std::ofstream ofs(etc + "/passwd");
ofs << "toor:x:0:0:toor:/toor:/bin/ash" << std::endl;
ofs.close();
ofs << "toor:x:0:0:toor:/toor:/bin/ash\n"
<< "+testuser::::::\n";
}
{
std::ofstream ofs(etc + "/group");
ofs << "toor:x:0:toor" << std::endl;
ofs.close();
ofs << "toor:x:0:toor\n"
<< "+testgroup::::::\n";
}
}

Expand Down Expand Up @@ -211,4 +211,19 @@ TEST_F(usergroup_manager_host_root_test, host_root_lookup)
ASSERT_EQ(group->gid, 0);
ASSERT_STREQ(group->name, "toor");
}

TEST_F(usergroup_manager_host_root_test, nss_user_lookup)
{
std::string container_id; // empty container_id means host

sinsp_usergroup_manager mgr(&m_inspector);
mgr.add_user(container_id, -1, 0, 0, {}, {}, {});
mgr.add_user(container_id, -1, 65534, 0, {}, {}, {});

auto* usr = mgr.add_user(container_id, -1, 0, 0, "+test_user", "", "");
ASSERT_EQ(usr, nullptr);

auto* grp = mgr.add_group(container_id, -1, 0, "+test_group");
ASSERT_EQ(grp, nullptr);
}
#endif

0 comments on commit 19b6911

Please sign in to comment.