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