d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha NSS Responder
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha Pallavi Jha <pallavikumarijha@gmail.com>
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha Copyright (C) 2013 Red Hat
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha This program is free software; you can redistribute it and/or modify
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha it under the terms of the GNU General Public License as published by
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha the Free Software Foundation; either version 3 of the License, or
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha (at your option) any later version.
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha This program is distributed in the hope that it will be useful,
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha but WITHOUT ANY WARRANTY; without even the implied warranty of
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha GNU General Public License for more details.
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha You should have received a copy of the GNU General Public License
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha along with this program. If not, see <http://www.gnu.org/licenses/>.
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose#define CERT "MIIECTCCAvGgAwIBAgIBCTANBgkqhkiG9w0BAQsFADA0MRIwEAYDVQQKDAlJUEEuREVWRUwxHjAcBgNVBAMMFUNlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNTA0MjgxMDIxMTFaFw0xNzA0MjgxMDIxMTFaMDIxEjAQBgNVBAoMCUlQQS5ERVZFTDEcMBoGA1UEAwwTaXBhLWRldmVsLmlwYS5kZXZlbDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALIykqtHuAwTVEofHikG/9BQy/dfeZFlsTkBg2qtnnc78w3XufbcnkpJp9Bmcsy/d9beqf5nlsxJ8TcjLsRQ9Ou6YtQjTfM3OILuOz8s0ICbF6qb66bd9hX/BrLO/9+KnpWFSR+E/YEmzgYyDTbKfBWBaGuPPrOi/K6vwkRYFZVA/FYZkYDtQhFmBO884HYzS4P6frRH3PvtRqWNCmaHpe97dGKsvnM2ybT+IMSB8/54GajQr3+BciRh2XaT4wvSTxkXM1fUgrDxqAP2AZmpuIyDyboZh+rWOwbrTPfx5SipELZG3uHhP8HMcr4qQ8b20LWgxCRuT73sIooHET350xUCAwEAAaOCASYwggEiMB8GA1UdIwQYMBaAFPKdQk4PxEglWC8czg+hPyLIVciRMDsGCCsGAQUFBwEBBC8wLTArBggrBgEFBQcwAYYfaHR0cDovL2lwYS1jYS5pcGEuZGV2ZWwvY2Evb2NzcDAOBgNVHQ8BAf8EBAMCBPAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMHQGA1UdHwRtMGswaaAxoC+GLWh0dHA6Ly9pcGEtY2EuaXBhLmRldmVsL2lwYS9jcmwvTWFzdGVyQ1JMLmJpbqI0pDIwMDEOMAwGA1UECgwFaXBhY2ExHjAcBgNVBAMMFUNlcnRpZmljYXRlIEF1dGhvcml0eTAdBgNVHQ4EFgQULSs/y/Wy/zIsqMIc3b2MgB7dMYIwDQYJKoZIhvcNAQELBQADggEBAJpHLlCnTR1TD8lxQgzl2n1JZOeryN/fAsGH0Vve2m8r5PC+ugnfAoULiuabBn1pOGxy/0x7Kg0/Iy8WRv8Fk7DqJCjXEqFXuFkZJfNDCtP9DzeNuMoV50iKoMfHS38BPFjXN+X/fSsBrA2fUWrlQCTmXlUN97gvQqxt5Slrxgukvxm9OSfu/sWz22LUvtJHupYwWv1iALgnXS86lAuVNYVALLxn34r58XsZlj5CSBMjBJWpaxEzgUdag3L2IPqOQXuPd0d8x11G9E/9gQquOSe2aiZjsdO/VYOCmzZsM2QPUMBVlBPDhfTVcWXQwN385uycW/ARtSzzSME2jKKWSIQ="
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* register_cli_protocol_version is required in test since it links with
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastruct cli_protocol_version *register_cli_protocol_version(void)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha static struct cli_protocol_version responder_test_cli_protocol_version[] = {
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* Mock NSS structure */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastatic struct nss_ctx *
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha err = sss_idmap_init(sss_idmap_talloc, nctx, sss_idmap_talloc_free,
c02b8482375837b57cb618ed56d4bede0e006d9dPavel Březina DEBUG(SSSDBG_FATAL_FAILURE, "sss_idmap_init failed.\n");
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech ret = sss_ncache_init(ts, SHORTSPAN, 0, &ts->ctx);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct test_state *ts = talloc_get_type_abort(*state, struct test_state);
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech ret = sss_ncache_init(memctx, SHORTSPAN, 0, &ctx);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* @test_sss_ncache_uid : test following functions
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_set_uid
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_check_uid
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when uid not present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when uid is present in database */
e1aed98d7c195f844ac8e85050d04f3ca5f899b3Sumit Bose ret = sss_ncache_set_uid(ts->ctx, permanent, NULL, uid);
e1aed98d7c195f844ac8e85050d04f3ca5f899b3Sumit Bose ret = sss_ncache_set_uid(ts->ctx, permanent, NULL, uid);
e1aed98d7c195f844ac8e85050d04f3ca5f899b3Sumit Bose ret = sss_ncache_set_uid(ts->ctx, permanent, NULL, uid);
e1aed98d7c195f844ac8e85050d04f3ca5f899b3Sumit Bose ret = sss_ncache_set_uid(ts->ctx, permanent, NULL, uid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* @test_sss_ncache_gid : test following functions
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_set_gid
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_check_gid
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when gid is not present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when gid is present in database */
e1aed98d7c195f844ac8e85050d04f3ca5f899b3Sumit Bose ret = sss_ncache_set_gid(ts->ctx, permanent, NULL, gid);
ee4be57409e157af0a57228605ef8e07f6d4fa1bPetr Cech ret = sss_ncache_set_gid(ts->ctx, permanent, NULL, gid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* @test_sss_ncache_sid : test following functions
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_set_sid
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_check_sid
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /*test when sid in not present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when sid is present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_sid(ts->ctx, permanent, sid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_sid(ts->ctx, permanent, sid);
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose/* @test_sss_ncache_cert : test following functions
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose * sss_ncache_set_cert
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose * sss_ncache_check_cert_
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose ts = talloc_get_type_abort(*state, struct test_state);
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose /*test when cert in not present in database */
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose /* test when cert is present in database */
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose ret = sss_ncache_set_cert(ts->ctx, permanent, cert);
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose ret = sss_ncache_set_cert(ts->ctx, permanent, cert);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* @test_sss_ncache_user : test following functions
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_check_user
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_set_user
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
1f5a03646ce55efa2ea415248ed5fe6375139305Lukas Slebodnik dom->name = discard_const_p(char, TEST_DOM_NAME);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek name = sss_create_internal_fqname(ts, NAME, dom->name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name is not present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name is present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_user(ts->ctx, permanent, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_user(ts->ctx, permanent, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* @test_sss_ncache_group : test following functions
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_check_group
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_set_group
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
1f5a03646ce55efa2ea415248ed5fe6375139305Lukas Slebodnik dom->name = discard_const_p(char, TEST_DOM_NAME);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek name = sss_create_internal_fqname(ts, NAME, dom->name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name is not present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name is present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_group(ts->ctx, permanent, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_group(ts->ctx, permanent, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* @test_sss_ncache_netgr : test following functions
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_check_netgr
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_set_netgr
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
1f5a03646ce55efa2ea415248ed5fe6375139305Lukas Slebodnik dom->name = discard_const_p(char, TEST_DOM_NAME);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name is not present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name is present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_netgr(ts->ctx, permanent, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_netgr(ts->ctx, permanent, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* @test_sss_ncache_service_name : test following functions
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_check_service
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_set_service_name
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastatic void test_sss_ncache_service_name(void **state)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
1f5a03646ce55efa2ea415248ed5fe6375139305Lukas Slebodnik dom->name = discard_const_p(char, TEST_DOM_NAME);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name and protocol are not present in database */
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_service(ts->ctx, dom, name, PROTO);
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_service(ts->ctx, dom, name, PROTO);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name and protocol are present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_service_name(ts->ctx, permanent, dom, name, PROTO);
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_service(ts->ctx, dom, name, PROTO);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_service_name(ts->ctx, permanent, dom, name, PROTO);
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_service(ts->ctx, dom, name, PROTO);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* @test_sss_ncache_service_port : test following functions
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_check_service_port
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_set_service_port
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastatic void test_sss_ncache_service_port(void **state)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
1f5a03646ce55efa2ea415248ed5fe6375139305Lukas Slebodnik dom->name = discard_const_p(char, TEST_DOM_NAME);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name, port and protocol are not present in database */
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_service_port(ts->ctx, dom, (uint16_t)PORT,
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_service_port(ts->ctx, dom, (uint16_t)PORT,
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name, port and protocol are present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_service_port(ts->ctx, permanent, dom, (uint16_t)PORT,
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_service_port(ts->ctx, dom, (uint16_t)PORT,
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_service_port(ts->ctx, permanent, dom, (uint16_t)PORT,
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_service_port(ts->ctx, dom, (uint16_t)PORT,
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastatic void test_sss_ncache_reset_permanent(void **state)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
e1aed98d7c195f844ac8e85050d04f3ca5f899b3Sumit Bose ret = sss_ncache_set_uid(ts->ctx, permanent, NULL, 0);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozekstatic int check_user_in_ncache(struct sss_nc_ctx *ctx,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek const char *name)
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek fqdn = sss_create_internal_fqname(ctx, name, dom->name);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozekstatic int check_group_in_ncache(struct sss_nc_ctx *ctx,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek const char *name)
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek fqdn = sss_create_internal_fqname(ctx, name, dom->name);
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidênciostatic int check_uid_in_ncache(struct sss_nc_ctx *ctx,
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio ret = sss_ncache_check_uid(ctx, NULL, uid);
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidênciostatic int check_gid_in_ncache(struct sss_nc_ctx *ctx,
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio ret = sss_ncache_check_gid(ctx, NULL, gid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastatic void test_sss_ncache_prepopulate(void **state)
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek { "filter_users", "testuser1, testuser2@"TEST_DOM_NAME", testuser3@somedomain" },
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek { "filter_groups", "testgroup1, testgroup2@"TEST_DOM_NAME", testgroup3@somedomain" },
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
1f5a03646ce55efa2ea415248ed5fe6375139305Lukas Slebodnik dom->name = discard_const_p(char, TEST_DOM_NAME);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha tc = create_dom_test_ctx(ts, TESTS_PATH, TEST_CONF_DB,
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_names_init(ts, tc->confdb, TEST_DOM_NAME, &dom->names);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_prepopulate(ncache, tc->confdb, ts->rctx);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom, "testuser1");
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom, "testgroup1");
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom, "testuser2");
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom, "testgroup2");
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom, "testuser3");
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom, "testgroup3");
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom, "testuser3@somedomain");
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom, "testgroup3@somedomain");
e54764d62bfcc48770d9b2578132979aa58636e5Fabiano Fidêncio ret = check_user_in_ncache(ncache, dom, "root");
e54764d62bfcc48770d9b2578132979aa58636e5Fabiano Fidêncio ret = check_group_in_ncache(ncache, dom, "root");
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozekstatic void test_sss_ncache_default_domain_suffix(void **state)
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek { "filter_users", "testuser1, testuser2@"TEST_DOM_NAME", testuser3@somedomain" },
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek { "filter_groups", "testgroup1, testgroup2@"TEST_DOM_NAME", testgroup3@somedomain" },
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek ts = talloc_get_type_abort(*state, struct test_state);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek dom->name = discard_const_p(char, TEST_DOM_NAME);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek tc = create_dom_test_ctx(ts, TESTS_PATH, TEST_CONF_DB,
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek ts->rctx->default_domain = discard_const(TEST_DOM_NAME);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek ret = sss_names_init(ts, tc->confdb, TEST_DOM_NAME, &dom->names);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek ret = sss_ncache_prepopulate(ncache, tc->confdb, ts->rctx);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom, "testuser1");
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom, "testgroup1");
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom, "testuser2");
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom, "testgroup2");
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom, "testuser3");
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom, "testgroup3");
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozekstatic void test_sss_ncache_reset_prepopulate(void **state)
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek { "filter_users", "testuser1@"TEST_DOM_NAME", testuser2@"TEST_DOM_NAME"2" },
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek { "filter_groups", "testgroup1@"TEST_DOM_NAME", testgroup2@"TEST_DOM_NAME"2" },
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek const char *nss_filter_users[] = { params[0].value, NULL};
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek const char *nss_filter_groups[] = { params[1].value, NULL};
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek ts = talloc_get_type_abort(*state, struct test_state);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek dom->name = discard_const_p(char, TEST_DOM_NAME);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek tc = create_dom_test_ctx(ts, TESTS_PATH, TEST_CONF_DB,
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek ret = confdb_add_param(tc->confdb, true, "config/nss",
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek ret = confdb_add_param(tc->confdb, true, "config/nss",
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek ts->rctx->default_domain = discard_const(TEST_DOM_NAME);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek ret = sss_names_init(ts, tc->confdb, TEST_DOM_NAME, &dom->names);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek ret = sss_ncache_reset_repopulate_permanent(ts->rctx, ncache);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek /* Add another domain */
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek dom2 = talloc_zero(ts, struct sss_domain_info);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek dom2->name = discard_const_p(char, TEST_DOM_NAME"2");
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek /* First domain should not be known, the second not */
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom, "testuser1");
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom, "testgroup1");
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom2, "testuser2");
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom2, "testgroup2");
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek ret = sss_ncache_reset_repopulate_permanent(ts->rctx, ncache);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek /* First domain should not be known, the second not */
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom, "testuser1");
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom, "testgroup1");
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom2, "testuser2");
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom2, "testgroup2");
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ts = talloc_get_type_abort(*state, struct test_state);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek dom->name = discard_const_p(char, TEST_DOM_NAME);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek /* Set users */
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_uid(ts->ctx, NULL, 123);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_set_uid(ts->ctx, false, NULL, 123);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_uid(ts->ctx, NULL, 123);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_user(ts->ctx, dom, "foo");
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_set_user(ts->ctx, false, dom, "foo");
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_user(ts->ctx, dom, "foo");
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek /* Set groups */
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_gid(ts->ctx, NULL, 456);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_set_gid(ts->ctx, false, NULL, 456);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_gid(ts->ctx, NULL, 456);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_group(ts->ctx, dom, "bar");
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_set_group(ts->ctx, false, dom, "bar");
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_group(ts->ctx, dom, "bar");
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek /* Users are no longer negatively cached */
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_user(ts->ctx, dom, "foo");
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_uid(ts->ctx, NULL, 123);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek /* Groups still are */
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_gid(ts->ctx, NULL, 456);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_group(ts->ctx, dom, "bar");
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_gid(ts->ctx, NULL, 456);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_group(ts->ctx, dom, "bar");
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozekstatic void test_sss_ncache_locate_uid_gid(void **state)
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ts = talloc_get_type_abort(*state, struct test_state);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek dom->name = discard_const_p(char, TEST_DOM_NAME);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek dom2->name = discard_const_p(char, TEST_DOM_NAME"2");
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_check_locate_gid(ts->ctx, dom, gid);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_check_locate_uid(ts->ctx, dom, uid);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_set_locate_gid(ts->ctx, dom, gid);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_set_locate_uid(ts->ctx, dom, uid);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_check_locate_gid(ts->ctx, dom, gid);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_check_locate_uid(ts->ctx, dom, uid);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_check_locate_gid(ts->ctx, dom2, gid);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_check_locate_uid(ts->ctx, dom2, uid);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozekstatic void test_sss_ncache_domain_locate_type(void **state)
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ts = talloc_get_type_abort(*state, struct test_state);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek dom->name = discard_const_p(char, TEST_DOM_NAME);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek dom2->name = discard_const_p(char, TEST_DOM_NAME"2");
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_check_domain_locate_type(ts->ctx, dom, "foo");
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_set_domain_locate_type(ts->ctx, dom, "foo");
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_check_domain_locate_type(ts->ctx, dom, "foo");
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_check_domain_locate_type(ts->ctx, dom2, "foo");
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_uid, setup, teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_gid, setup, teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_sid, setup, teardown),
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose cmocka_unit_test_setup_teardown(test_sss_ncache_cert, setup, teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_user, setup, teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_group, setup, teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_netgr, setup, teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_service_name, setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_service_port,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_reset_permanent, setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_prepopulate,
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_default_domain_suffix,
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_reset_prepopulate,
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_reset,
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_locate_uid_gid,
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_domain_locate_type,
cb4742876508a08ba90c82466c9dba708e4bf999Pavel Březina test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek rv = cmocka_run_group_tests(tests, NULL, NULL);