]> eyrie.org Git - kerberos/krb5-sync.git/commitdiff
Simplify queue-only test using make-krb5-conf
authorRuss Allbery <eagle@eyrie.org>
Thu, 5 Dec 2013 04:36:29 +0000 (20:36 -0800)
committerRuss Allbery <eagle@eyrie.org>
Thu, 5 Dec 2013 04:36:29 +0000 (20:36 -0800)
Generate the krb5.conf file for the queue-only test by adding the
configuration setting on to the default.conf file instead of using
a separate file.  Also redo the setup to be somewhat cleaner.

tests/data/queue.conf [deleted file]
tests/plugin/queue-only-t.c

diff --git a/tests/data/queue.conf b/tests/data/queue.conf
deleted file mode 100644 (file)
index 6c9b986..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-# Test krb5.conf for testing the plugins.  This doesn't have to represent
-# any actual realm.  Note use of a relative path for the queue directory.
-
-[appdefaults]
-    krb5-sync = {
-        ad_keytab         = ad-keytab
-        ad_principal      = service/krb5-sync@EXAMPLE.COM
-        ad_realm          = AD.EXAMPLE.COM
-        ad_admin_server   = ad.example.com
-        ad_ldap_base      = ou=Accounts,dc=ad,dc=example,dc=com
-        ad_instances      = exclude
-        ad_queue_only     = true
-
-        queue_dir         = queue
-        syslog            = false
-    }
-
-[libdefaults]
-    default_realm         = EXAMPLE.COM
index ada79216b7676425db5d251f7dc74a18b6d2f898..56ba4955a33e38c8ac783b1b611d1fc48fa4ace7 100644 (file)
@@ -20,6 +20,8 @@
 
 #include <plugin/internal.h>
 #include <tests/tap/basic.h>
+#include <tests/tap/kerberos.h>
+#include <tests/tap/process.h>
 #include <tests/tap/string.h>
 #include <tests/tap/sync.h>
 
 int
 main(void)
 {
-    char *tmpdir, *krb5conf, *env;
+    char *path, *tmpdir, *krb5_config;
+    char *setup_argv[6];
     krb5_context ctx;
     krb5_principal princ;
     krb5_error_code code;
     kadm5_hook_modinfo *config;
 
+    /* Define the plan. */
+    plan(23);
+
+    /* Set up a temporary directory and queue relative to it. */
+    path = test_file_path("data/default.conf");
     tmpdir = test_tmpdir();
     if (chdir(tmpdir) < 0)
         sysbail("cannot cd to %s", tmpdir);
-    krb5conf = test_file_path("data/queue.conf");
-    if (krb5conf == NULL)
-        bail("cannot find tests/data/queue.conf");
     if (mkdir("queue", 0777) < 0)
         sysbail("cannot mkdir queue");
-    basprintf(&env, "KRB5_CONFIG=%s", krb5conf);
-    if (putenv(env) < 0)
-        sysbail("cannot set KRB5_CONFIG");
+
+    /* Set up our krb5.conf with ad_queue_only set. */
+    setup_argv[0] = test_file_path("data/make-krb5-conf");
+    if (setup_argv[0] == NULL)
+        bail("cannot find data/make-krb5-conf in the test suite");
+    setup_argv[1] = path;
+    setup_argv[2] = tmpdir;
+    setup_argv[3] = (char *) "ad_queue_only";
+    setup_argv[4] = (char *) "true";
+    setup_argv[5] = NULL;
+    run_setup((const char **) setup_argv);
+
+    /* Point KRB5_CONFIG at the newly-generated krb5.conf file. */
+    basprintf(&krb5_config, "KRB5_CONFIG=%s/krb5.conf", tmpdir);
+    putenv(krb5_config);
+
+    /* Obtain a new Kerberos context with that krb5.conf file. */
     code = krb5_init_context(&ctx);
     if (code != 0)
-        bail("cannot create Kerberos context (%d)", (int) code);
-    code = krb5_parse_name(ctx, "test@EXAMPLE.COM", &princ);
-    if (code != 0)
-        bail("cannot parse principal: %s", krb5_get_error_message(ctx, code));
-
-    plan(23);
+        bail_krb5(ctx, code, "cannot initialize Kerberos context");
 
     /* Test init. */
     is_int(0, sync_init(ctx, &config), "sync_init succeeds");
     ok(config != NULL, "...and config is non-NULL");
 
     /* Create a password change and be sure it's queued. */
+    code = krb5_parse_name(ctx, "test@EXAMPLE.COM", &princ);
+    if (code != 0)
+        bail_krb5(ctx, code, "cannot parse principal test@EXAMPLE.COM");
     code = sync_chpass(config, ctx, princ, "foobar");
     is_int(0, code, "sync_chpass succeeds");
     sync_queue_check_password("queue", "test", "foobar");
@@ -79,13 +96,18 @@ main(void)
     /* Shut down the plugin. */
     sync_close(ctx, config);
 
-    /* Clean up. */
-    krb5_free_principal(ctx, princ);
-    krb5_free_context(ctx);
-    test_file_path_free(krb5conf);
+    /* Manually clean up after the results of make-krb5-conf. */
+    basprintf(&path, "%s/krb5.conf", tmpdir);
+    unlink(path);
+    free(path);
     if (chdir("..") < 0)
         sysbail("cannot chdir to parent directory");
     test_tmpdir_free(tmpdir);
-    free(env);
+
+    /* Clean up. */
+    krb5_free_principal(ctx, princ);
+    krb5_free_context(ctx);
+    putenv((char *) "KRB5_CONFIG=");
+    free(krb5_config);
     return 0;
 }