Skip to content

Commit

Permalink
test(fim): unit tests for get_user and get_group
Browse files Browse the repository at this point in the history
  • Loading branch information
vikman90 committed Aug 16, 2024
1 parent 9966c5b commit 03922dc
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/common/syscheck_op/tests/unit/tests/test_syscheck_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ static void test_get_user_error(void **state) {
will_return(__wrap_getpwuid_r, ENOENT);
#endif

expect_string(__wrap__mdebug2, formatted_msg, "Failed getting user_name (2): 'No such file or directory'\n");
expect_string(__wrap__mdebug2, formatted_msg, "Failed getting user_name for uid 1: (2): 'No such file or directory'\n");

user = get_user(1);

Expand Down Expand Up @@ -536,6 +536,26 @@ static void test_get_group_no_group(void **state) {

assert_null(output);
}

static void test_get_group_error(void **state) {
const char *output;

errno = ENOENT;

will_return(__wrap_sysconf, 8);

expect_value(__wrap_w_getgrgid, gid, 1000);
will_return(__wrap_w_getgrgid, NULL);
will_return(__wrap_w_getgrgid, NULL); // We don't care about member buffers
will_return(__wrap_w_getgrgid, 0); // Fail

expect_string(__wrap__mdebug2, formatted_msg, "Failed getting group_name for gid 1000: (2): 'No such file or directory'\n");

output = get_group(1000);

assert_null(output);
}

#else
static void test_get_group(void **state) {
assert_string_equal(get_group(0), "");
Expand Down Expand Up @@ -3140,6 +3160,7 @@ int main(int argc, char *argv[]) {
/* get_group tests */
cmocka_unit_test(test_get_group_success),
cmocka_unit_test(test_get_group_no_group),
cmocka_unit_test_teardown(test_get_group_error, teardown_string),

/* ag_send_syscheck tests */
cmocka_unit_test(test_ag_send_syscheck_success),
Expand Down

0 comments on commit 03922dc

Please sign in to comment.