summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/krb5_child-test.c38
-rw-r--r--src/tests/krb5_utils-tests.c44
2 files changed, 32 insertions, 50 deletions
diff --git a/src/tests/krb5_child-test.c b/src/tests/krb5_child-test.c
index 4dde996a..2ca65531 100644
--- a/src/tests/krb5_child-test.c
+++ b/src/tests/krb5_child-test.c
@@ -39,6 +39,7 @@
#include "providers/krb5/krb5_utils.h"
extern struct dp_option default_krb5_opts[];
+extern struct sss_krb5_cc_be file_cc;
static krb5_context krb5_error_ctx;
#define KRB5_DEBUG(level, krb5_error) do { \
@@ -118,6 +119,8 @@ create_dummy_krb5_ctx(TALLOC_CTX *mem_ctx, const char *realm)
krb5_ctx = talloc_zero(mem_ctx, struct krb5_ctx);
if (!krb5_ctx) return NULL;
+ krb5_ctx->cc_be = &file_cc;
+
krb5_ctx->illegal_path_re = pcre_compile2(ILLEGAL_PATH_PATTERN, 0,
&errval, &errstr, &errpos, NULL);
if (krb5_ctx->illegal_path_re == NULL) {
@@ -250,14 +253,16 @@ create_dummy_req(TALLOC_CTX *mem_ctx, const char *user,
DEBUG(SSSDBG_FUNC_DATA, ("ccname [%s] uid [%llu] gid [%llu]\n",
kr->ccname, kr->uid, kr->gid));
- ret = create_ccache_dir(kr, kr->ccname,
- kr->krb5_ctx->illegal_path_re,
- kr->uid, kr->gid, private);
+ ret = kr->krb5_ctx->cc_be->create(kr->ccname,
+ kr->krb5_ctx->illegal_path_re,
+ kr->uid, kr->gid, private);
if (ret != EOK) {
DEBUG(SSSDBG_OP_FAILURE, ("create_ccache_dir failed.\n"));
- goto fail;
}
+ } else {
+ kr->ccname = talloc_strdup(kr, ccname);
}
+ if (!kr->ccname) goto fail;
return kr;
@@ -375,29 +380,6 @@ done:
return ret;
}
-static void
-remove_ccache(const char *cc)
-{
- size_t offset = 0;
- errno_t ret;
-
- if (strncmp(cc, "FILE:", 5) == 0) {
- offset = 5;
- }
- if (cc[offset] != '/') {
- DEBUG(SSSDBG_FATAL_FAILURE,
- ("ccname [%s] does not contain absolute path?\n", cc));
- }
-
- errno = 0;
- ret = unlink(cc+offset);
- if (ret == -1) {
- ret = errno;
- DEBUG(SSSDBG_FATAL_FAILURE,
- ("unlink [%s] failed [%d]: %s\n", cc, ret, strerror(ret)));
- }
-}
-
int
main(int argc, const char *argv[])
{
@@ -542,7 +524,7 @@ main(int argc, const char *argv[])
ret = 0;
done:
if (rm_ccache && ctx->res && ctx->res->ccname) {
- remove_ccache(ctx->res->ccname);
+ ctx->kr->krb5_ctx->cc_be->remove(ctx->res->ccname);
}
free(password);
talloc_free(ctx);
diff --git a/src/tests/krb5_utils-tests.c b/src/tests/krb5_utils-tests.c
index aacc384d..4a572488 100644
--- a/src/tests/krb5_utils-tests.c
+++ b/src/tests/krb5_utils-tests.c
@@ -117,14 +117,14 @@ START_TEST(test_pub_ccache_dir)
ret = chmod(testpath, 0754);
fail_unless(ret == EOK, "chmod failed.");
- ret = create_ccache_dir(tmp_ctx, filename, NULL, 12345, 12345, false);
- fail_unless(ret == EINVAL, "create_ccache_dir does not return EINVAL "
+ ret = cc_file_create(filename, NULL, 12345, 12345, false);
+ fail_unless(ret == EINVAL, "cc_file_create does not return EINVAL "
"while x-bit is missing.");
ret = chmod(testpath, 0755);
fail_unless(ret == EOK, "chmod failed.");
- ret = create_ccache_dir(tmp_ctx, filename, NULL, 12345, 12345, false);
- fail_unless(ret == EOK, "create_ccache_dir failed.");
+ ret = cc_file_create(filename, NULL, 12345, 12345, false);
+ fail_unless(ret == EOK, "cc_file_create failed.");
check_dir(subdirname, 0, 0, 01777);
RMDIR(subdirname);
@@ -158,7 +158,7 @@ START_TEST(test_pub_ccache_dir_in_user_dir)
filename = talloc_asprintf(tmp_ctx, "%s/ccfile", subdirname);
fail_unless(filename != NULL, "talloc_asprintf failed.");
- ret = create_ccache_dir(tmp_ctx, filename, NULL, 12345, 12345, false);
+ ret = cc_file_create(filename, NULL, 12345, 12345, false);
fail_unless(ret == EINVAL, "Creating public ccache dir in user dir "
"does not failed with EINVAL.");
@@ -193,14 +193,14 @@ START_TEST(test_priv_ccache_dir)
ret = chmod(testpath, 0754);
fail_unless(ret == EOK, "chmod failed.");
- ret = create_ccache_dir(tmp_ctx, filename, NULL, uid, gid, true);
- fail_unless(ret == EINVAL, "create_ccache_dir does not return EINVAL "
+ ret = cc_file_create(filename, NULL, uid, gid, true);
+ fail_unless(ret == EINVAL, "cc_file_create does not return EINVAL "
"while x-bit is missing.");
ret = chmod(testpath, 0755);
fail_unless(ret == EOK, "chmod failed.");
- ret = create_ccache_dir(tmp_ctx, filename, NULL, uid, gid, true);
- fail_unless(ret == EOK, "create_ccache_dir failed.");
+ ret = cc_file_create(filename, NULL, uid, gid, true);
+ fail_unless(ret == EOK, "cc_file_create failed.");
check_dir(subdir, uid, gid, 0700);
RMDIR(subdir);
@@ -248,14 +248,14 @@ START_TEST(test_private_ccache_dir_in_user_dir)
ret = chmod(user_dir, 0600);
fail_unless(ret == EOK, "chmod failed.");
- ret = create_ccache_dir(tmp_ctx, filename, NULL, uid, gid, true);
- fail_unless(ret == EINVAL, "create_ccache_dir does not return EINVAL "
+ ret = cc_file_create(filename, NULL, uid, gid, true);
+ fail_unless(ret == EINVAL, "cc_file_create does not return EINVAL "
"while x-bit is missing.");
ret = chmod(user_dir, 0700);
fail_unless(ret == EOK, "chmod failed.");
- ret = create_ccache_dir(tmp_ctx, filename, NULL, uid, gid, true);
- fail_unless(ret == EOK, "create_ccache_dir failed.");
+ ret = cc_file_create(filename, NULL, uid, gid, true);
+ fail_unless(ret == EOK, "cc_file_create failed.");
check_dir(dn3, uid, gid, 0700);
RMDIR(dn3);
@@ -292,7 +292,7 @@ START_TEST(test_private_ccache_dir_in_wrong_user_dir)
filename = talloc_asprintf(tmp_ctx, "%s/ccfile", subdirname);
fail_unless(filename != NULL, "talloc_asprintf failed.");
- ret = create_ccache_dir(tmp_ctx, filename, NULL, 12345, 12345, true);
+ ret = cc_file_create(filename, NULL, 12345, 12345, true);
fail_unless(ret == EINVAL, "Creating private ccache dir in wrong user "
"dir does not failed with EINVAL.");
@@ -329,28 +329,28 @@ START_TEST(test_illegal_patterns)
filename = talloc_asprintf(tmp_ctx, "abc/./ccfile");
fail_unless(filename != NULL, "talloc_asprintf failed.");
- ret = create_ccache_dir(tmp_ctx, filename, illegal_re, uid, gid, true);
- fail_unless(ret == EINVAL, "create_ccache_dir allowed relative path [%s].",
+ ret = cc_file_create(filename, illegal_re, uid, gid, true);
+ fail_unless(ret == EINVAL, "cc_file_create allowed relative path [%s].",
filename);
filename = talloc_asprintf(tmp_ctx, "%s/abc/./ccfile", dirname);
fail_unless(filename != NULL, "talloc_asprintf failed.");
- ret = create_ccache_dir(tmp_ctx, filename, illegal_re, uid, gid, true);
- fail_unless(ret == EINVAL, "create_ccache_dir allowed "
+ ret = cc_file_create(filename, illegal_re, uid, gid, true);
+ fail_unless(ret == EINVAL, "cc_file_create allowed "
"illegal pattern '/./' in filename [%s].",
filename);
filename = talloc_asprintf(tmp_ctx, "%s/abc/../ccfile", dirname);
fail_unless(filename != NULL, "talloc_asprintf failed.");
- ret = create_ccache_dir(tmp_ctx, filename, illegal_re, uid, gid, true);
- fail_unless(ret == EINVAL, "create_ccache_dir allowed "
+ ret = cc_file_create(filename, illegal_re, uid, gid, true);
+ fail_unless(ret == EINVAL, "cc_file_create allowed "
"illegal pattern '/../' in filename [%s].",
filename);
filename = talloc_asprintf(tmp_ctx, "%s/abc//ccfile", dirname);
fail_unless(filename != NULL, "talloc_asprintf failed.");
- ret = create_ccache_dir(tmp_ctx, filename, illegal_re, uid, gid, true);
- fail_unless(ret == EINVAL, "create_ccache_dir allowed "
+ ret = cc_file_create(filename, illegal_re, uid, gid, true);
+ fail_unless(ret == EINVAL, "cc_file_create allowed "
"illegal pattern '//' in filename [%s].",
filename);