>From c14978d23957b57b33a223ebc3f103151c0cd39f Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Mon, 9 Mar 2015 17:26:54 +0100 Subject: [PATCH 1/4] tests: ncache_hit must be an int to test UPNs In order to detect faulty cases where negcache would be checked twice, we need to convert the ncache_hit to integer and check exact amounts of hits. --- src/tests/cmocka/test_nss_srv.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/tests/cmocka/test_nss_srv.c b/src/tests/cmocka/test_nss_srv.c index 4dbda3bd605a9559658cec58009c762c77dd1b1a..bf8bddb263f1f0b8eae1293c021fa958f329f1e0 100644 --- a/src/tests/cmocka/test_nss_srv.c +++ b/src/tests/cmocka/test_nss_srv.c @@ -48,7 +48,7 @@ struct nss_test_ctx { struct sss_cmd_table *nss_cmds; struct nss_ctx *nctx; - bool ncache_hit; + int ncache_hits; }; const char *global_extra_attrs[] = {"phone", "mobile", NULL}; @@ -159,7 +159,7 @@ int __wrap_sss_ncache_check_user(struct sss_nc_ctx *ctx, int ttl, ret = __real_sss_ncache_check_user(ctx, ttl, dom, name); if (ret == EEXIST) { - nss_test_ctx->ncache_hit = true; + nss_test_ctx->ncache_hits++; } return ret; } @@ -172,7 +172,7 @@ int __wrap_sss_ncache_check_uid(struct sss_nc_ctx *ctx, int ttl, uid_t uid) ret = __real_sss_ncache_check_uid(ctx, ttl, uid); if (ret == EEXIST) { - nss_test_ctx->ncache_hit = true; + nss_test_ctx->ncache_hits++; } return ret; } @@ -347,7 +347,7 @@ void test_nss_getpwnam_neg(void **state) mock_input_user_or_group("testuser_neg"); mock_account_recv_simple(); - assert_true(nss_test_ctx->ncache_hit == false); + assert_int_equal(nss_test_ctx->ncache_hits, 0); ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM, nss_test_ctx->nss_cmds); @@ -356,7 +356,7 @@ void test_nss_getpwnam_neg(void **state) /* Wait until the test finishes with ENOENT */ ret = test_ev_loop(nss_test_ctx->tctx); assert_int_equal(ret, ENOENT); - assert_true(nss_test_ctx->ncache_hit == false); + assert_int_equal(nss_test_ctx->ncache_hits, 0); /* Test that subsequent search for a nonexistent user yields * ENOENT and Account callback is not called, on the other hand @@ -373,7 +373,7 @@ void test_nss_getpwnam_neg(void **state) ret = test_ev_loop(nss_test_ctx->tctx); assert_int_equal(ret, ENOENT); /* Negative cache was hit this time */ - assert_true(nss_test_ctx->ncache_hit == true); + assert_int_equal(nss_test_ctx->ncache_hits, 1); } static int test_nss_getpwnam_search_acct_cb(void *pvt) @@ -791,7 +791,7 @@ void test_nss_getpwuid_neg(void **state) mock_input_id(nss_test_ctx, id); mock_account_recv_simple(); - assert_true(nss_test_ctx->ncache_hit == false); + assert_int_equal(nss_test_ctx->ncache_hits, 0); ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWUID, nss_test_ctx->nss_cmds); @@ -800,7 +800,7 @@ void test_nss_getpwuid_neg(void **state) /* Wait until the test finishes with ENOENT */ ret = test_ev_loop(nss_test_ctx->tctx); assert_int_equal(ret, ENOENT); - assert_true(nss_test_ctx->ncache_hit == false); + assert_int_equal(nss_test_ctx->ncache_hits, 0); /* Test that subsequent search for a nonexistent id yields * ENOENT and Account callback is not called, on the other hand @@ -817,7 +817,7 @@ void test_nss_getpwuid_neg(void **state) ret = test_ev_loop(nss_test_ctx->tctx); assert_int_equal(ret, ENOENT); /* Negative cache was hit this time */ - assert_true(nss_test_ctx->ncache_hit == true); + assert_int_equal(nss_test_ctx->ncache_hits, 1); } static int test_nss_getpwuid_search_acct_cb(void *pvt) -- 2.1.0