802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose/*
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose Authors:
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose Sumit Bose <sbose@redhat.com>
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose Copyright (C) 2014 Red Hat
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose SSSD tests: Tests ccache utilities
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose This program is free software; you can redistribute it and/or modify
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose it under the terms of the GNU General Public License as published by
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose the Free Software Foundation; either version 3 of the License, or
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose (at your option) any later version.
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose This program is distributed in the hope that it will be useful,
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose GNU General Public License for more details.
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose You should have received a copy of the GNU General Public License
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose*/
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose#include <stdio.h>
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose#include <popt.h>
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose#include "util/sss_krb5.h"
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose#include "providers/krb5/krb5_common.h"
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose#include "providers/krb5/krb5_ccache.h"
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose#include "tests/cmocka/common_mock.h"
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose#define CCACHE_TEST_CLIENT_PRINC "test/client@TEST.CCACHE"
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose#define CCACHE_TEST_SERVER_PRINC "test/server@TEST.CCACHE"
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose#define CCACHE_PATH TEST_DIR "/ccache_test.ccache"
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bosestruct ccache_test_ctx {
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_context kctx;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose const char *ccache_file_name;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_principal client_principal;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_principal server_principal;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose};
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int setup_ccache(void **state)
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose{
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose struct ccache_test_ctx *test_ctx;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_error_code kerr;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_ccache ccache;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_creds test_creds;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose static krb5_address addr;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose int add=0x12345;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_authdata *a;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose static krb5_address *addrs[] = {
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose &addr,
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose NULL,
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose };
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_true(leak_check_setup());
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_ctx = talloc_zero(global_talloc_context, struct ccache_test_ctx);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_non_null(test_ctx);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = krb5_init_context(&test_ctx->kctx);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_int_equal(kerr, 0);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose addr.magic = KV5M_ADDRESS;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose addr.addrtype = ADDRTYPE_INET;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose addr.length = 4;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose addr.contents = (krb5_octet *) &add;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose memset(&test_creds, 0, sizeof(test_creds));
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.magic = KV5M_CREDS;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = krb5_parse_name(test_ctx->kctx, CCACHE_TEST_CLIENT_PRINC,
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose &test_ctx->client_principal);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_int_equal(kerr, 0);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.client = test_ctx->client_principal;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = krb5_parse_name(test_ctx->kctx, CCACHE_TEST_SERVER_PRINC,
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose &test_ctx->server_principal);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_int_equal(kerr, 0);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.server = test_ctx->server_principal;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.keyblock.magic = KV5M_KEYBLOCK;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.keyblock.contents = 0;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.keyblock.enctype = 1;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.keyblock.length = 1;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.keyblock.contents = (unsigned char *) discard_const("1");
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.times.authtime = 1111;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.times.starttime = 2222;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.times.endtime = 3333;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.times.renew_till = 4444;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.is_skey = 1;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.ticket_flags = 5555;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.addresses = addrs;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.ticket.magic = KV5M_DATA;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.ticket.length = sizeof("Ticket");
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.ticket.data = discard_const("Ticket");
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.authdata = malloc (2 * sizeof(krb5_authdata *));
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_non_null(test_creds.authdata);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose a = (krb5_authdata *) malloc(sizeof(krb5_authdata));
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_non_null(a);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose a->magic = KV5M_AUTHDATA;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose a->ad_type = KRB5_AUTHDATA_IF_RELEVANT;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose a->contents = (krb5_octet * ) malloc(1);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_non_null(a->contents);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose a->contents[0]=5;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose a->length = 1;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.authdata[0] = a;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.authdata[1] = NULL;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_ctx->ccache_file_name = "FILE:" CCACHE_PATH;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = krb5_cc_resolve(test_ctx->kctx, test_ctx->ccache_file_name,
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose &ccache);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_int_equal(kerr, 0);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = krb5_cc_initialize(test_ctx->kctx, ccache, test_creds.client);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_int_equal(kerr, 0);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = krb5_cc_store_cred(test_ctx->kctx, ccache, &test_creds);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_int_equal(kerr, 0);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = krb5_cc_close(test_ctx->kctx, ccache);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_int_equal(kerr, 0);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose check_leaks_push(test_ctx);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose *state = test_ctx;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_free_authdata(test_ctx->kctx, test_creds.authdata);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose}
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int teardown_ccache(void **state)
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose{
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose int ret;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose struct ccache_test_ctx *test_ctx = talloc_get_type(*state,
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose struct ccache_test_ctx);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_non_null(test_ctx);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_free_principal(test_ctx->kctx, test_ctx->client_principal);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_free_principal(test_ctx->kctx, test_ctx->server_principal);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_free_context(test_ctx->kctx);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose ret = unlink(CCACHE_PATH);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_int_equal(ret, 0);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_true(check_leaks_pop(test_ctx) == true);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose talloc_free(test_ctx);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_true(leak_check_teardown());
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose}
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bosevoid test_copy_ccache(void **state)
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose{
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_error_code kerr;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose char *mem_ccache_name;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_ccache ccache;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_creds mcreds;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_creds creds;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_principal mem_principal;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose struct ccache_test_ctx *test_ctx = talloc_get_type(*state,
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose struct ccache_test_ctx);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_non_null(test_ctx);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = copy_ccache_into_memory(test_ctx, test_ctx->kctx,
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_ctx->ccache_file_name,
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose &mem_ccache_name);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_int_equal(kerr, 0);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_non_null(mem_ccache_name);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = krb5_cc_resolve(test_ctx->kctx, mem_ccache_name, &ccache);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_int_equal(kerr, 0);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose talloc_free(mem_ccache_name);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = krb5_cc_get_principal(test_ctx->kctx, ccache, &mem_principal);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_int_equal(kerr, 0);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_non_null(mem_principal);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_true(krb5_principal_compare(test_ctx->kctx, mem_principal,
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_ctx->client_principal));
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_free_principal(test_ctx->kctx, mem_principal);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose memset(&mcreds, 0, sizeof(mcreds));
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose memset(&creds, 0, sizeof(mcreds));
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose mcreds.client = test_ctx->client_principal;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose mcreds.server = test_ctx->server_principal;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = krb5_cc_retrieve_cred(test_ctx->kctx, ccache, 0, &mcreds, &creds);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_int_equal(kerr, 0);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_free_cred_contents(test_ctx->kctx, &creds);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = krb5_cc_destroy(test_ctx->kctx, ccache);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_int_equal(kerr, 0);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose}
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Boseint main(int argc, const char *argv[])
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose{
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose poptContext pc;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose int opt;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose int rv;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose struct poptOption long_options[] = {
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose POPT_AUTOHELP
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose SSSD_DEBUG_OPTS
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose POPT_TABLEEND
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose };
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek const struct CMUnitTest tests[] = {
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_copy_ccache,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek setup_ccache, teardown_ccache),
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose };
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose debug_level = SSSDBG_INVALID;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose pc = poptGetContext(argv[0], argc, argv, long_options, 0);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose while((opt = poptGetNextOpt(pc)) != -1) {
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose switch(opt) {
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose default:
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose fprintf(stderr, "\nInvalid option %s: %s\n\n",
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose poptBadOption(pc, 0), poptStrerror(opt));
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose poptPrintUsage(pc, stderr, 0);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose return 1;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose }
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose }
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose poptFreeContext(pc);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose DEBUG_CLI_INIT(debug_level);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose /* Even though normally the tests should clean up after themselves
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz * they might not after a failed run. Remove the old DB to be sure */
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose tests_set_cwd();
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek rv = cmocka_run_group_tests(tests, NULL, NULL);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose return rv;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose}