cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek Copyright (C) 2017 Red Hat
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek SSSD tests: Test KCM JSON marshalling
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek This program is free software; you can redistribute it and/or modify
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek it under the terms of the GNU General Public License as published by
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek (at your option) any later version.
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek This program is distributed in the hope that it will be useful,
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek GNU General Public License for more details.
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek You should have received a copy of the GNU General Public License
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
7d73049884e3a96ca3b00b5bd4104f4edd6287abJakub Hrozek#define TEST_UUID_STR "5f8f296b-02be-4e86-9235-500e82354186"
7d73049884e3a96ca3b00b5bd4104f4edd6287abJakub Hrozek#define TEST_SEC_KEY_MULTIDIGITS TEST_UUID_STR"-123456"
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek test_ctx = talloc_zero(NULL, struct kcm_marshalling_test_ctx);
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozekstatic int teardown_kcm_marshalling(void **state)
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek struct kcm_marshalling_test_ctx *test_ctx = talloc_get_type(*state,
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek krb5_free_principal(test_ctx->kctx, test_ctx->princ);
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozekstatic void assert_cc_name_equal(struct kcm_ccache *cc1,
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozekstatic void assert_cc_uuid_equal(struct kcm_ccache *cc1,
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozekstatic void assert_cc_princ_equal(struct kcm_ccache *cc1,
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozekstatic void assert_cc_offset_equal(struct kcm_ccache *cc1,
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozekstatic void assert_cc_equal(struct kcm_ccache *cc1,
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozekstatic void test_kcm_ccache_marshall_unmarshall(void **state)
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek struct kcm_marshalling_test_ctx *test_ctx = talloc_get_type(*state,
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek name = talloc_asprintf(test_ctx, "%"SPRIuid, getuid());
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek (const char *) data,
7d73049884e3a96ca3b00b5bd4104f4edd6287abJakub Hrozek /* This key is exactly one byte shorter than it should be */
7d73049884e3a96ca3b00b5bd4104f4edd6287abJakub Hrozek (const char *) data,
7d73049884e3a96ca3b00b5bd4104f4edd6287abJakub Hrozek ret = sec_key_get_uuid(TEST_SEC_KEY_ONEDIGIT, uuid);
7d73049884e3a96ca3b00b5bd4104f4edd6287abJakub Hrozek ret = sec_key_get_uuid(TEST_SEC_KEY_NOSEP, uuid);
7d73049884e3a96ca3b00b5bd4104f4edd6287abJakub Hrozek name = sec_key_get_name(TEST_SEC_KEY_ONEDIGIT);
7d73049884e3a96ca3b00b5bd4104f4edd6287abJakub Hrozek name = sec_key_get_name(TEST_SEC_KEY_MULTIDIGITS);
7d73049884e3a96ca3b00b5bd4104f4edd6287abJakub Hrozek assert_true(sec_key_match_name(TEST_SEC_KEY_ONEDIGIT, "0"));
7d73049884e3a96ca3b00b5bd4104f4edd6287abJakub Hrozek assert_true(sec_key_match_name(TEST_SEC_KEY_MULTIDIGITS, "123456"));
7d73049884e3a96ca3b00b5bd4104f4edd6287abJakub Hrozek assert_false(sec_key_match_name(TEST_SEC_KEY_MULTIDIGITS, "0"));
7d73049884e3a96ca3b00b5bd4104f4edd6287abJakub Hrozek assert_false(sec_key_match_name(TEST_SEC_KEY_ONEDIGIT, "123456"));
7d73049884e3a96ca3b00b5bd4104f4edd6287abJakub Hrozek assert_false(sec_key_match_name(TEST_UUID_STR, "0"));
7d73049884e3a96ca3b00b5bd4104f4edd6287abJakub Hrozek assert_false(sec_key_match_name(TEST_SEC_KEY_NOSEP, "0"));
7d73049884e3a96ca3b00b5bd4104f4edd6287abJakub Hrozek assert_false(sec_key_match_name(TEST_SEC_KEY_ONEDIGIT, NULL));
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek cmocka_unit_test_setup_teardown(test_kcm_ccache_marshall_unmarshall,
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
cac0db2f8004ae88b9263dc3888a11a2d3d3d114Jakub Hrozek /* 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 */