test_negcache.c revision d00ffd2cb4e2f17c75b466178bb645b5c9317909
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein/*
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein SSSD
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein
b99dbaab171d91e1b664397cc40e039d0c087c65fielding NSS Responder
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein Authors:
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein Pallavi Jha <pallavikumarijha@gmail.com>
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein Copyright (C) 2013 Red Hat
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein
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
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/>.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein*/
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include <stdarg.h>
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include <stdlib.h>
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include <stddef.h>
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include <setjmp.h>
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include <errno.h>
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include <unistd.h>
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include <sys/types.h>
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include <inttypes.h>
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include <cmocka.h>
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include "tests/cmocka/common_mock.h"
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include "tests/cmocka/common_mock_resp.h"
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include "responder/nss/nsssrv.h"
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include "responder/nss/nsssrv_private.h"
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include "sss_client/idmap/sss_nss_idmap.h"
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include "util/util_sss_idmap.h"
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include "lib/idmap/sss_idmap.h"
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include "util/util.h"
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include "util/util_sss_idmap.h"
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include "responder/common/responder.h"
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include "responder/common/negcache.h"
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#define PORT 21
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#define SID "S-1-2-3-4-5"
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#define PROTO "TCP"
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#define LIFETIME 200
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#define SHORTSPAN 1
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#define NAME "foo_name"
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#define UID "U-1-2-3-4-5"
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#define TESTS_PATH "tests_nss"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#define TEST_CONF_DB "test_nss_conf.ldb"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#define TEST_SYSDB_FILE "cache_nss_test.ldb"
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#define TEST_DOM_NAME "nss_test"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#define TEST_SUBDOM_NAME "test.sub"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#define TEST_ID_PROVIDER "ldap"
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1b21d7b3d97def358b2e923655edeb16613a1c31gstein/* register_cli_protocol_version is required in test since it links with
952023a04a2f9d51553babd9094fb857f1c97548trawick * responder_common.c module
1b21d7b3d97def358b2e923655edeb16613a1c31gstein */
1b21d7b3d97def358b2e923655edeb16613a1c31gsteinstruct cli_protocol_version *register_cli_protocol_version(void)
1b21d7b3d97def358b2e923655edeb16613a1c31gstein{
1b21d7b3d97def358b2e923655edeb16613a1c31gstein static struct cli_protocol_version responder_test_cli_protocol_version[] = {
f4c310fd2555c6faca1f980f00b161eadb089023gstein {0, NULL, NULL}
f4c310fd2555c6faca1f980f00b161eadb089023gstein };
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return responder_test_cli_protocol_version;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Mock NSS structure */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic struct nss_ctx *
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowemock_nctx(TALLOC_CTX *mem_ctx)
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe{
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct nss_ctx *nctx;
f4c310fd2555c6faca1f980f00b161eadb089023gstein errno_t ret;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm enum idmap_error_code err;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein nctx = talloc_zero(mem_ctx, struct nss_ctx);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!nctx) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_init(nctx, &nctx->ncache);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ret != EOK) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein talloc_free(nctx);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe nctx->neg_timeout = 10;
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe nctx->pwfield = discard_const("*");
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gstein err = sss_idmap_init(sss_idmap_talloc, nctx, sss_idmap_talloc_free,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm &nctx->idmap_ctx);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (err != IDMAP_SUCCESS) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein DEBUG(SSSDBG_FATAL_FAILURE, ("sss_idmap_init failed.\n"));
f4c310fd2555c6faca1f980f00b161eadb089023gstein talloc_free(nctx);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return nctx;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* responder context is duplicated here because linking
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe * with common_mock_resp.c would get us duplicates
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstruct resp_ctx *
f4c310fd2555c6faca1f980f00b161eadb089023gsteinmock_rctx(TALLOC_CTX *mem_ctx,
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct tevent_context *ev,
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct sss_domain_info *domains,
f4c310fd2555c6faca1f980f00b161eadb089023gstein void *pvt_ctx)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm{
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct resp_ctx *rctx;
f4c310fd2555c6faca1f980f00b161eadb089023gstein errno_t ret;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rctx = talloc_zero(mem_ctx, struct resp_ctx);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!rctx) return NULL;
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe ret = sss_hash_create(rctx, 30, &rctx->dp_request_table);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ret != EOK) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein talloc_free(rctx);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rctx->ev = ev;
f4c310fd2555c6faca1f980f00b161eadb089023gstein rctx->domains = domains;
f4c310fd2555c6faca1f980f00b161eadb089023gstein rctx->pvt_ctx = pvt_ctx;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rctx;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstruct test_state {
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct sss_nc_ctx *ctx;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm struct nss_ctx *nctx;
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct resp_ctx *rctx;
f4c310fd2555c6faca1f980f00b161eadb089023gstein};
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void setup(void **state)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein int ret;
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe struct test_state *ts;
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gstein ts = talloc(NULL, struct test_state);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_non_null(ts);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_init(ts, &ts->ctx);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EOK);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_non_null(ts->ctx);
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe *state = (void *)ts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void teardown(void **state)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct test_state *ts = talloc_get_type_abort(*state, struct test_state);
f4c310fd2555c6faca1f980f00b161eadb089023gstein talloc_free(ts);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void test_sss_ncache_init(void **state)
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe{
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe int ret;
f4c310fd2555c6faca1f980f00b161eadb089023gstein TALLOC_CTX *memctx;
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct sss_nc_ctx *ctx;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein memctx = talloc_new(NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_non_null(memctx);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_init(memctx, &ctx );
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EOK);
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe assert_non_null(ctx);
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe talloc_free(memctx);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* @test_sss_ncache_uid : test following functions
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_set_uid
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_check_uid
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void test_sss_ncache_uid(void **state)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein uid_t uid;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int ret, ttl;
f4c310fd2555c6faca1f980f00b161eadb089023gstein bool permanent;
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct test_state *ts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ttl = LIFETIME;
48f35e10f195dd594d75738fc536bb885eda537cgstein uid = getuid();
48f35e10f195dd594d75738fc536bb885eda537cgstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ts = talloc_get_type_abort(*state, struct test_state);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when uid not present in database */
91644a5f4d3e992dc208304b50e80bbb236fca89trawick ret = sss_ncache_check_uid(ts->ctx, ttl, uid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, ENOENT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when uid is present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein permanent = true;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_reset_permanent(ts->ctx);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EOK);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_set_uid(ts->ctx, permanent, uid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EOK);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_uid(ts->ctx, ttl, uid);
48f35e10f195dd594d75738fc536bb885eda537cgstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ttl = SHORTSPAN;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_set_uid(ts->ctx, permanent, uid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EOK);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
48f35e10f195dd594d75738fc536bb885eda537cgstein ret = sss_ncache_check_uid(ts->ctx, ttl, uid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein sleep(SHORTSPAN + 1);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_uid(ts->ctx, ttl, uid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein permanent = false;
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein ret = sss_ncache_set_uid(ts->ctx, permanent, uid);
48f35e10f195dd594d75738fc536bb885eda537cgstein assert_int_equal(ret, EOK);
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein ret = sss_ncache_check_uid(ts->ctx, ttl, uid);
48f35e10f195dd594d75738fc536bb885eda537cgstein assert_int_equal(ret, EEXIST);
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein sleep(SHORTSPAN + 1);
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein ret = sss_ncache_check_uid(ts->ctx, ttl, uid);
48f35e10f195dd594d75738fc536bb885eda537cgstein assert_int_equal(ret, ENOENT);
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein ret = sss_ncache_set_uid(ts->ctx, permanent, uid);
48f35e10f195dd594d75738fc536bb885eda537cgstein assert_int_equal(ret, EOK);
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein /* test when ttl is -1 with uid present in database*/
48f35e10f195dd594d75738fc536bb885eda537cgstein ttl = -1;
48f35e10f195dd594d75738fc536bb885eda537cgstein ret = sss_ncache_check_uid(ts->ctx, ttl, uid);
48f35e10f195dd594d75738fc536bb885eda537cgstein assert_int_equal(ret, EEXIST);
48f35e10f195dd594d75738fc536bb885eda537cgstein}
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein/* @test_sss_ncache_gid : test following functions
48f35e10f195dd594d75738fc536bb885eda537cgstein * sss_ncache_set_gid
48f35e10f195dd594d75738fc536bb885eda537cgstein * sss_ncache_check_gid
48f35e10f195dd594d75738fc536bb885eda537cgstein */
48f35e10f195dd594d75738fc536bb885eda537cgsteinstatic void test_sss_ncache_gid(void **state)
48f35e10f195dd594d75738fc536bb885eda537cgstein{
48f35e10f195dd594d75738fc536bb885eda537cgstein gid_t gid;
48f35e10f195dd594d75738fc536bb885eda537cgstein int ret, ttl;
48f35e10f195dd594d75738fc536bb885eda537cgstein bool permanent;
48f35e10f195dd594d75738fc536bb885eda537cgstein struct test_state *ts;
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein ttl = LIFETIME;
48f35e10f195dd594d75738fc536bb885eda537cgstein gid = getgid();
48f35e10f195dd594d75738fc536bb885eda537cgstein ts = talloc_get_type_abort(*state, struct test_state);
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein /* test when gid is not present in database */
48f35e10f195dd594d75738fc536bb885eda537cgstein ret = sss_ncache_check_gid(ts->ctx, ttl, gid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, ENOENT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when gid is present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein permanent = true;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_set_gid(ts->ctx, permanent, gid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EOK);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_gid(ts->ctx, ttl, gid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein permanent = false;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_set_uid(ts->ctx, permanent, gid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EOK);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
48f35e10f195dd594d75738fc536bb885eda537cgstein ret = sss_ncache_check_uid(ts->ctx, ttl, gid);
48f35e10f195dd594d75738fc536bb885eda537cgstein assert_int_equal(ret, EEXIST);
48f35e10f195dd594d75738fc536bb885eda537cgstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* test when ttl is -1 with gid present in database*/
f4c310fd2555c6faca1f980f00b161eadb089023gstein ttl = -1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_gid(ts->ctx, ttl, gid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* @test_sss_ncache_sid : test following functions
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_set_sid
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_check_sid
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void test_sss_ncache_sid(void **state)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein int ret, ttl;
f4c310fd2555c6faca1f980f00b161eadb089023gstein bool permanent;
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *sid = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct test_state *ts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ttl = LIFETIME;
f4c310fd2555c6faca1f980f00b161eadb089023gstein sid = SID;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ts = talloc_get_type_abort(*state, struct test_state);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*test when sid in not present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_sid(ts->ctx, ttl, sid);
f958dac1550254a59b45f4655138bb34dad5e76egstein assert_int_equal(ret, ENOENT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when sid is present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein permanent = true;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_set_sid(ts->ctx, permanent, sid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EOK);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_sid(ts->ctx, ttl, sid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein permanent = false;
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein ret = sss_ncache_set_sid(ts->ctx, permanent, sid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EOK);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein ret = sss_ncache_check_sid(ts->ctx, ttl, sid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when ttl is -1 with sid present in database*/
f4c310fd2555c6faca1f980f00b161eadb089023gstein ttl = -1;
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein ret = sss_ncache_check_sid(ts->ctx, ttl, sid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* @test_sss_ncache_user : test following functions
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein * sss_ncache_check_user
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_set_user
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void test_sss_ncache_user(void **state)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f39230a531b23d94f86a087963299bbe2e431a4agstein int ret, ttl;
f39230a531b23d94f86a087963299bbe2e431a4agstein bool permanent;
f39230a531b23d94f86a087963299bbe2e431a4agstein const char *name = NAME;
f39230a531b23d94f86a087963299bbe2e431a4agstein struct test_state *ts;
f39230a531b23d94f86a087963299bbe2e431a4agstein struct sss_domain_info *dom;
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein ttl = LIFETIME;
f39230a531b23d94f86a087963299bbe2e431a4agstein ts = talloc_get_type_abort(*state, struct test_state);
f39230a531b23d94f86a087963299bbe2e431a4agstein dom = talloc(ts, struct sss_domain_info);
f39230a531b23d94f86a087963299bbe2e431a4agstein dom->name = discard_const(NAME);
1e2133fe37e6cbcd683233057ef62236bc8e5826trawick
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein /* test when domain name is not present in database */
f39230a531b23d94f86a087963299bbe2e431a4agstein dom->case_sensitive = false;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ret = sss_ncache_check_user(ts->ctx, ttl, dom, name);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein assert_int_equal(ret, ENOENT);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein dom->case_sensitive = true;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ret = sss_ncache_check_user(ts->ctx, ttl, dom, name);
f39230a531b23d94f86a087963299bbe2e431a4agstein assert_int_equal(ret, ENOENT);
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein /* test when domain name is present in database */
f39230a531b23d94f86a087963299bbe2e431a4agstein permanent = true;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ret = sss_ncache_set_user(ts->ctx, permanent, dom, name);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein assert_int_equal(ret, EOK);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ret = sss_ncache_check_user(ts->ctx, ttl, dom, name);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein assert_int_equal(ret, EEXIST);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein permanent = false;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ret = sss_ncache_set_user(ts->ctx, permanent, dom, name);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein assert_int_equal(ret, EOK);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ret = sss_ncache_check_user(ts->ctx, ttl, dom, name);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein assert_int_equal(ret, EEXIST);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein /* test when ttl is -1 with domain name present in database */
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ttl = -1;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ret = sss_ncache_check_user(ts->ctx, ttl, dom, name);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein assert_int_equal(ret, EEXIST);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein}
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein/* @test_sss_ncache_group : test following functions
f39230a531b23d94f86a087963299bbe2e431a4agstein * sss_ncache_check_group
f39230a531b23d94f86a087963299bbe2e431a4agstein * sss_ncache_set_group
f39230a531b23d94f86a087963299bbe2e431a4agstein */
f39230a531b23d94f86a087963299bbe2e431a4agsteinstatic void test_sss_ncache_group(void **state)
f39230a531b23d94f86a087963299bbe2e431a4agstein{
f39230a531b23d94f86a087963299bbe2e431a4agstein int ret, ttl;
f39230a531b23d94f86a087963299bbe2e431a4agstein bool permanent;
f39230a531b23d94f86a087963299bbe2e431a4agstein const char *name = NAME;
f39230a531b23d94f86a087963299bbe2e431a4agstein struct test_state *ts;
f39230a531b23d94f86a087963299bbe2e431a4agstein struct sss_domain_info *dom;
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein ttl = LIFETIME;
f39230a531b23d94f86a087963299bbe2e431a4agstein ts = talloc_get_type_abort(*state, struct test_state);
f39230a531b23d94f86a087963299bbe2e431a4agstein dom = talloc(ts, struct sss_domain_info);
f39230a531b23d94f86a087963299bbe2e431a4agstein dom->name = discard_const(NAME);
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein /* test when domain name is not present in database */
f39230a531b23d94f86a087963299bbe2e431a4agstein dom->case_sensitive = false;
f39230a531b23d94f86a087963299bbe2e431a4agstein ret = sss_ncache_check_group(ts->ctx, ttl, dom, name);
f39230a531b23d94f86a087963299bbe2e431a4agstein assert_int_equal(ret, ENOENT);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein
f39230a531b23d94f86a087963299bbe2e431a4agstein dom->case_sensitive = true;
f39230a531b23d94f86a087963299bbe2e431a4agstein ret = sss_ncache_check_group(ts->ctx, ttl, dom, name);
f39230a531b23d94f86a087963299bbe2e431a4agstein assert_int_equal(ret, ENOENT);
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein /* test when domain name is present in database */
f39230a531b23d94f86a087963299bbe2e431a4agstein permanent = true;
f39230a531b23d94f86a087963299bbe2e431a4agstein ret = sss_ncache_set_group(ts->ctx, permanent, dom, name);
f39230a531b23d94f86a087963299bbe2e431a4agstein assert_int_equal(ret, EOK);
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein ret = sss_ncache_check_group(ts->ctx, ttl, dom, name);
f39230a531b23d94f86a087963299bbe2e431a4agstein assert_int_equal(ret, EEXIST);
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein permanent = false;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_set_group(ts->ctx, permanent, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EOK);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_group(ts->ctx, ttl, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when ttl is -1 with domain name present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ttl = -1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_group(ts->ctx, ttl, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* @test_sss_ncache_netgr : test following functions
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_check_netgr
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_set_netgr
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void test_sss_ncache_netgr(void **state)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm int ret, ttl;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm bool permanent;
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *name = NAME;
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct test_state *ts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct sss_domain_info *dom;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ttl = LIFETIME;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ts = talloc_get_type_abort(*state, struct test_state);
f4c310fd2555c6faca1f980f00b161eadb089023gstein dom = talloc(ts, struct sss_domain_info);
f4c310fd2555c6faca1f980f00b161eadb089023gstein dom->name = discard_const(NAME);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when domain name is not present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein dom->case_sensitive = false;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_netgr(ts->ctx, ttl, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, ENOENT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein dom->case_sensitive = true;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_netgr(ts->ctx, ttl, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, ENOENT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when domain name is present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein permanent = true;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_set_netgr(ts->ctx, permanent, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EOK);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_netgr(ts->ctx, ttl, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein permanent = false;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_set_netgr(ts->ctx, permanent, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EOK);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_netgr(ts->ctx, ttl, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when ttl is -1 with domain name present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ttl = -1;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ret = sss_ncache_check_netgr(ts->ctx, ttl, dom, name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* @test_sss_ncache_service_name : test following functions
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * sss_ncache_check_service
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_set_service_name
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void test_sss_ncache_service_name(void **state)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein int ret, ttl;
f4c310fd2555c6faca1f980f00b161eadb089023gstein bool permanent;
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *name = NAME;
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct test_state *ts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct sss_domain_info *dom;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ttl = LIFETIME;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ts = talloc_get_type_abort(*state, struct test_state);
f4c310fd2555c6faca1f980f00b161eadb089023gstein dom = talloc(ts, struct sss_domain_info);
f4c310fd2555c6faca1f980f00b161eadb089023gstein dom->name = discard_const(NAME);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when domain name and protocol are not present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein dom->case_sensitive = false;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service(ts->ctx, ttl, dom, name, PROTO);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm assert_int_equal(ret, ENOENT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein dom->case_sensitive = true;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service(ts->ctx, ttl, dom, name, PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, ENOENT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when domain name and protocol are present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein permanent = true;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_set_service_name(ts->ctx, permanent, dom, name, PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EOK);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service(ts->ctx, ttl, dom, name, PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein permanent = false;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_set_service_name(ts->ctx, permanent, dom, name, PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EOK);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service(ts->ctx, ttl, dom, name, PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when ttl is -1 with domain name present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ttl = -1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service(ts->ctx, ttl, dom, name, PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* @test_sss_ncache_service_port : test following functions
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_check_service_port
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sss_ncache_set_service_port
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void test_sss_ncache_service_port(void **state)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein int ret, ttl;
f4c310fd2555c6faca1f980f00b161eadb089023gstein bool permanent;
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct test_state *ts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct sss_domain_info *dom;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ttl = LIFETIME;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ts = talloc_get_type_abort(*state, struct test_state);
f4c310fd2555c6faca1f980f00b161eadb089023gstein dom = talloc(ts, struct sss_domain_info);
f4c310fd2555c6faca1f980f00b161eadb089023gstein dom->name = discard_const(NAME);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when domain name, port and protocol are not present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein dom->case_sensitive = false;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service_port(ts->ctx, ttl, dom, (uint16_t)PORT,
f4c310fd2555c6faca1f980f00b161eadb089023gstein PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, ENOENT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein dom->case_sensitive = true;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service_port(ts->ctx, ttl, dom, (uint16_t)PORT,
f4c310fd2555c6faca1f980f00b161eadb089023gstein PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, ENOENT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when domain name, port and protocol are present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein permanent = true;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_set_service_port(ts->ctx, permanent, dom, (uint16_t)PORT,
f4c310fd2555c6faca1f980f00b161eadb089023gstein PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EOK);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service_port(ts->ctx, ttl, dom, (uint16_t)PORT,
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein permanent = false;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_set_service_port(ts->ctx, permanent, dom, (uint16_t)PORT,
f4c310fd2555c6faca1f980f00b161eadb089023gstein PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EOK);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service_port(ts->ctx, ttl, dom, (uint16_t)PORT,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* test when ttl is -1 with domain name present in database */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ttl = -1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_service_port(ts->ctx, ttl, dom, (uint16_t)PORT,
f4c310fd2555c6faca1f980f00b161eadb089023gstein PROTO);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void test_sss_ncache_reset_permanent(void **state)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein int ret;
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct test_state *ts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ts = talloc_get_type_abort(*state, struct test_state);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_reset_permanent(ts->ctx);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EOK);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void test_sss_ncache_prepopulate(void **state)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein int ret;
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct test_state *ts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct tevent_context *ev;
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct sss_nc_ctx *ncache;
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct sss_test_ctx *tc;
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct sss_domain_info *dom;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct sss_test_conf_param params[] = {
f4c310fd2555c6faca1f980f00b161eadb089023gstein { "filter_users", "testuser1" },
f4c310fd2555c6faca1f980f00b161eadb089023gstein { "filter_groups", "testgroup1" },
f4c310fd2555c6faca1f980f00b161eadb089023gstein { NULL, NULL },
f4c310fd2555c6faca1f980f00b161eadb089023gstein };
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ts = talloc_get_type_abort(*state, struct test_state);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ev = tevent_context_init(ts);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_non_null(ev);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein dom = talloc_zero(ts, struct sss_domain_info);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_non_null(dom);
f4c310fd2555c6faca1f980f00b161eadb089023gstein dom->name = discard_const(NAME);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ts->nctx = mock_nctx(ts);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_non_null(ts->nctx);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein tc = create_dom_test_ctx(ts, TESTS_PATH, TEST_CONF_DB,
f4c310fd2555c6faca1f980f00b161eadb089023gstein TEST_SYSDB_FILE, NAME,
f4c310fd2555c6faca1f980f00b161eadb089023gstein TEST_ID_PROVIDER, params);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_non_null(tc);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ncache = ts->ctx;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ts->rctx = mock_rctx(ts, ev, dom, ts->nctx);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_non_null(ts->rctx);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_names_init(ts, tc->confdb, TEST_DOM_NAME, &dom->names);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EOK);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_prepopulate(ncache, tc->confdb, ts->rctx);
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EOK);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein sleep(SHORTSPAN);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_user(ncache, 1, dom, "testuser1");
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = sss_ncache_check_group(ncache, 1, dom, "testgroup1");
f4c310fd2555c6faca1f980f00b161eadb089023gstein assert_int_equal(ret, EEXIST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinint main(void)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein int rv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein const UnitTest tests[] = {
f4c310fd2555c6faca1f980f00b161eadb089023gstein unit_test(test_sss_ncache_init),
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 teardown),
f4c310fd2555c6faca1f980f00b161eadb089023gstein unit_test_setup_teardown(test_sss_ncache_service_port, setup,
f4c310fd2555c6faca1f980f00b161eadb089023gstein teardown),
f4c310fd2555c6faca1f980f00b161eadb089023gstein unit_test_setup_teardown(test_sss_ncache_reset_permanent, setup,
f4c310fd2555c6faca1f980f00b161eadb089023gstein teardown),
f4c310fd2555c6faca1f980f00b161eadb089023gstein unit_test_setup_teardown(test_sss_ncache_prepopulate, setup, teardown)
f4c310fd2555c6faca1f980f00b161eadb089023gstein };
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein tests_set_cwd();
f4c310fd2555c6faca1f980f00b161eadb089023gstein test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_SYSDB_FILE);
f4c310fd2555c6faca1f980f00b161eadb089023gstein test_dom_suite_setup(TESTS_PATH);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rv = run_tests(tests);
f4c310fd2555c6faca1f980f00b161eadb089023gstein test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_SYSDB_FILE);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein