summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2013-08-05 16:10:10 -0400
committerGreg Hudson <ghudson@mit.edu>2013-08-15 12:39:58 -0400
commit7ad5f3bfd8b57d2f4c001182792e25968309ca8a (patch)
tree56092fc925f574c72c9f0a0afae396ed5387c093 /src/plugins
parent4f7f1fce6edca17db625d76c1f81ea098f29c313 (diff)
downloadkrb5-7ad5f3bfd8b57d2f4c001182792e25968309ca8a.tar.gz
krb5-7ad5f3bfd8b57d2f4c001182792e25968309ca8a.tar.xz
krb5-7ad5f3bfd8b57d2f4c001182792e25968309ca8a.zip
Add hostrealm interface tests
Create a test module for the hostrealm interface, a harness to call the realm mapping functions and display their results, and a Python script to exercise the functionality of the interface and each module (except the dns module, which we cannot easily test since it relies on TXT records in the public DNS). ticket: 7687
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/hostrealm/test/Makefile.in21
-rw-r--r--src/plugins/hostrealm/test/deps14
-rw-r--r--src/plugins/hostrealm/test/hostrealm_test.exports2
-rw-r--r--src/plugins/hostrealm/test/main.c197
4 files changed, 234 insertions, 0 deletions
diff --git a/src/plugins/hostrealm/test/Makefile.in b/src/plugins/hostrealm/test/Makefile.in
new file mode 100644
index 0000000000..2d9c38e32a
--- /dev/null
+++ b/src/plugins/hostrealm/test/Makefile.in
@@ -0,0 +1,21 @@
+mydir=plugins$(S)hostrealm$(S)test
+BUILDTOP=$(REL)..$(S)..$(S)..
+
+LIBBASE=hostrealm_test
+LIBMAJOR=0
+LIBMINOR=0
+RELDIR=../plugins/hostrealm/test
+# Depends on libkrb5
+SHLIB_EXPDEPS= $(KRB5_DEPLIB)
+SHLIB_EXPLIBS= $(KRB5_LIB)
+
+STLIBOBJS=main.o
+
+SRCS= $(srcdir)/main.c
+
+all-unix:: all-libs
+install-unix::
+clean-unix:: clean-libs clean-libobjs
+
+@libnover_frag@
+@libobj_frag@
diff --git a/src/plugins/hostrealm/test/deps b/src/plugins/hostrealm/test/deps
new file mode 100644
index 0000000000..d91fef860d
--- /dev/null
+++ b/src/plugins/hostrealm/test/deps
@@ -0,0 +1,14 @@
+#
+# Generated makefile dependencies follow.
+#
+main.so main.po $(OUTPRE)main.$(OBJEXT): $(BUILDTOP)/include/autoconf.h \
+ $(BUILDTOP)/include/krb5/krb5.h $(BUILDTOP)/include/osconf.h \
+ $(BUILDTOP)/include/profile.h $(COM_ERR_DEPS) $(top_srcdir)/include/k5-buf.h \
+ $(top_srcdir)/include/k5-err.h $(top_srcdir)/include/k5-gmt_mktime.h \
+ $(top_srcdir)/include/k5-int-pkinit.h $(top_srcdir)/include/k5-int.h \
+ $(top_srcdir)/include/k5-platform.h $(top_srcdir)/include/k5-plugin.h \
+ $(top_srcdir)/include/k5-thread.h $(top_srcdir)/include/k5-trace.h \
+ $(top_srcdir)/include/krb5.h $(top_srcdir)/include/krb5/authdata_plugin.h \
+ $(top_srcdir)/include/krb5/hostrealm_plugin.h $(top_srcdir)/include/krb5/plugin.h \
+ $(top_srcdir)/include/port-sockets.h $(top_srcdir)/include/socket-utils.h \
+ main.c
diff --git a/src/plugins/hostrealm/test/hostrealm_test.exports b/src/plugins/hostrealm/test/hostrealm_test.exports
new file mode 100644
index 0000000000..1adb759285
--- /dev/null
+++ b/src/plugins/hostrealm/test/hostrealm_test.exports
@@ -0,0 +1,2 @@
+hostrealm_test1_initvt
+hostrealm_test2_initvt
diff --git a/src/plugins/hostrealm/test/main.c b/src/plugins/hostrealm/test/main.c
new file mode 100644
index 0000000000..3b36dce77d
--- /dev/null
+++ b/src/plugins/hostrealm/test/main.c
@@ -0,0 +1,197 @@
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/* plugins/hostrealm/test/main.c - test module for host-realm interface */
+/*
+ * Copyright (C) 2010,2013 by the Massachusetts Institute of Technology.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * This file implements two hostrealm modules named "test1" and "test2".
+ *
+ * The first module returns multi-element lists. For host_realm and
+ * fallback_realm, it returns a list of the host's components in order. For
+ * default_realm, it returns a list containing "one" and "two".
+ *
+ * The second module tests error handling. For host_realm and fallback_realm,
+ * it returns a fatal error on hosts beginning with 'z', a list containing "a"
+ * for hosts beginning with 'a', and passes control to later modules otherwise.
+ * For default_realm, it returns a fatal error.
+ */
+
+#include <k5-int.h>
+#include <krb5/hostrealm_plugin.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+static krb5_error_code
+split_comps(krb5_context context, krb5_hostrealm_moddata data,
+ const char *host, char ***realms_out)
+{
+ krb5_error_code ret;
+ const char *p, *q;
+ char *word = NULL, **list = NULL, **newptr;
+ size_t count = 0;
+
+ *realms_out = NULL;
+ if (*host == '\0')
+ return KRB5_PLUGIN_NO_HANDLE;
+ p = host;
+ while (TRUE) {
+ q = strchr(p, '.');
+ word = (q == NULL) ? strdup(p) : k5memdup0(p, q - p, &ret);
+ if (word == NULL)
+ goto oom;
+ newptr = realloc(list, (count + 2) * sizeof(*list));
+ if (newptr == NULL)
+ goto oom;
+ list = newptr;
+ list[count++] = word;
+ list[count] = NULL;
+ word = NULL;
+ if (q == NULL)
+ break;
+ p = q + 1;
+ }
+ *realms_out = list;
+ return 0;
+
+oom:
+ krb5_free_host_realm(context, list);
+ free(word);
+ return ENOMEM;
+}
+
+static krb5_error_code
+multi_defrealm(krb5_context context, krb5_hostrealm_moddata data,
+ char ***realms_out)
+{
+ char **list = NULL, *one = NULL, *two = NULL;
+
+ *realms_out = NULL;
+ one = strdup("one");
+ if (one == NULL)
+ goto oom;
+ two = strdup("two");
+ if (two == NULL)
+ goto oom;
+ list = calloc(3, sizeof(*list));
+ if (list == NULL)
+ goto oom;
+ list[0] = one;
+ list[1] = two;
+ list[2] = NULL;
+ *realms_out = list;
+ return 0;
+
+oom:
+ free(one);
+ free(two);
+ free(list);
+ return ENOMEM;
+}
+
+static krb5_error_code
+maybe_realm(krb5_context context, krb5_hostrealm_moddata data,
+ const char *host, char ***realms_out)
+{
+ char **list, *a;
+
+ *realms_out = NULL;
+ if (*host == 'z')
+ return KRB5_ERR_NO_SERVICE;
+ if (*host != 'a')
+ return KRB5_PLUGIN_NO_HANDLE;
+ a = strdup("a");
+ if (a == NULL)
+ return ENOMEM;
+ list = calloc(2, sizeof(*list));
+ if (list == NULL) {
+ free(a);
+ return ENOMEM;
+ }
+ list[0] = a;
+ list[1] = NULL;
+ *realms_out = list;
+ return 0;
+}
+
+static krb5_error_code
+error(krb5_context context, krb5_hostrealm_moddata data, char ***realms_out)
+{
+ *realms_out = NULL;
+ return KRB5_ERR_NO_SERVICE;
+}
+
+static void
+free_realmlist(krb5_context context, krb5_hostrealm_moddata data,
+ char **list)
+{
+ krb5_free_host_realm(context, list);
+}
+
+krb5_error_code
+hostrealm_test1_initvt(krb5_context context, int maj_ver, int min_ver,
+ krb5_plugin_vtable vtable);
+krb5_error_code
+hostrealm_test2_initvt(krb5_context context, int maj_ver, int min_ver,
+ krb5_plugin_vtable vtable);
+
+krb5_error_code
+hostrealm_test1_initvt(krb5_context context, int maj_ver, int min_ver,
+ krb5_plugin_vtable vtable)
+{
+ krb5_hostrealm_vtable vt;
+
+ if (maj_ver != 1)
+ return KRB5_PLUGIN_VER_NOTSUPP;
+ vt = (krb5_hostrealm_vtable)vtable;
+ vt->name = "test1";
+ vt->host_realm = split_comps;
+ vt->fallback_realm = split_comps;
+ vt->default_realm = multi_defrealm;
+ vt->free_list = free_realmlist;
+ return 0;
+}
+
+krb5_error_code
+hostrealm_test2_initvt(krb5_context context, int maj_ver, int min_ver,
+ krb5_plugin_vtable vtable)
+{
+ krb5_hostrealm_vtable vt;
+
+ if (maj_ver != 1)
+ return KRB5_PLUGIN_VER_NOTSUPP;
+ vt = (krb5_hostrealm_vtable)vtable;
+ vt->name = "test2";
+ vt->host_realm = maybe_realm;
+ vt->default_realm = error;
+ vt->free_list = free_realmlist;
+ return 0;
+}