d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/*
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha SSSD
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha NSS Responder
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha Authors:
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha Pallavi Jha <pallavikumarijha@gmail.com>
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha Copyright (C) 2013 Red Hat
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha This program is free software; you can redistribute it and/or modify
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha it under the terms of the GNU General Public License as published by
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha the Free Software Foundation; either version 3 of the License, or
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha (at your option) any later version.
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha This program is distributed in the hope that it will be useful,
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha but WITHOUT ANY WARRANTY; without even the implied warranty of
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha GNU General Public License for more details.
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha You should have received a copy of the GNU General Public License
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha along with this program. If not, see <http://www.gnu.org/licenses/>.
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha*/
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#include <stdarg.h>
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#include <stdlib.h>
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#include <stddef.h>
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#include <setjmp.h>
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#include <errno.h>
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#include <unistd.h>
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#include <sys/types.h>
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#include <inttypes.h>
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#include <cmocka.h>
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#include "tests/cmocka/common_mock.h"
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#include "tests/cmocka/common_mock_resp.h"
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina#include "responder/nss/nss_private.h"
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#include "sss_client/idmap/sss_nss_idmap.h"
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#include "util/util_sss_idmap.h"
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#include "lib/idmap/sss_idmap.h"
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#include "util/util.h"
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#include "util/util_sss_idmap.h"
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#include "responder/common/responder.h"
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#include "responder/common/negcache.h"
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#define PORT 21
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#define SID "S-1-2-3-4-5"
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose#define CERT "MIIECTCCAvGgAwIBAgIBCTANBgkqhkiG9w0BAQsFADA0MRIwEAYDVQQKDAlJUEEuREVWRUwxHjAcBgNVBAMMFUNlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNTA0MjgxMDIxMTFaFw0xNzA0MjgxMDIxMTFaMDIxEjAQBgNVBAoMCUlQQS5ERVZFTDEcMBoGA1UEAwwTaXBhLWRldmVsLmlwYS5kZXZlbDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALIykqtHuAwTVEofHikG/9BQy/dfeZFlsTkBg2qtnnc78w3XufbcnkpJp9Bmcsy/d9beqf5nlsxJ8TcjLsRQ9Ou6YtQjTfM3OILuOz8s0ICbF6qb66bd9hX/BrLO/9+KnpWFSR+E/YEmzgYyDTbKfBWBaGuPPrOi/K6vwkRYFZVA/FYZkYDtQhFmBO884HYzS4P6frRH3PvtRqWNCmaHpe97dGKsvnM2ybT+IMSB8/54GajQr3+BciRh2XaT4wvSTxkXM1fUgrDxqAP2AZmpuIyDyboZh+rWOwbrTPfx5SipELZG3uHhP8HMcr4qQ8b20LWgxCRuT73sIooHET350xUCAwEAAaOCASYwggEiMB8GA1UdIwQYMBaAFPKdQk4PxEglWC8czg+hPyLIVciRMDsGCCsGAQUFBwEBBC8wLTArBggrBgEFBQcwAYYfaHR0cDovL2lwYS1jYS5pcGEuZGV2ZWwvY2Evb2NzcDAOBgNVHQ8BAf8EBAMCBPAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMHQGA1UdHwRtMGswaaAxoC+GLWh0dHA6Ly9pcGEtY2EuaXBhLmRldmVsL2lwYS9jcmwvTWFzdGVyQ1JMLmJpbqI0pDIwMDEOMAwGA1UECgwFaXBhY2ExHjAcBgNVBAMMFUNlcnRpZmljYXRlIEF1dGhvcml0eTAdBgNVHQ4EFgQULSs/y/Wy/zIsqMIc3b2MgB7dMYIwDQYJKoZIhvcNAQELBQADggEBAJpHLlCnTR1TD8lxQgzl2n1JZOeryN/fAsGH0Vve2m8r5PC+ugnfAoULiuabBn1pOGxy/0x7Kg0/Iy8WRv8Fk7DqJCjXEqFXuFkZJfNDCtP9DzeNuMoV50iKoMfHS38BPFjXN+X/fSsBrA2fUWrlQCTmXlUN97gvQqxt5Slrxgukvxm9OSfu/sWz22LUvtJHupYwWv1iALgnXS86lAuVNYVALLxn34r58XsZlj5CSBMjBJWpaxEzgUdag3L2IPqOQXuPd0d8x11G9E/9gQquOSe2aiZjsdO/VYOCmzZsM2QPUMBVlBPDhfTVcWXQwN385uycW/ARtSzzSME2jKKWSIQ="
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#define PROTO "TCP"
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#define SHORTSPAN 1
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#define NAME "foo_name"
50c9d542e8bf641412debaa82a4dcf67ddb72258Lukas Slebodnik#define TESTS_PATH "tp_" BASE_FILE_STEM
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#define TEST_CONF_DB "test_nss_conf.ldb"
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#define TEST_DOM_NAME "nss_test"
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha#define TEST_ID_PROVIDER "ldap"
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* register_cli_protocol_version is required in test since it links with
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * responder_common.c module
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastruct cli_protocol_version *register_cli_protocol_version(void)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha{
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha static struct cli_protocol_version responder_test_cli_protocol_version[] = {
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha {0, NULL, NULL}
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha };
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha return responder_test_cli_protocol_version;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha}
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* Mock NSS structure */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastatic struct nss_ctx *
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhamock_nctx(TALLOC_CTX *mem_ctx)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha{
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct nss_ctx *nctx;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha enum idmap_error_code err;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha nctx = talloc_zero(mem_ctx, struct nss_ctx);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha if (!nctx) {
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha return NULL;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha }
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha nctx->pwfield = discard_const("*");
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha err = sss_idmap_init(sss_idmap_talloc, nctx, sss_idmap_talloc_free,
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha &nctx->idmap_ctx);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha if (err != IDMAP_SUCCESS) {
c02b8482375837b57cb618ed56d4bede0e006d9dPavel Březina DEBUG(SSSDBG_FATAL_FAILURE, "sss_idmap_init failed.\n");
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha talloc_free(nctx);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha return NULL;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha }
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha return nctx;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha}
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastruct test_state {
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct sss_nc_ctx *ctx;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct nss_ctx *nctx;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct resp_ctx *rctx;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha};
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int setup(void **state)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha{
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha int ret;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct test_state *ts;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc(NULL, struct test_state);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_non_null(ts);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech ret = sss_ncache_init(ts, SHORTSPAN, 0, &ts->ctx);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_non_null(ts->ctx);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha *state = (void *)ts;
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha}
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int teardown(void **state)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha{
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct test_state *ts = talloc_get_type_abort(*state, struct test_state);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha talloc_free(ts);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha}
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastatic void test_sss_ncache_init(void **state)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha{
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha int ret;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha TALLOC_CTX *memctx;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct sss_nc_ctx *ctx;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha memctx = talloc_new(NULL);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_non_null(memctx);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech ret = sss_ncache_init(memctx, SHORTSPAN, 0, &ctx);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_non_null(ctx);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha talloc_free(memctx);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha}
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* @test_sss_ncache_uid : test following functions
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_set_uid
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_check_uid
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastatic void test_sss_ncache_uid(void **state)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha{
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha uid_t uid;
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech int ret;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha bool permanent;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct test_state *ts;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha uid = getuid();
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when uid not present in database */
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_uid(ts->ctx, NULL, uid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, ENOENT);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when uid is present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha permanent = true;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_reset_permanent(ts->ctx);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
e1aed98d7c195f844ac8e85050d04f3ca5f899b3Sumit Bose ret = sss_ncache_set_uid(ts->ctx, permanent, NULL, uid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_uid(ts->ctx, NULL, uid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
e1aed98d7c195f844ac8e85050d04f3ca5f899b3Sumit Bose ret = sss_ncache_set_uid(ts->ctx, permanent, NULL, uid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_uid(ts->ctx, NULL, uid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha sleep(SHORTSPAN + 1);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_uid(ts->ctx, NULL, uid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha permanent = false;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
e1aed98d7c195f844ac8e85050d04f3ca5f899b3Sumit Bose ret = sss_ncache_set_uid(ts->ctx, permanent, NULL, uid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_uid(ts->ctx, NULL, uid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha sleep(SHORTSPAN + 1);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_uid(ts->ctx, NULL, uid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, ENOENT);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
e1aed98d7c195f844ac8e85050d04f3ca5f899b3Sumit Bose ret = sss_ncache_set_uid(ts->ctx, permanent, NULL, uid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha}
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* @test_sss_ncache_gid : test following functions
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_set_gid
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_check_gid
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastatic void test_sss_ncache_gid(void **state)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha{
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha gid_t gid;
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech int ret;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha bool permanent;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct test_state *ts;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha gid = getgid();
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when gid is not present in database */
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_gid(ts->ctx, NULL, gid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, ENOENT);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when gid is present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha permanent = true;
e1aed98d7c195f844ac8e85050d04f3ca5f899b3Sumit Bose ret = sss_ncache_set_gid(ts->ctx, permanent, NULL, gid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_gid(ts->ctx, NULL, gid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha permanent = false;
ee4be57409e157af0a57228605ef8e07f6d4fa1bPetr Cech ret = sss_ncache_set_gid(ts->ctx, permanent, NULL, gid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_gid(ts->ctx, NULL, gid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha}
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* @test_sss_ncache_sid : test following functions
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_set_sid
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_check_sid
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastatic void test_sss_ncache_sid(void **state)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha{
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech int ret;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha bool permanent;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha const char *sid = NULL;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct test_state *ts;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha sid = SID;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /*test when sid in not present in database */
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_sid(ts->ctx, sid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, ENOENT);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when sid is present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha permanent = true;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_sid(ts->ctx, permanent, sid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_sid(ts->ctx, sid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha permanent = false;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_sid(ts->ctx, permanent, sid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_sid(ts->ctx, sid);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha}
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose/* @test_sss_ncache_cert : test following functions
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose * sss_ncache_set_cert
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose * sss_ncache_check_cert_
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose */
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bosestatic void test_sss_ncache_cert(void **state)
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose{
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech int ret;
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose bool permanent;
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose const char *cert = NULL;
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose struct test_state *ts;
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose cert = CERT;
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose ts = talloc_get_type_abort(*state, struct test_state);
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose /*test when cert in not present in database */
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_cert(ts->ctx, cert);
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose assert_int_equal(ret, ENOENT);
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose /* test when cert is present in database */
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose permanent = true;
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose ret = sss_ncache_set_cert(ts->ctx, permanent, cert);
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose assert_int_equal(ret, EOK);
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_cert(ts->ctx, cert);
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose assert_int_equal(ret, EEXIST);
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose permanent = false;
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose ret = sss_ncache_set_cert(ts->ctx, permanent, cert);
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose assert_int_equal(ret, EOK);
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_cert(ts->ctx, cert);
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose assert_int_equal(ret, EEXIST);
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose}
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* @test_sss_ncache_user : test following functions
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_check_user
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_set_user
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastatic void test_sss_ncache_user(void **state)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha{
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech int ret;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha bool permanent;
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek char *name;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct test_state *ts;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct sss_domain_info *dom;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha dom = talloc(ts, struct sss_domain_info);
1f5a03646ce55efa2ea415248ed5fe6375139305Lukas Slebodnik dom->name = discard_const_p(char, TEST_DOM_NAME);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek name = sss_create_internal_fqname(ts, NAME, dom->name);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek assert_non_null(name);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name is not present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha dom->case_sensitive = false;
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_user(ts->ctx, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, ENOENT);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha dom->case_sensitive = true;
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_user(ts->ctx, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, ENOENT);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name is present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha permanent = true;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_user(ts->ctx, permanent, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_user(ts->ctx, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha permanent = false;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_user(ts->ctx, permanent, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_user(ts->ctx, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek talloc_free(name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha}
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* @test_sss_ncache_group : test following functions
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_check_group
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_set_group
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastatic void test_sss_ncache_group(void **state)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha{
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech int ret;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha bool permanent;
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek char *name;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct test_state *ts;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct sss_domain_info *dom;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha dom = talloc(ts, struct sss_domain_info);
1f5a03646ce55efa2ea415248ed5fe6375139305Lukas Slebodnik dom->name = discard_const_p(char, TEST_DOM_NAME);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek name = sss_create_internal_fqname(ts, NAME, dom->name);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek assert_non_null(name);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name is not present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha dom->case_sensitive = false;
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_group(ts->ctx, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, ENOENT);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha dom->case_sensitive = true;
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_group(ts->ctx, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, ENOENT);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name is present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha permanent = true;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_group(ts->ctx, permanent, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_group(ts->ctx, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha permanent = false;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_group(ts->ctx, permanent, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_group(ts->ctx, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek talloc_free(name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha}
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* @test_sss_ncache_netgr : test following functions
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_check_netgr
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_set_netgr
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastatic void test_sss_ncache_netgr(void **state)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha{
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech int ret;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha bool permanent;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha const char *name = NAME;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct test_state *ts;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct sss_domain_info *dom;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha dom = talloc(ts, struct sss_domain_info);
1f5a03646ce55efa2ea415248ed5fe6375139305Lukas Slebodnik dom->name = discard_const_p(char, TEST_DOM_NAME);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name is not present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha dom->case_sensitive = false;
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_netgr(ts->ctx, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, ENOENT);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha dom->case_sensitive = true;
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_netgr(ts->ctx, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, ENOENT);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name is present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha permanent = true;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_netgr(ts->ctx, permanent, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_netgr(ts->ctx, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha permanent = false;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_netgr(ts->ctx, permanent, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_netgr(ts->ctx, dom, name);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha}
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* @test_sss_ncache_service_name : test following functions
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_check_service
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_set_service_name
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastatic void test_sss_ncache_service_name(void **state)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha{
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech int ret;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha bool permanent;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha const char *name = NAME;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct test_state *ts;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct sss_domain_info *dom;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha dom = talloc(ts, struct sss_domain_info);
1f5a03646ce55efa2ea415248ed5fe6375139305Lukas Slebodnik dom->name = discard_const_p(char, TEST_DOM_NAME);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name and protocol are not present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha dom->case_sensitive = false;
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_service(ts->ctx, dom, name, PROTO);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, ENOENT);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha dom->case_sensitive = true;
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_service(ts->ctx, dom, name, PROTO);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, ENOENT);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name and protocol are present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha permanent = true;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_service_name(ts->ctx, permanent, dom, name, PROTO);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_service(ts->ctx, dom, name, PROTO);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha permanent = false;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_service_name(ts->ctx, permanent, dom, name, PROTO);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_service(ts->ctx, dom, name, PROTO);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha}
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha/* @test_sss_ncache_service_port : test following functions
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_check_service_port
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha * sss_ncache_set_service_port
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastatic void test_sss_ncache_service_port(void **state)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha{
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech int ret;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha bool permanent;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct test_state *ts;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct sss_domain_info *dom;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha dom = talloc(ts, struct sss_domain_info);
1f5a03646ce55efa2ea415248ed5fe6375139305Lukas Slebodnik dom->name = discard_const_p(char, TEST_DOM_NAME);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name, port and protocol are not present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha dom->case_sensitive = false;
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_service_port(ts->ctx, dom, (uint16_t)PORT,
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha PROTO);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, ENOENT);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha dom->case_sensitive = true;
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_service_port(ts->ctx, dom, (uint16_t)PORT,
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha PROTO);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, ENOENT);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha /* test when domain name, port and protocol are present in database */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha permanent = true;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_service_port(ts->ctx, permanent, dom, (uint16_t)PORT,
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha PROTO);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_service_port(ts->ctx, dom, (uint16_t)PORT,
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha PROTO);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha permanent = false;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_set_service_port(ts->ctx, permanent, dom, (uint16_t)PORT,
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha PROTO);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_service_port(ts->ctx, dom, (uint16_t)PORT,
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha PROTO);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha}
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastatic void test_sss_ncache_reset_permanent(void **state)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha{
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha int ret;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct test_state *ts;
d338bb46b8c03c33e6182e725911af6d778bcf00Jakub Hrozek const bool permanent = true;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
d338bb46b8c03c33e6182e725911af6d778bcf00Jakub Hrozek
e1aed98d7c195f844ac8e85050d04f3ca5f899b3Sumit Bose ret = sss_ncache_set_uid(ts->ctx, permanent, NULL, 0);
d338bb46b8c03c33e6182e725911af6d778bcf00Jakub Hrozek assert_int_equal(ret, EOK);
d338bb46b8c03c33e6182e725911af6d778bcf00Jakub Hrozek
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_uid(ts->ctx, NULL, 0);
d338bb46b8c03c33e6182e725911af6d778bcf00Jakub Hrozek assert_int_equal(ret, EEXIST);
d338bb46b8c03c33e6182e725911af6d778bcf00Jakub Hrozek
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_reset_permanent(ts->ctx);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d338bb46b8c03c33e6182e725911af6d778bcf00Jakub Hrozek
0393f0d44ac92035de29a8bc8b2005db6d90b640Petr Cech ret = sss_ncache_check_uid(ts->ctx, NULL, 0);
d338bb46b8c03c33e6182e725911af6d778bcf00Jakub Hrozek assert_int_equal(ret, ENOENT);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha}
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozekstatic int check_user_in_ncache(struct sss_nc_ctx *ctx,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek struct sss_domain_info *dom,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek const char *name)
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek{
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek char *fqdn;
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek int ret;
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek fqdn = sss_create_internal_fqname(ctx, name, dom->name);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = sss_ncache_check_user(ctx, dom, fqdn);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek talloc_free(fqdn);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek return ret;
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek}
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozekstatic int check_group_in_ncache(struct sss_nc_ctx *ctx,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek struct sss_domain_info *dom,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek const char *name)
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek{
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek char *fqdn;
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek int ret;
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek fqdn = sss_create_internal_fqname(ctx, name, dom->name);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = sss_ncache_check_group(ctx, dom, fqdn);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek talloc_free(fqdn);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek return ret;
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek}
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidênciostatic int check_uid_in_ncache(struct sss_nc_ctx *ctx,
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio uid_t uid)
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio{
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio int ret;
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio ret = sss_ncache_check_uid(ctx, NULL, uid);
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio return ret;
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio}
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidênciostatic int check_gid_in_ncache(struct sss_nc_ctx *ctx,
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio gid_t gid)
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio{
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio int ret;
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio ret = sss_ncache_check_gid(ctx, NULL, gid);
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio return ret;
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio}
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhastatic void test_sss_ncache_prepopulate(void **state)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha{
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha int ret;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct test_state *ts;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct tevent_context *ev;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct sss_nc_ctx *ncache;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct sss_test_ctx *tc;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct sss_domain_info *dom;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha struct sss_test_conf_param params[] = {
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek { "filter_users", "testuser1, testuser2@"TEST_DOM_NAME", testuser3@somedomain" },
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek { "filter_groups", "testgroup1, testgroup2@"TEST_DOM_NAME", testgroup3@somedomain" },
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha { NULL, NULL },
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha };
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ev = tevent_context_init(ts);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_non_null(ev);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha dom = talloc_zero(ts, struct sss_domain_info);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_non_null(dom);
1f5a03646ce55efa2ea415248ed5fe6375139305Lukas Slebodnik dom->name = discard_const_p(char, TEST_DOM_NAME);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts->nctx = mock_nctx(ts);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_non_null(ts->nctx);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha tc = create_dom_test_ctx(ts, TESTS_PATH, TEST_CONF_DB,
1f5a03646ce55efa2ea415248ed5fe6375139305Lukas Slebodnik TEST_DOM_NAME, TEST_ID_PROVIDER, params);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_non_null(tc);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ncache = ts->ctx;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ts->rctx = mock_rctx(ts, ev, dom, ts->nctx);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_non_null(ts->rctx);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_names_init(ts, tc->confdb, TEST_DOM_NAME, &dom->names);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha ret = sss_ncache_prepopulate(ncache, tc->confdb, ts->rctx);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EOK);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha sleep(SHORTSPAN);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom, "testuser1");
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom, "testgroup1");
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha assert_int_equal(ret, EEXIST);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom, "testuser2");
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek assert_int_equal(ret, EEXIST);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom, "testgroup2");
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek assert_int_equal(ret, EEXIST);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom, "testuser3");
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek assert_int_equal(ret, ENOENT);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom, "testgroup3");
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek assert_int_equal(ret, ENOENT);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom, "testuser3@somedomain");
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek assert_int_equal(ret, ENOENT);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom, "testgroup3@somedomain");
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek assert_int_equal(ret, ENOENT);
e54764d62bfcc48770d9b2578132979aa58636e5Fabiano Fidêncio
e54764d62bfcc48770d9b2578132979aa58636e5Fabiano Fidêncio ret = check_user_in_ncache(ncache, dom, "root");
e54764d62bfcc48770d9b2578132979aa58636e5Fabiano Fidêncio assert_int_equal(ret, EEXIST);
e54764d62bfcc48770d9b2578132979aa58636e5Fabiano Fidêncio
e54764d62bfcc48770d9b2578132979aa58636e5Fabiano Fidêncio ret = check_group_in_ncache(ncache, dom, "root");
e54764d62bfcc48770d9b2578132979aa58636e5Fabiano Fidêncio assert_int_equal(ret, EEXIST);
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio ret = check_uid_in_ncache(ncache, 0);
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio assert_int_equal(ret, EEXIST);
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio ret = check_gid_in_ncache(ncache, 0);
b4b3d0642120ca05f63959fe2f317a6b93031929Fabiano Fidêncio assert_int_equal(ret, EEXIST);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek}
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozekstatic void test_sss_ncache_default_domain_suffix(void **state)
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek{
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek int ret;
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek struct test_state *ts;
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek struct tevent_context *ev;
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek struct sss_nc_ctx *ncache;
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek struct sss_test_ctx *tc;
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek struct sss_domain_info *dom;
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek struct sss_test_conf_param params[] = {
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek { "filter_users", "testuser1, testuser2@"TEST_DOM_NAME", testuser3@somedomain" },
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek { "filter_groups", "testgroup1, testgroup2@"TEST_DOM_NAME", testgroup3@somedomain" },
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek { NULL, NULL },
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek };
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek ts = talloc_get_type_abort(*state, struct test_state);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek ev = tevent_context_init(ts);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek assert_non_null(ev);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek dom = talloc_zero(ts, struct sss_domain_info);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek assert_non_null(dom);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek dom->name = discard_const_p(char, TEST_DOM_NAME);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek ts->nctx = mock_nctx(ts);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek assert_non_null(ts->nctx);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek tc = create_dom_test_ctx(ts, TESTS_PATH, TEST_CONF_DB,
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek TEST_DOM_NAME, TEST_ID_PROVIDER, params);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek assert_non_null(tc);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek ncache = ts->ctx;
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek ts->rctx = mock_rctx(ts, ev, dom, ts->nctx);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek assert_non_null(ts->rctx);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek ts->rctx->default_domain = discard_const(TEST_DOM_NAME);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek ret = sss_names_init(ts, tc->confdb, TEST_DOM_NAME, &dom->names);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek assert_int_equal(ret, EOK);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek ret = sss_ncache_prepopulate(ncache, tc->confdb, ts->rctx);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek assert_int_equal(ret, EOK);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom, "testuser1");
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek assert_int_equal(ret, EEXIST);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom, "testgroup1");
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek assert_int_equal(ret, EEXIST);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom, "testuser2");
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek assert_int_equal(ret, EEXIST);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom, "testgroup2");
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek assert_int_equal(ret, EEXIST);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom, "testuser3");
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek assert_int_equal(ret, ENOENT);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom, "testgroup3");
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek assert_int_equal(ret, ENOENT);
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha}
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozekstatic void test_sss_ncache_reset_prepopulate(void **state)
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek{
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek int ret;
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek struct test_state *ts;
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek struct tevent_context *ev;
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek struct sss_nc_ctx *ncache;
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek struct sss_test_ctx *tc;
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek struct sss_domain_info *dom;
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek struct sss_domain_info *dom2;
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek struct sss_test_conf_param params[] = {
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek { "filter_users", "testuser1@"TEST_DOM_NAME", testuser2@"TEST_DOM_NAME"2" },
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek { "filter_groups", "testgroup1@"TEST_DOM_NAME", testgroup2@"TEST_DOM_NAME"2" },
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek { NULL, NULL },
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek };
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek const char *nss_filter_users[] = { params[0].value, NULL};
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek const char *nss_filter_groups[] = { params[1].value, NULL};
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek ts = talloc_get_type_abort(*state, struct test_state);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek ev = tevent_context_init(ts);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek assert_non_null(ev);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek dom = talloc_zero(ts, struct sss_domain_info);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek assert_non_null(dom);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek dom->name = discard_const_p(char, TEST_DOM_NAME);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek ts->nctx = mock_nctx(ts);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek assert_non_null(ts->nctx);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek tc = create_dom_test_ctx(ts, TESTS_PATH, TEST_CONF_DB,
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek TEST_DOM_NAME, TEST_ID_PROVIDER, params);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek assert_non_null(tc);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek ret = confdb_add_param(tc->confdb, true, "config/nss",
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek "filter_users", nss_filter_users);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek assert_int_equal(ret, EOK);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek ret = confdb_add_param(tc->confdb, true, "config/nss",
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek "filter_groups", nss_filter_groups);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek assert_int_equal(ret, EOK);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek ncache = ts->ctx;
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek ts->rctx = mock_rctx(ts, ev, dom, ts->nctx);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek assert_non_null(ts->rctx);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek ts->rctx->default_domain = discard_const(TEST_DOM_NAME);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek ts->rctx->cdb = tc->confdb;
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek ret = sss_names_init(ts, tc->confdb, TEST_DOM_NAME, &dom->names);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek assert_int_equal(ret, EOK);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek ret = sss_ncache_reset_repopulate_permanent(ts->rctx, ncache);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek assert_int_equal(ret, EOK);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek /* Add another domain */
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek dom2 = talloc_zero(ts, struct sss_domain_info);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek assert_non_null(dom2);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek dom2->name = discard_const_p(char, TEST_DOM_NAME"2");
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek dom->next = dom2;
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek dom2->names = dom->names;
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek /* First domain should not be known, the second not */
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom, "testuser1");
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek assert_int_equal(ret, EEXIST);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom, "testgroup1");
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek assert_int_equal(ret, EEXIST);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom2, "testuser2");
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek assert_int_equal(ret, ENOENT);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom2, "testgroup2");
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek assert_int_equal(ret, ENOENT);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek ret = sss_ncache_reset_repopulate_permanent(ts->rctx, ncache);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek assert_int_equal(ret, EOK);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek /* First domain should not be known, the second not */
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom, "testuser1");
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek assert_int_equal(ret, EEXIST);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom, "testgroup1");
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek assert_int_equal(ret, EEXIST);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(ncache, dom2, "testuser2");
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek assert_int_equal(ret, EEXIST);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(ncache, dom2, "testgroup2");
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek assert_int_equal(ret, EEXIST);
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek}
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozekstatic void test_sss_ncache_reset(void **state)
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek{
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek errno_t ret;
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek struct test_state *ts;
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek struct sss_domain_info *dom;
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ts = talloc_get_type_abort(*state, struct test_state);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek dom = talloc(ts, struct sss_domain_info);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_non_null(dom);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek dom->case_sensitive = true;
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek dom->name = discard_const_p(char, TEST_DOM_NAME);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek /* Set users */
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_uid(ts->ctx, NULL, 123);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, ENOENT);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_set_uid(ts->ctx, false, NULL, 123);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, EOK);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_uid(ts->ctx, NULL, 123);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, EEXIST);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_user(ts->ctx, dom, "foo");
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, ENOENT);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_set_user(ts->ctx, false, dom, "foo");
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, EOK);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_user(ts->ctx, dom, "foo");
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, EEXIST);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek /* Set groups */
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_gid(ts->ctx, NULL, 456);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, ENOENT);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_set_gid(ts->ctx, false, NULL, 456);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, EOK);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_gid(ts->ctx, NULL, 456);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, EEXIST);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_group(ts->ctx, dom, "bar");
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, ENOENT);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_set_group(ts->ctx, false, dom, "bar");
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, EOK);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_group(ts->ctx, dom, "bar");
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, EEXIST);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_reset_users(ts->ctx);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, EOK);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek /* Users are no longer negatively cached */
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_user(ts->ctx, dom, "foo");
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, ENOENT);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_uid(ts->ctx, NULL, 123);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, ENOENT);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek /* Groups still are */
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_gid(ts->ctx, NULL, 456);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, EEXIST);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_group(ts->ctx, dom, "bar");
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, EEXIST);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_reset_groups(ts->ctx);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, EOK);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_gid(ts->ctx, NULL, 456);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, ENOENT);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek ret = sss_ncache_check_group(ts->ctx, dom, "bar");
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek assert_int_equal(ret, ENOENT);
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek}
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozekstatic void test_sss_ncache_locate_uid_gid(void **state)
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek{
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek uid_t uid;
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek gid_t gid;
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek int ret;
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek struct test_state *ts;
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek struct sss_domain_info *dom;
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek struct sss_domain_info *dom2;
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ts = talloc_get_type_abort(*state, struct test_state);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek uid = getuid();
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek gid = getgid();
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek dom = talloc(ts, struct sss_domain_info);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek assert_non_null(dom);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek dom->name = discard_const_p(char, TEST_DOM_NAME);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek dom2 = talloc(ts, struct sss_domain_info);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek assert_non_null(dom2);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek dom2->name = discard_const_p(char, TEST_DOM_NAME"2");
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_check_locate_gid(ts->ctx, dom, gid);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek assert_int_equal(ret, ENOENT);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_check_locate_uid(ts->ctx, dom, uid);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek assert_int_equal(ret, ENOENT);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_set_locate_gid(ts->ctx, dom, gid);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek assert_int_equal(ret, EOK);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_set_locate_uid(ts->ctx, dom, uid);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek assert_int_equal(ret, EOK);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_check_locate_gid(ts->ctx, dom, gid);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek assert_int_equal(ret, EEXIST);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_check_locate_uid(ts->ctx, dom, uid);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek assert_int_equal(ret, EEXIST);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_check_locate_gid(ts->ctx, dom2, gid);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek assert_int_equal(ret, ENOENT);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_check_locate_uid(ts->ctx, dom2, uid);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek assert_int_equal(ret, ENOENT);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek}
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozekstatic void test_sss_ncache_domain_locate_type(void **state)
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek{
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek int ret;
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek struct test_state *ts;
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek struct sss_domain_info *dom;
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek struct sss_domain_info *dom2;
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ts = talloc_get_type_abort(*state, struct test_state);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek dom = talloc(ts, struct sss_domain_info);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek assert_non_null(dom);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek dom->name = discard_const_p(char, TEST_DOM_NAME);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek dom2 = talloc(ts, struct sss_domain_info);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek assert_non_null(dom2);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek dom2->name = discard_const_p(char, TEST_DOM_NAME"2");
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_check_domain_locate_type(ts->ctx, dom, "foo");
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek assert_int_equal(ret, ENOENT);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_set_domain_locate_type(ts->ctx, dom, "foo");
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek assert_int_equal(ret, EOK);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_check_domain_locate_type(ts->ctx, dom, "foo");
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek assert_int_equal(ret, EEXIST);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek ret = sss_ncache_check_domain_locate_type(ts->ctx, dom2, "foo");
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek assert_int_equal(ret, ENOENT);
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek}
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jhaint main(void)
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha{
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha int rv;
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek const struct CMUnitTest tests[] = {
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test(test_sss_ncache_init),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_uid, setup, teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_gid, setup, teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_sid, setup, teardown),
8d4dedea12e2b71f83a1b0e5f0fc5cdb706dcf98Sumit Bose cmocka_unit_test_setup_teardown(test_sss_ncache_cert, setup, teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_user, setup, teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_group, setup, teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_netgr, setup, teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_service_name, setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_service_port,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek setup, teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_reset_permanent, setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_prepopulate,
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek setup, teardown),
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_default_domain_suffix,
1aa492ce890f362564bfac21f3cfb0a3e38608bdJakub Hrozek setup, teardown),
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_reset_prepopulate,
0d19785f9ffd9c66df5b30d208ec7b0216a9555bJakub Hrozek setup, teardown),
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_reset,
99a32e4f5164e174d5a3ffa5a1fe622075a8fe45Jakub Hrozek setup, teardown),
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_locate_uid_gid,
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek setup, teardown),
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_ncache_domain_locate_type,
07452697a67902dc6876d2f40d364cf1eadf2431Jakub Hrozek setup, teardown),
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha };
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha tests_set_cwd();
cb4742876508a08ba90c82466c9dba708e4bf999Pavel Březina test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha test_dom_suite_setup(TESTS_PATH);
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek rv = cmocka_run_group_tests(tests, NULL, NULL);
dd191498f56ce10f596308cdd0fad344af0d86b9Lukas Slebodnik if (rv == 0) {
cb4742876508a08ba90c82466c9dba708e4bf999Pavel Březina test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
dd191498f56ce10f596308cdd0fad344af0d86b9Lukas Slebodnik }
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha return rv;
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha}