krb5 commit: Add tests for gss_inquire_mechs_for_name
Greg Hudson
ghudson at MIT.EDU
Mon Sep 17 15:22:36 EDT 2012
https://github.com/krb5/krb5/commit/5b624ab7388c17cfeae040aa41d0bfc74eca1fc1
commit 5b624ab7388c17cfeae040aa41d0bfc74eca1fc1
Author: Greg Hudson <ghudson at mit.edu>
Date: Mon Sep 17 14:42:46 2012 -0400
Add tests for gss_inquire_mechs_for_name
.gitignore | 1 +
src/tests/gssapi/Makefile.in | 21 +++++++----
src/tests/gssapi/common.c | 4 ++-
src/tests/gssapi/common.h | 2 +-
src/tests/gssapi/t_gssapi.py | 13 +++++++
src/tests/gssapi/t_inq_mechs_name.c | 62 +++++++++++++++++++++++++++++++++++
6 files changed, 93 insertions(+), 10 deletions(-)
diff --git a/.gitignore b/.gitignore
index 9737d26..218800f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -269,6 +269,7 @@ testlog
/src/tests/gssapi/t_imp_cred
/src/tests/gssapi/t_imp_name
/src/tests/gssapi/t_inq_cred
+/src/tests/gssapi/t_inq_mechs_name
/src/tests/gssapi/t_namingexts
/src/tests/gssapi/t_s4u
/src/tests/gssapi/t_s4u2proxy_krb5
diff --git a/src/tests/gssapi/Makefile.in b/src/tests/gssapi/Makefile.in
index a34c28e..e20cbac 100644
--- a/src/tests/gssapi/Makefile.in
+++ b/src/tests/gssapi/Makefile.in
@@ -7,25 +7,27 @@ PROG_RPATH=$(KRB5_LIBDIR)
SRCS= $(srcdir)/t_accname.c $(srcdir)/t_ccselect.c $(srcdir)/t_credstore.c \
$(srcdir)/t_export_cred.c $(srcdir)/t_export_name.c \
$(srcdir)/t_gssexts.c $(srcdir)/t_imp_cred.c $(srcdir)/t_imp_name.c \
- $(srcdir)/t_inq_cred.c $(srcdir)/t_namingexts.c $(srcdir)/t_s4u.c \
+ $(srcdir)/t_inq_cred.c $(srcdir)/t_inq_mechs_name.c \
+ $(srcdir)/t_namingexts.c $(srcdir)/t_s4u.c \
$(srcdir)/t_s4u2proxy_krb5.c $(srcdir)/t_saslname.c \
$(srcdir)/t_spnego.c
OBJS= ccinit.o ccrefresh.o common.o t_accname.o t_ccselect.o t_credstore.o \
t_export_cred.o t_export_name.o t_gssexts.o t_imp_cred.o t_imp_name.o \
- t_inq_cred.o t_namingexts.o t_s4u.o t_s4u2proxy_krb5.o t_saslname.o \
- t_spnego.o
+ t_inq_cred.o t_inq_mechs_name.o t_namingexts.o t_s4u.o \
+ t_s4u2proxy_krb5.o t_saslname.o t_spnego.o
COMMON_DEPS= common.o $(GSS_DEPLIBS) $(KRB5_BASE_DEPLIBS)
COMMON_LIBS= common.o $(GSS_LIBS) $(KRB5_BASE_LIBS)
all:: ccinit ccrefresh t_accname t_ccselect t_credstore t_export_cred \
- t_export_name t_gssexts t_imp_cred t_imp_name t_inq_cred t_namingexts \
- t_s4u t_s4u2proxy_krb5 t_saslname t_spnego
+ t_export_name t_gssexts t_imp_cred t_imp_name t_inq_cred \
+ t_inq_mechs_name t_namingexts t_s4u t_s4u2proxy_krb5 t_saslname \
+ t_spnego
check-pytests:: ccinit ccrefresh t_accname t_ccselect t_credstore \
- t_export_cred t_export_name t_imp_cred t_inq_cred t_s4u \
- t_s4u2proxy_krb5 t_spnego
+ t_export_cred t_export_name t_imp_cred t_inq_cred t_inq_mechs_name \
+ t_s4u t_s4u2proxy_krb5 t_spnego
$(RUNPYTEST) $(srcdir)/t_gssapi.py $(PYTESTFLAGS)
$(RUNPYTEST) $(srcdir)/t_ccselect.py $(PYTESTFLAGS)
$(RUNPYTEST) $(srcdir)/t_client_keytab.py $(PYTESTFLAGS)
@@ -54,6 +56,8 @@ t_imp_name: t_imp_name.o $(COMMON_DEPS)
$(CC_LINK) -o $@ t_imp_name.o $(COMMON_LIBS)
t_inq_cred: t_inq_cred.o $(COMMON_DEPS)
$(CC_LINK) -o $@ t_inq_cred.o $(COMMON_LIBS)
+t_inq_mechs_name: t_inq_mechs_name.o $(COMMON_DEPS)
+ $(CC_LINK) -o $@ t_inq_mechs_name.o $(COMMON_LIBS)
t_namingexts: t_namingexts.o $(COMMON_DEPS)
$(CC_LINK) -o $@ t_namingexts.o $(COMMON_LIBS)
t_s4u: t_s4u.o $(COMMON_DEPS)
@@ -68,4 +72,5 @@ t_spnego: t_spnego.o $(COMMON_DEPS)
clean::
$(RM) ccinit ccrefresh t_accname t_ccselect t_credstore t_export_cred \
$(RM) t_export_name t_gssexts t_imp_cred t_imp_name t_inq_cred
- $(RM) t_namingexts t_s4u t_s4u2proxy_krb5 t_saslname t_spnego
+ $(RM) t_inq_mechs_name t_namingexts t_s4u t_s4u2proxy_krb5 t_saslname
+ $(RM) t_spnego
diff --git a/src/tests/gssapi/common.c b/src/tests/gssapi/common.c
index ab968cc..61558a0 100644
--- a/src/tests/gssapi/common.c
+++ b/src/tests/gssapi/common.c
@@ -135,7 +135,9 @@ display_oid(const char *tag, gss_OID oid)
major = gss_oid_to_str(&minor, oid, &buf);
check_gsserr("gss_oid_to_str", major, minor);
- printf("%s:\t%.*s\n", tag, (int)buf.length, (char *)buf.value);
+ if (tag != NULL)
+ printf("%s:\t", tag);
+ printf("%.*s\n", (int)buf.length, (char *)buf.value);
(void)gss_release_buffer(&minor, &buf);
}
diff --git a/src/tests/gssapi/common.h b/src/tests/gssapi/common.h
index 43d692d..e2ca8b9 100644
--- a/src/tests/gssapi/common.h
+++ b/src/tests/gssapi/common.h
@@ -58,7 +58,7 @@ gss_name_t import_name(const char *str);
/* Display name as canonicalized to mech, preceded by tag. */
void display_canon_name(const char *tag, gss_name_t name, gss_OID mech);
-/* Display oid in printable form, preceded by tag. */
+/* Display oid in printable form, preceded by tag (if not NULL). */
void display_oid(const char *tag, gss_OID oid);
/* Display attributes of name, including hex value if noisy is true. */
diff --git a/src/tests/gssapi/t_gssapi.py b/src/tests/gssapi/t_gssapi.py
index b21380f..e453b71 100755
--- a/src/tests/gssapi/t_gssapi.py
+++ b/src/tests/gssapi/t_gssapi.py
@@ -172,4 +172,17 @@ output = realm.run_as_client(['./t_export_name', '-s', 'p:a at b'])
if output != '0401000806062B060105050200000003614062\n':
fail('Unexpected output from t_export_name (SPNEGO krb5 principal)')
+# Test gss_inquire_mechs_for_name behavior.
+krb5_mech = '{ 1 2 840 113554 1 2 2 }'
+spnego_mech = '{ 1 3 6 1 5 5 2 }'
+out = realm.run_as_client(['./t_inq_mechs_name', 'p:a at b'])
+if krb5_mech not in out:
+ fail('t_inq_mechs_name (principal)')
+out = realm.run_as_client(['./t_inq_mechs_name', 'u:x'])
+if krb5_mech not in out or spnego_mech not in out:
+ fail('t_inq_mecs_name (user)')
+out = realm.run_as_client(['./t_inq_mechs_name', 'h:host'])
+if krb5_mech not in out or spnego_mech not in out:
+ fail('t_inq_mecs_name (hostbased)')
+
success('GSSAPI tests')
diff --git a/src/tests/gssapi/t_inq_mechs_name.c b/src/tests/gssapi/t_inq_mechs_name.c
new file mode 100644
index 0000000..da87b86
--- /dev/null
+++ b/src/tests/gssapi/t_inq_mechs_name.c
@@ -0,0 +1,62 @@
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/* tests/gssapi/t_inq_mechs_name.c - Exercise gss_inquire_mechs_for_name */
+/*
+ * Copyright (C) 2012 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.
+ */
+
+/*
+ * Test program to exercise gss_inquire_mechs_for_name by importing a name and
+ * reporting the mech OIDs which are reported as being able to process it.
+ *
+ * Usage: ./t_inq_mechs_name name
+ */
+
+#include <stdio.h>
+
+#include "common.h"
+
+int
+main(int argc, char *argv[])
+{
+ OM_uint32 minor, major;
+ gss_name_t name;
+ gss_OID_set mechs;
+ size_t i;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: t_inq_mechs_for_name name\n");
+ return 1;
+ }
+ name = import_name(argv[1]);
+ major = gss_inquire_mechs_for_name(&minor, name, &mechs);
+ check_gsserr("gss_inquire_mechs_for_name", major, minor);
+ for (i = 0; i < mechs->count; i++)
+ display_oid(NULL, &mechs->elements[i]);
+ return 0;
+}
More information about the cvs-krb5
mailing list