test_negcache.c revision d00ffd2cb4e2f17c75b466178bb645b5c9317909
b99dbaab171d91e1b664397cc40e039d0c087c65fielding NSS Responder
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein Pallavi Jha <pallavikumarijha@gmail.com>
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein Copyright (C) 2013 Red Hat
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein This program is free software; you can redistribute it and/or modify
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein it under the terms of the GNU General Public License as published by
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein the Free Software Foundation; either version 3 of the License, or
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein (at your option) any later version.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein This program is distributed in the hope that it will be useful,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein but WITHOUT ANY WARRANTY; without even the implied warranty of
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein GNU General Public License for more details.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein You should have received a copy of the GNU General Public License
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein along with this program. If not, see <http://www.gnu.org/licenses/>.
1b21d7b3d97def358b2e923655edeb16613a1c31gstein/* register_cli_protocol_version is required in test since it links with
1b21d7b3d97def358b2e923655edeb16613a1c31gsteinstruct cli_protocol_version *register_cli_protocol_version(void)
1b21d7b3d97def358b2e923655edeb16613a1c31gstein static struct cli_protocol_version responder_test_cli_protocol_version[] = {
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Mock NSS structure */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic struct nss_ctx *
f4c310fd2555c6faca1f980f00b161eadb089023gstein err = sss_idmap_init(sss_idmap_talloc, nctx, sss_idmap_talloc_free,
f4c310fd2555c6faca1f980f00b161eadb089023gstein DEBUG(SSSDBG_FATAL_FAILURE, ("sss_idmap_init failed.\n"));
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* responder context is duplicated here because linking
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe * with common_mock_resp.c would get us duplicates
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe ret = sss_hash_create(rctx, 30, &rctx->dp_request_table);
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct test_state *ts = talloc_get_type_abort(*state, struct test_state);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* @test_sss_ncache_uid : test following functions
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_set_uid
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_check_uid
f4c310fd2555c6faca1f980f00b161eadb089023gstein ts = talloc_get_type_abort(*state, struct test_state);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when uid not present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when uid is present in database */
48f35e10f195dd594d75738fc536bb885eda537cgstein /* test when ttl is -1 with uid present in database*/
48f35e10f195dd594d75738fc536bb885eda537cgstein/* @test_sss_ncache_gid : test following functions
48f35e10f195dd594d75738fc536bb885eda537cgstein * sss_ncache_set_gid
48f35e10f195dd594d75738fc536bb885eda537cgstein * sss_ncache_check_gid
48f35e10f195dd594d75738fc536bb885eda537cgstein ts = talloc_get_type_abort(*state, struct test_state);
48f35e10f195dd594d75738fc536bb885eda537cgstein /* test when gid is not present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when gid is present in database */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* test when ttl is -1 with gid present in database*/
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* @test_sss_ncache_sid : test following functions
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_set_sid
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_check_sid
f4c310fd2555c6faca1f980f00b161eadb089023gstein ts = talloc_get_type_abort(*state, struct test_state);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*test when sid in not present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when sid is present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when ttl is -1 with sid present in database*/
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* @test_sss_ncache_user : test following functions
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein * sss_ncache_check_user
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_set_user
f39230a531b23d94f86a087963299bbe2e431a4agstein ts = talloc_get_type_abort(*state, struct test_state);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein /* test when domain name is not present in database */
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ret = sss_ncache_check_user(ts->ctx, ttl, dom, name);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ret = sss_ncache_check_user(ts->ctx, ttl, dom, name);
f39230a531b23d94f86a087963299bbe2e431a4agstein /* test when domain name is present in database */
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ret = sss_ncache_set_user(ts->ctx, permanent, dom, name);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ret = sss_ncache_check_user(ts->ctx, ttl, dom, name);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ret = sss_ncache_set_user(ts->ctx, permanent, dom, name);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ret = sss_ncache_check_user(ts->ctx, ttl, dom, name);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein /* test when ttl is -1 with domain name present in database */
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ret = sss_ncache_check_user(ts->ctx, ttl, dom, name);
f39230a531b23d94f86a087963299bbe2e431a4agstein/* @test_sss_ncache_group : test following functions
f39230a531b23d94f86a087963299bbe2e431a4agstein * sss_ncache_check_group
f39230a531b23d94f86a087963299bbe2e431a4agstein * sss_ncache_set_group
f39230a531b23d94f86a087963299bbe2e431a4agstein ts = talloc_get_type_abort(*state, struct test_state);
f39230a531b23d94f86a087963299bbe2e431a4agstein /* test when domain name is not present in database */
f39230a531b23d94f86a087963299bbe2e431a4agstein ret = sss_ncache_check_group(ts->ctx, ttl, dom, name);
f39230a531b23d94f86a087963299bbe2e431a4agstein ret = sss_ncache_check_group(ts->ctx, ttl, dom, name);
f39230a531b23d94f86a087963299bbe2e431a4agstein /* test when domain name is present in database */
f39230a531b23d94f86a087963299bbe2e431a4agstein ret = sss_ncache_set_group(ts->ctx, permanent, dom, name);
f39230a531b23d94f86a087963299bbe2e431a4agstein ret = sss_ncache_check_group(ts->ctx, ttl, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_set_group(ts->ctx, permanent, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_group(ts->ctx, ttl, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when ttl is -1 with domain name present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_group(ts->ctx, ttl, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* @test_sss_ncache_netgr : test following functions
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_check_netgr
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_set_netgr
f4c310fd2555c6faca1f980f00b161eadb089023gstein ts = talloc_get_type_abort(*state, struct test_state);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when domain name is not present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_netgr(ts->ctx, ttl, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_netgr(ts->ctx, ttl, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when domain name is present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_set_netgr(ts->ctx, permanent, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_netgr(ts->ctx, ttl, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_set_netgr(ts->ctx, permanent, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_netgr(ts->ctx, ttl, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when ttl is -1 with domain name present in database */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ret = sss_ncache_check_netgr(ts->ctx, ttl, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* @test_sss_ncache_service_name : test following functions
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * sss_ncache_check_service
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_set_service_name
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void test_sss_ncache_service_name(void **state)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ts = talloc_get_type_abort(*state, struct test_state);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when domain name and protocol are not present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service(ts->ctx, ttl, dom, name, PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service(ts->ctx, ttl, dom, name, PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when domain name and protocol are present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_set_service_name(ts->ctx, permanent, dom, name, PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service(ts->ctx, ttl, dom, name, PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_set_service_name(ts->ctx, permanent, dom, name, PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service(ts->ctx, ttl, dom, name, PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when ttl is -1 with domain name present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service(ts->ctx, ttl, dom, name, PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* @test_sss_ncache_service_port : test following functions
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_check_service_port
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_set_service_port
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void test_sss_ncache_service_port(void **state)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ts = talloc_get_type_abort(*state, struct test_state);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when domain name, port and protocol are not present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service_port(ts->ctx, ttl, dom, (uint16_t)PORT,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service_port(ts->ctx, ttl, dom, (uint16_t)PORT,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when domain name, port and protocol are present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_set_service_port(ts->ctx, permanent, dom, (uint16_t)PORT,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service_port(ts->ctx, ttl, dom, (uint16_t)PORT,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_set_service_port(ts->ctx, permanent, dom, (uint16_t)PORT,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service_port(ts->ctx, ttl, dom, (uint16_t)PORT,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when ttl is -1 with domain name present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service_port(ts->ctx, ttl, dom, (uint16_t)PORT,
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void test_sss_ncache_reset_permanent(void **state)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ts = talloc_get_type_abort(*state, struct test_state);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ts = talloc_get_type_abort(*state, struct test_state);
f4c310fd2555c6faca1f980f00b161eadb089023gstein tc = create_dom_test_ctx(ts, TESTS_PATH, TEST_CONF_DB,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_names_init(ts, tc->confdb, TEST_DOM_NAME, &dom->names);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_prepopulate(ncache, tc->confdb, ts->rctx);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_user(ncache, 1, dom, "testuser1");
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_group(ncache, 1, dom, "testgroup1");
f4c310fd2555c6faca1f980f00b161eadb089023gstein unit_test_setup_teardown(test_sss_ncache_uid, setup, teardown),
f4c310fd2555c6faca1f980f00b161eadb089023gstein unit_test_setup_teardown(test_sss_ncache_gid, setup, teardown),
f4c310fd2555c6faca1f980f00b161eadb089023gstein unit_test_setup_teardown(test_sss_ncache_sid, setup, teardown),
f4c310fd2555c6faca1f980f00b161eadb089023gstein unit_test_setup_teardown(test_sss_ncache_user, setup, teardown),
f4c310fd2555c6faca1f980f00b161eadb089023gstein unit_test_setup_teardown(test_sss_ncache_group, setup, teardown),
f4c310fd2555c6faca1f980f00b161eadb089023gstein unit_test_setup_teardown(test_sss_ncache_netgr, setup, teardown),
f4c310fd2555c6faca1f980f00b161eadb089023gstein unit_test_setup_teardown(test_sss_ncache_service_name, setup,
f4c310fd2555c6faca1f980f00b161eadb089023gstein unit_test_setup_teardown(test_sss_ncache_service_port, setup,
f4c310fd2555c6faca1f980f00b161eadb089023gstein unit_test_setup_teardown(test_sss_ncache_reset_permanent, setup,
f4c310fd2555c6faca1f980f00b161eadb089023gstein unit_test_setup_teardown(test_sss_ncache_prepopulate, setup, teardown)
f4c310fd2555c6faca1f980f00b161eadb089023gstein test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_SYSDB_FILE);