802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose Sumit Bose <sbose@redhat.com>
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose Copyright (C) 2014 Red Hat
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose SSSD tests: Tests ccache utilities
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 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 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#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 test_ctx = talloc_zero(global_talloc_context, struct ccache_test_ctx);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = krb5_parse_name(test_ctx->kctx, CCACHE_TEST_CLIENT_PRINC,
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = krb5_parse_name(test_ctx->kctx, CCACHE_TEST_SERVER_PRINC,
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.keyblock.contents = (unsigned char *) discard_const("1");
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.ticket.data = discard_const("Ticket");
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_creds.authdata = malloc (2 * sizeof(krb5_authdata *));
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose a = (krb5_authdata *) malloc(sizeof(krb5_authdata));
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose test_ctx->ccache_file_name = "FILE:" CCACHE_PATH;
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = krb5_cc_resolve(test_ctx->kctx, test_ctx->ccache_file_name,
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = krb5_cc_initialize(test_ctx->kctx, ccache, test_creds.client);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = krb5_cc_store_cred(test_ctx->kctx, ccache, &test_creds);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_free_authdata(test_ctx->kctx, test_creds.authdata);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose struct ccache_test_ctx *test_ctx = talloc_get_type(*state,
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 struct ccache_test_ctx *test_ctx = talloc_get_type(*state,
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = copy_ccache_into_memory(test_ctx, test_ctx->kctx,
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = krb5_cc_resolve(test_ctx->kctx, mem_ccache_name, &ccache);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = krb5_cc_get_principal(test_ctx->kctx, ccache, &mem_principal);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose assert_true(krb5_principal_compare(test_ctx->kctx, mem_principal,
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose krb5_free_principal(test_ctx->kctx, mem_principal);
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose kerr = krb5_cc_retrieve_cred(test_ctx->kctx, ccache, 0, &mcreds, &creds);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_copy_ccache,
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose pc = poptGetContext(argv[0], argc, argv, long_options, 0);
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 */