test_negcache.c revision 1f5a03646ce55efa2ea415248ed5fe6375139305
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/*
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding SSSD
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding
b99dbaab171d91e1b664397cc40e039d0c087c65fielding NSS Responder
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding Authors:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding Pallavi Jha <pallavikumarijha@gmail.com>
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding Copyright (C) 2013 Red Hat
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
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
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/>.
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding*/
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#include <stdarg.h>
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include <stdlib.h>
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#include <stddef.h>
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#include <setjmp.h>
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#include <errno.h>
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#include <unistd.h>
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include <sys/types.h>
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#include <inttypes.h>
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#include <cmocka.h>
64185f9824e42f21ca7b9ae6c004484215c031a7rbb
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "tests/cmocka/common_mock.h"
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#include "tests/cmocka/common_mock_resp.h"
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#include "responder/nss/nsssrv.h"
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#include "responder/nss/nsssrv_private.h"
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#include "sss_client/idmap/sss_nss_idmap.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "util/util_sss_idmap.h"
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#include "lib/idmap/sss_idmap.h"
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#include "util/util.h"
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#include "util/util_sss_idmap.h"
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#include "responder/common/responder.h"
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#include "responder/common/negcache.h"
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#define PORT 21
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#define SID "S-1-2-3-4-5"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#define PROTO "TCP"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#define LIFETIME 200
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#define SHORTSPAN 1
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#define NAME "foo_name"
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#define UID "U-1-2-3-4-5"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#define TESTS_PATH "tests_ncache"
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#define TEST_CONF_DB "test_nss_conf.ldb"
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#define TEST_DOM_NAME "nss_test"
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding#define TEST_SYSDB_FILE "cache_"TEST_DOM_NAME".ldb"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#define TEST_SUBDOM_NAME "test.sub"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#define TEST_ID_PROVIDER "ldap"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* register_cli_protocol_version is required in test since it links with
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * responder_common.c module
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstruct cli_protocol_version *register_cli_protocol_version(void)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding static struct cli_protocol_version responder_test_cli_protocol_version[] = {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding {0, NULL, NULL}
dc80439e9fba60c753cd145cb6799409ffea9b71ronald };
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
dc80439e9fba60c753cd145cb6799409ffea9b71ronald return responder_test_cli_protocol_version;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* Mock NSS structure */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic struct nss_ctx *
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingmock_nctx(TALLOC_CTX *mem_ctx)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding struct nss_ctx *nctx;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding errno_t ret;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding enum idmap_error_code err;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding nctx = talloc_zero(mem_ctx, struct nss_ctx);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!nctx) {
dc80439e9fba60c753cd145cb6799409ffea9b71ronald return NULL;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald }
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_init(nctx, &nctx->ncache);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ret != EOK) {
dc80439e9fba60c753cd145cb6799409ffea9b71ronald talloc_free(nctx);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald return NULL;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald }
dc80439e9fba60c753cd145cb6799409ffea9b71ronald nctx->neg_timeout = 10;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald nctx->pwfield = discard_const("*");
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
dc80439e9fba60c753cd145cb6799409ffea9b71ronald err = sss_idmap_init(sss_idmap_talloc, nctx, sss_idmap_talloc_free,
dc80439e9fba60c753cd145cb6799409ffea9b71ronald &nctx->idmap_ctx);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald if (err != IDMAP_SUCCESS) {
c7d0205ec1649076e7742d72a25ac53779768312stoddard DEBUG(SSSDBG_FATAL_FAILURE, ("sss_idmap_init failed.\n"));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding talloc_free(nctx);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return NULL;
250899dceaa9782bb99db6226ceb573bd9a02c73stoddard }
c7d0205ec1649076e7742d72a25ac53779768312stoddard return nctx;
250899dceaa9782bb99db6226ceb573bd9a02c73stoddard}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* responder context is duplicated here because linking
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * with common_mock_resp.c would get us duplicates
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstruct resp_ctx *
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingmock_rctx(TALLOC_CTX *mem_ctx,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding struct tevent_context *ev,
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe struct sss_domain_info *domains,
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe void *pvt_ctx)
694e8dc146faadc46b2455f3bd0998121fc76c5drbb{
c7d0205ec1649076e7742d72a25ac53779768312stoddard struct resp_ctx *rctx;
c7d0205ec1649076e7742d72a25ac53779768312stoddard errno_t ret;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
032b8a34c3911bbc5ad5385ca40af65af273bff9wrowe rctx = talloc_zero(mem_ctx, struct resp_ctx);
cd9f429ff62d134cdf6ec903c33430c5ebae12f0trawick if (!rctx) return NULL;
cd9f429ff62d134cdf6ec903c33430c5ebae12f0trawick
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_hash_create(rctx, 30, &rctx->dp_request_table);
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald if (ret != EOK) {
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald talloc_free(rctx);
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald return NULL;
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm rctx->ev = ev;
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald rctx->domains = domains;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm rctx->pvt_ctx = pvt_ctx;
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald return rctx;
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald}
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronaldstruct test_state {
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald struct sss_nc_ctx *ctx;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm struct nss_ctx *nctx;
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald struct resp_ctx *rctx;
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald};
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronaldstatic void setup(void **state)
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald{
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm int ret;
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald struct test_state *ts;
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald
066877f1a045103acfdd376d48cdd473c33f409bdougm ts = talloc(NULL, struct test_state);
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald assert_non_null(ts);
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald
066877f1a045103acfdd376d48cdd473c33f409bdougm ret = sss_ncache_init(ts, &ts->ctx);
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald assert_int_equal(ret, EOK);
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald assert_non_null(ts->ctx);
066877f1a045103acfdd376d48cdd473c33f409bdougm
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald *state = (void *)ts;
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald}
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronaldstatic void teardown(void **state)
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald{
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald struct test_state *ts = talloc_get_type_abort(*state, struct test_state);
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald talloc_free(ts);
8ec8f1c8f0f37ca3f5ebb0e0b491dd07481dccbfronald}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void test_sss_ncache_init(void **state)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int ret;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding TALLOC_CTX *memctx;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding struct sss_nc_ctx *ctx;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memctx = talloc_new(NULL);
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe assert_non_null(memctx);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_init(memctx, &ctx );
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EOK);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_non_null(ctx);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding talloc_free(memctx);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* @test_sss_ncache_uid : test following functions
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * sss_ncache_set_uid
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * sss_ncache_check_uid
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe */
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowestatic void test_sss_ncache_uid(void **state)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding uid_t uid;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm int ret, ttl;
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe bool permanent;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding struct test_state *ts;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ttl = LIFETIME;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding uid = getuid();
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ts = talloc_get_type_abort(*state, struct test_state);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* test when uid not present in database */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_uid(ts->ctx, ttl, uid);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, ENOENT);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
d0a225bdac006f3361e80bfc1be7e6f9b0e81f80ronald /* test when uid is present in database */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding permanent = true;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_reset_permanent(ts->ctx);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EOK);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_set_uid(ts->ctx, permanent, uid);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EOK);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_uid(ts->ctx, ttl, uid);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EEXIST);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ttl = SHORTSPAN;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_set_uid(ts->ctx, permanent, uid);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EOK);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_uid(ts->ctx, ttl, uid);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EEXIST);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sleep(SHORTSPAN + 1);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_uid(ts->ctx, ttl, uid);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EEXIST);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding permanent = false;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_set_uid(ts->ctx, permanent, uid);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EOK);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_uid(ts->ctx, ttl, uid);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EEXIST);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm sleep(SHORTSPAN + 1);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ret = sss_ncache_check_uid(ts->ctx, ttl, uid);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald assert_int_equal(ret, ENOENT);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_set_uid(ts->ctx, permanent, uid);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EOK);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* test when ttl is -1 with uid present in database*/
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ttl = -1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_uid(ts->ctx, ttl, uid);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EEXIST);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm}
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* @test_sss_ncache_gid : test following functions
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * sss_ncache_set_gid
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * sss_ncache_check_gid
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void test_sss_ncache_gid(void **state)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding gid_t gid;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald int ret, ttl;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding bool permanent;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm struct test_state *ts;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ttl = LIFETIME;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm gid = getgid();
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ts = talloc_get_type_abort(*state, struct test_state);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
dc80439e9fba60c753cd145cb6799409ffea9b71ronald /* test when gid is not present in database */
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ret = sss_ncache_check_gid(ts->ctx, ttl, gid);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald assert_int_equal(ret, ENOENT);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
dc80439e9fba60c753cd145cb6799409ffea9b71ronald /* test when gid is present in database */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding permanent = true;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ret = sss_ncache_set_gid(ts->ctx, permanent, gid);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald assert_int_equal(ret, EOK);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_gid(ts->ctx, ttl, gid);
138c8f7cb8254e035c6f45288e3909cd9c21be5cmartin assert_int_equal(ret, EEXIST);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding permanent = false;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_set_uid(ts->ctx, permanent, gid);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EOK);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ret = sss_ncache_check_uid(ts->ctx, ttl, gid);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EEXIST);
c7d0205ec1649076e7742d72a25ac53779768312stoddard
407cde44becba3694e7c3d81ac99b5d86f4b03a9rbb /* test when ttl is -1 with gid present in database*/
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ttl = -1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_gid(ts->ctx, ttl, gid);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald assert_int_equal(ret, EEXIST);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm}
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* @test_sss_ncache_sid : test following functions
dc80439e9fba60c753cd145cb6799409ffea9b71ronald * sss_ncache_set_sid
066877f1a045103acfdd376d48cdd473c33f409bdougm * sss_ncache_check_sid
dc80439e9fba60c753cd145cb6799409ffea9b71ronald */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void test_sss_ncache_sid(void **state)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
dc80439e9fba60c753cd145cb6799409ffea9b71ronald int ret, ttl;
066877f1a045103acfdd376d48cdd473c33f409bdougm bool permanent;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald const char *sid = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding struct test_state *ts;
d0a225bdac006f3361e80bfc1be7e6f9b0e81f80ronald
d0a225bdac006f3361e80bfc1be7e6f9b0e81f80ronald ttl = LIFETIME;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sid = SID;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ts = talloc_get_type_abort(*state, struct test_state);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /*test when sid in not present in database */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ret = sss_ncache_check_sid(ts->ctx, ttl, sid);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, ENOENT);
d0a225bdac006f3361e80bfc1be7e6f9b0e81f80ronald
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* test when sid is present in database */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding permanent = true;
afd0a335375c636605c8625b0d5755dd2408be2btrawick ret = sss_ncache_set_sid(ts->ctx, permanent, sid);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm assert_int_equal(ret, EOK);
afd0a335375c636605c8625b0d5755dd2408be2btrawick
afd0a335375c636605c8625b0d5755dd2408be2btrawick ret = sss_ncache_check_sid(ts->ctx, ttl, sid);
afd0a335375c636605c8625b0d5755dd2408be2btrawick assert_int_equal(ret, EEXIST);
c7d0205ec1649076e7742d72a25ac53779768312stoddard
c7d0205ec1649076e7742d72a25ac53779768312stoddard permanent = false;
e4c4fcc82268e0192db234c74a6db784b879fffdrbb ret = sss_ncache_set_sid(ts->ctx, permanent, sid);
c7d0205ec1649076e7742d72a25ac53779768312stoddard assert_int_equal(ret, EOK);
c7d0205ec1649076e7742d72a25ac53779768312stoddard
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ret = sss_ncache_check_sid(ts->ctx, ttl, sid);
250899dceaa9782bb99db6226ceb573bd9a02c73stoddard assert_int_equal(ret, EEXIST);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* test when ttl is -1 with sid present in database*/
d0a225bdac006f3361e80bfc1be7e6f9b0e81f80ronald ttl = -1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_sid(ts->ctx, ttl, sid);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EEXIST);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm}
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
dc80439e9fba60c753cd145cb6799409ffea9b71ronald/* @test_sss_ncache_user : test following functions
dc80439e9fba60c753cd145cb6799409ffea9b71ronald * sss_ncache_check_user
dc80439e9fba60c753cd145cb6799409ffea9b71ronald * sss_ncache_set_user
dc80439e9fba60c753cd145cb6799409ffea9b71ronald */
dc80439e9fba60c753cd145cb6799409ffea9b71ronaldstatic void test_sss_ncache_user(void **state)
dc80439e9fba60c753cd145cb6799409ffea9b71ronald{
dc80439e9fba60c753cd145cb6799409ffea9b71ronald int ret, ttl;
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein bool permanent;
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein const char *name = NAME;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm struct test_state *ts;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding struct sss_domain_info *dom;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ttl = LIFETIME;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ts = talloc_get_type_abort(*state, struct test_state);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dom = talloc(ts, struct sss_domain_info);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dom->name = discard_const_p(char, TEST_DOM_NAME);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
dc80439e9fba60c753cd145cb6799409ffea9b71ronald /* test when domain name is not present in database */
dc80439e9fba60c753cd145cb6799409ffea9b71ronald dom->case_sensitive = false;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ret = sss_ncache_check_user(ts->ctx, ttl, dom, name);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald assert_int_equal(ret, ENOENT);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm dom->case_sensitive = true;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ret = sss_ncache_check_user(ts->ctx, ttl, dom, name);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald assert_int_equal(ret, ENOENT);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
dc80439e9fba60c753cd145cb6799409ffea9b71ronald /* test when domain name is present in database */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding permanent = true;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_set_user(ts->ctx, permanent, dom, name);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald assert_int_equal(ret, EOK);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ret = sss_ncache_check_user(ts->ctx, ttl, dom, name);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EEXIST);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
dc80439e9fba60c753cd145cb6799409ffea9b71ronald permanent = false;
066877f1a045103acfdd376d48cdd473c33f409bdougm ret = sss_ncache_set_user(ts->ctx, permanent, dom, name);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald assert_int_equal(ret, EOK);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ret = sss_ncache_check_user(ts->ctx, ttl, dom, name);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald assert_int_equal(ret, EEXIST);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
dc80439e9fba60c753cd145cb6799409ffea9b71ronald /* test when ttl is -1 with domain name present in database */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ttl = -1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_user(ts->ctx, ttl, dom, name);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EEXIST);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm}
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
dc80439e9fba60c753cd145cb6799409ffea9b71ronald/* @test_sss_ncache_group : test following functions
dc80439e9fba60c753cd145cb6799409ffea9b71ronald * sss_ncache_check_group
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * sss_ncache_set_group
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void test_sss_ncache_group(void **state)
dc80439e9fba60c753cd145cb6799409ffea9b71ronald{
066877f1a045103acfdd376d48cdd473c33f409bdougm int ret, ttl;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald bool permanent;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald const char *name = NAME;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald struct test_state *ts;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald struct sss_domain_info *dom;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ttl = LIFETIME;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ts = talloc_get_type_abort(*state, struct test_state);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dom = talloc(ts, struct sss_domain_info);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dom->name = discard_const_p(char, TEST_DOM_NAME);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
dc80439e9fba60c753cd145cb6799409ffea9b71ronald /* test when domain name is not present in database */
dc80439e9fba60c753cd145cb6799409ffea9b71ronald dom->case_sensitive = false;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ret = sss_ncache_check_group(ts->ctx, ttl, dom, name);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, ENOENT);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
dc80439e9fba60c753cd145cb6799409ffea9b71ronald dom->case_sensitive = true;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_group(ts->ctx, ttl, dom, name);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, ENOENT);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* test when domain name is present in database */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding permanent = true;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_set_group(ts->ctx, permanent, dom, name);
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein assert_int_equal(ret, EOK);
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein ret = sss_ncache_check_group(ts->ctx, ttl, dom, name);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm assert_int_equal(ret, EEXIST);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding permanent = false;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_set_group(ts->ctx, permanent, dom, name);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EOK);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_group(ts->ctx, ttl, dom, name);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EEXIST);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* test when ttl is -1 with domain name present in database */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ttl = -1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_group(ts->ctx, ttl, dom, name);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EEXIST);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald}
090a954a1fe65b29a6f4a696f0136ef12ea0f1b1rbb
dc80439e9fba60c753cd145cb6799409ffea9b71ronald/* @test_sss_ncache_netgr : test following functions
dc80439e9fba60c753cd145cb6799409ffea9b71ronald * sss_ncache_check_netgr
dc80439e9fba60c753cd145cb6799409ffea9b71ronald * sss_ncache_set_netgr
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void test_sss_ncache_netgr(void **state)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int ret, ttl;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding bool permanent;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm const char *name = NAME;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald struct test_state *ts;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding struct sss_domain_info *dom;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ttl = LIFETIME;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ts = talloc_get_type_abort(*state, struct test_state);
066877f1a045103acfdd376d48cdd473c33f409bdougm dom = talloc(ts, struct sss_domain_info);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald dom->name = discard_const_p(char, TEST_DOM_NAME);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* test when domain name is not present in database */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm dom->case_sensitive = false;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ret = sss_ncache_check_netgr(ts->ctx, ttl, dom, name);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm assert_int_equal(ret, ENOENT);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
dc80439e9fba60c753cd145cb6799409ffea9b71ronald dom->case_sensitive = true;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ret = sss_ncache_check_netgr(ts->ctx, ttl, dom, name);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald assert_int_equal(ret, ENOENT);
066877f1a045103acfdd376d48cdd473c33f409bdougm
dc80439e9fba60c753cd145cb6799409ffea9b71ronald /* test when domain name is present in database */
066877f1a045103acfdd376d48cdd473c33f409bdougm permanent = true;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ret = sss_ncache_set_netgr(ts->ctx, permanent, dom, name);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald assert_int_equal(ret, EOK);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ret = sss_ncache_check_netgr(ts->ctx, ttl, dom, name);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald assert_int_equal(ret, EEXIST);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding permanent = false;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_set_netgr(ts->ctx, permanent, dom, name);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EOK);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ret = sss_ncache_check_netgr(ts->ctx, ttl, dom, name);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EEXIST);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* test when ttl is -1 with domain name present in database */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ttl = -1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_netgr(ts->ctx, ttl, dom, name);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm assert_int_equal(ret, EEXIST);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* @test_sss_ncache_service_name : test following functions
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * sss_ncache_check_service
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * sss_ncache_set_service_name
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void test_sss_ncache_service_name(void **state)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int ret, ttl;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding bool permanent;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *name = NAME;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding struct test_state *ts;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding struct sss_domain_info *dom;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ttl = LIFETIME;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ts = talloc_get_type_abort(*state, struct test_state);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dom = talloc(ts, struct sss_domain_info);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dom->name = discard_const_p(char, TEST_DOM_NAME);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* test when domain name and protocol are not present in database */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dom->case_sensitive = false;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_service(ts->ctx, ttl, dom, name, PROTO);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, ENOENT);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dom->case_sensitive = true;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_service(ts->ctx, ttl, dom, name, PROTO);
066877f1a045103acfdd376d48cdd473c33f409bdougm assert_int_equal(ret, ENOENT);
066877f1a045103acfdd376d48cdd473c33f409bdougm
066877f1a045103acfdd376d48cdd473c33f409bdougm /* test when domain name and protocol are present in database */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding permanent = true;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_set_service_name(ts->ctx, permanent, dom, name, PROTO);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EOK);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_service(ts->ctx, ttl, dom, name, PROTO);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EEXIST);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding permanent = false;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_set_service_name(ts->ctx, permanent, dom, name, PROTO);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EOK);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_service(ts->ctx, ttl, dom, name, PROTO);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EEXIST);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* test when ttl is -1 with domain name present in database */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ttl = -1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_service(ts->ctx, ttl, dom, name, PROTO);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EEXIST);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* @test_sss_ncache_service_port : test following functions
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * sss_ncache_check_service_port
090a954a1fe65b29a6f4a696f0136ef12ea0f1b1rbb * sss_ncache_set_service_port
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void test_sss_ncache_service_port(void **state)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int ret, ttl;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm bool permanent;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding struct test_state *ts;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding struct sss_domain_info *dom;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ttl = LIFETIME;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ts = talloc_get_type_abort(*state, struct test_state);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dom = talloc(ts, struct sss_domain_info);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dom->name = discard_const_p(char, TEST_DOM_NAME);
d0a225bdac006f3361e80bfc1be7e6f9b0e81f80ronald
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* test when domain name, port and protocol are not present in database */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dom->case_sensitive = false;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_service_port(ts->ctx, ttl, dom, (uint16_t)PORT,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm PROTO);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, ENOENT);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dom->case_sensitive = true;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ret = sss_ncache_check_service_port(ts->ctx, ttl, dom, (uint16_t)PORT,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding PROTO);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm assert_int_equal(ret, ENOENT);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* test when domain name, port and protocol are present in database */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding permanent = true;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_set_service_port(ts->ctx, permanent, dom, (uint16_t)PORT,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding PROTO);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EOK);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_service_port(ts->ctx, ttl, dom, (uint16_t)PORT,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding PROTO);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EEXIST);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
dc80439e9fba60c753cd145cb6799409ffea9b71ronald permanent = false;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ret = sss_ncache_set_service_port(ts->ctx, permanent, dom, (uint16_t)PORT,
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe PROTO);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm assert_int_equal(ret, EOK);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe ret = sss_ncache_check_service_port(ts->ctx, ttl, dom, (uint16_t)PORT,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding PROTO);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EEXIST);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* test when ttl is -1 with domain name present in database */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ttl = -1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = sss_ncache_check_service_port(ts->ctx, ttl, dom, (uint16_t)PORT,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding PROTO);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EEXIST);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void test_sss_ncache_reset_permanent(void **state)
dc80439e9fba60c753cd145cb6799409ffea9b71ronald{
dc80439e9fba60c753cd145cb6799409ffea9b71ronald int ret;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald struct test_state *ts;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ts = talloc_get_type_abort(*state, struct test_state);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ret = sss_ncache_reset_permanent(ts->ctx);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_int_equal(ret, EOK);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void test_sss_ncache_prepopulate(void **state)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int ret;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald struct test_state *ts;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald struct tevent_context *ev;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald struct sss_nc_ctx *ncache;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald struct sss_test_ctx *tc;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald struct sss_domain_info *dom;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
dc80439e9fba60c753cd145cb6799409ffea9b71ronald struct sss_test_conf_param params[] = {
dc80439e9fba60c753cd145cb6799409ffea9b71ronald { "filter_users", "testuser1" },
dc80439e9fba60c753cd145cb6799409ffea9b71ronald { "filter_groups", "testgroup1" },
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding { NULL, NULL },
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm };
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ts = talloc_get_type_abort(*state, struct test_state);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ev = tevent_context_init(ts);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_non_null(ev);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dom = talloc_zero(ts, struct sss_domain_info);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_non_null(dom);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dom->name = discard_const_p(char, TEST_DOM_NAME);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ts->nctx = mock_nctx(ts);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_non_null(ts->nctx);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm tc = create_dom_test_ctx(ts, TESTS_PATH, TEST_CONF_DB,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding TEST_DOM_NAME, TEST_ID_PROVIDER, params);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding assert_non_null(tc);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ncache = ts->ctx;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ts->rctx = mock_rctx(ts, ev, dom, ts->nctx);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald assert_non_null(ts->rctx);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ret = sss_names_init(ts, tc->confdb, TEST_DOM_NAME, &dom->names);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald assert_int_equal(ret, EOK);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe ret = sss_ncache_prepopulate(ncache, tc->confdb, ts->rctx);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald assert_int_equal(ret, EOK);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
dc80439e9fba60c753cd145cb6799409ffea9b71ronald sleep(SHORTSPAN);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
dc80439e9fba60c753cd145cb6799409ffea9b71ronald ret = sss_ncache_check_user(ncache, 1, dom, "testuser1");
dc80439e9fba60c753cd145cb6799409ffea9b71ronald assert_int_equal(ret, EEXIST);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ret = sss_ncache_check_group(ncache, 1, dom, "testgroup1");
dc80439e9fba60c753cd145cb6799409ffea9b71ronald assert_int_equal(ret, EEXIST);
dc80439e9fba60c753cd145cb6799409ffea9b71ronald}
dc80439e9fba60c753cd145cb6799409ffea9b71ronald
dc80439e9fba60c753cd145cb6799409ffea9b71ronaldint main(void)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm{
dc80439e9fba60c753cd145cb6799409ffea9b71ronald int rv;
dc80439e9fba60c753cd145cb6799409ffea9b71ronald const UnitTest tests[] = {
dc80439e9fba60c753cd145cb6799409ffea9b71ronald unit_test(test_sss_ncache_init),
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 teardown),
dc80439e9fba60c753cd145cb6799409ffea9b71ronald unit_test_setup_teardown(test_sss_ncache_service_port, setup,
dc80439e9fba60c753cd145cb6799409ffea9b71ronald teardown),
dc80439e9fba60c753cd145cb6799409ffea9b71ronald unit_test_setup_teardown(test_sss_ncache_reset_permanent, setup,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding teardown),
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding unit_test_setup_teardown(test_sss_ncache_prepopulate, setup, teardown)
090a954a1fe65b29a6f4a696f0136ef12ea0f1b1rbb };
090a954a1fe65b29a6f4a696f0136ef12ea0f1b1rbb
090a954a1fe65b29a6f4a696f0136ef12ea0f1b1rbb tests_set_cwd();
090a954a1fe65b29a6f4a696f0136ef12ea0f1b1rbb test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_SYSDB_FILE);
090a954a1fe65b29a6f4a696f0136ef12ea0f1b1rbb test_dom_suite_setup(TESTS_PATH);
090a954a1fe65b29a6f4a696f0136ef12ea0f1b1rbb
090a954a1fe65b29a6f4a696f0136ef12ea0f1b1rbb rv = run_tests(tests);
090a954a1fe65b29a6f4a696f0136ef12ea0f1b1rbb test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_SYSDB_FILE);
090a954a1fe65b29a6f4a696f0136ef12ea0f1b1rbb return rv;
090a954a1fe65b29a6f4a696f0136ef12ea0f1b1rbb}
090a954a1fe65b29a6f4a696f0136ef12ea0f1b1rbb