]> eyrie.org Git - kerberos/krb5-strength.git/blobdiff - tests/plugin/mit-t.c
Change CrackLib tests for system CrackLib
[kerberos/krb5-strength.git] / tests / plugin / mit-t.c
index 7026f441a8451ae5cc2c290a9eac3638202de24d..4406e38796e8475c5517c35b8dd70ddc5378ed97 100644 (file)
@@ -26,8 +26,8 @@
 #include <util/macros.h>
 
 /*
- * The password test data, generated from the JSON source.  Defines an arrays
- * named cdb_tests, cracklib_tests, and principal_tests.
+ * The password test data, generated from the JSON source.  Defines arrays
+ * named *_tests, where * is the file name without the ".c" suffix.
  */
 #include <tests/data/passwords/cdb.c>
 #include <tests/data/passwords/classes.c>
@@ -35,6 +35,7 @@
 #include <tests/data/passwords/length.c>
 #include <tests/data/passwords/letter.c>
 #include <tests/data/passwords/principal.c>
+#include <tests/data/passwords/sqlite.c>
 
 
 #ifndef HAVE_KRB5_PWQUAL_PLUGIN_H
@@ -159,20 +160,21 @@ main(void)
 
     /*
      * Calculate how many tests we have.  There are two tests for the module
-     * metadata, six more tests for initializing the plugin, and two tests per
-     * password test.
+     * metadata, seven more tests for initializing the plugin, and two tests
+     * per password test.
      *
      * We run all the CrackLib tests twice, once with an explicit dictionary
      * path and once from krb5.conf configuration.  We run the principal tests
-     * with both CrackLib and CDB configurations.
+     * with CrackLib, CDB, and SQLite configurations.
      */
     count = 2 * ARRAY_SIZE(cracklib_tests);
+    count += 2 * ARRAY_SIZE(length_tests);
     count += ARRAY_SIZE(cdb_tests);
+    count += ARRAY_SIZE(sqlite_tests);
     count += ARRAY_SIZE(classes_tests);
-    count += ARRAY_SIZE(length_tests);
     count += ARRAY_SIZE(letter_tests);
-    count += 2 * ARRAY_SIZE(principal_tests);
-    plan(2 + 6 + count * 2);
+    count += 3 * ARRAY_SIZE(principal_tests);
+    plan(2 + 8 + count * 2);
 
     /* Start with the krb5.conf that contains no dictionary configuration. */
     path = test_file_path("data/krb5.conf");
@@ -242,14 +244,41 @@ main(void)
         is_password_test(ctx, vtable, data, &cracklib_tests[i]);
     vtable->close(ctx, data);
 
+    /*
+     * Add length restrictions and a maximum length for CrackLib.  This should
+     * reject passwords as too short, but let through a password that's
+     * actually in the CrackLib dictionary.
+     */
+    setup_argv[5] = (char *) "minimum_length";
+    setup_argv[6] = (char *) "12";
+    setup_argv[7] = (char *) "cracklib_maxlen";
+    setup_argv[8] = (char *) "11";
+    setup_argv[9] = NULL;
+    run_setup((const char **) setup_argv);
+
+    /* Obtain a new Kerberos context with that krb5.conf file. */
+    krb5_free_context(ctx);
+    code = krb5_init_context(&ctx);
+    if (code != 0)
+        bail_krb5(ctx, code, "cannot initialize Kerberos context");
+
+    /* Run all of the length tests. */
+    code = vtable->open(ctx, NULL, &data);
+    is_int(0, code, "Plugin initialization (length)");
+    if (code != 0)
+        bail("cannot continue after plugin initialization failure");
+    for (i = 0; i < ARRAY_SIZE(length_tests); i++)
+        is_password_test(ctx, vtable, data, &length_tests[i]);
+    vtable->close(ctx, data);
+
     /* Add simple character class configuration to krb5.conf. */
-    setup_argv[5] = (char *) "minimum_different";
-    setup_argv[6] = (char *) "8";
-    setup_argv[7] = (char *) "require_ascii_printable";
+    setup_argv[3] = (char *) "minimum_different";
+    setup_argv[4] = (char *) "8";
+    setup_argv[5] = (char *) "require_ascii_printable";
+    setup_argv[6] = (char *) "true";
+    setup_argv[7] = (char *) "require_non_letter";
     setup_argv[8] = (char *) "true";
-    setup_argv[9] = (char *) "require_non_letter";
-    setup_argv[10] = (char *) "true";
-    setup_argv[11] = NULL;
+    setup_argv[9] = NULL;
     run_setup((const char **) setup_argv);
 
     /* Obtain a new Kerberos context with that krb5.conf file. */
@@ -272,7 +301,7 @@ main(void)
      * the dictionary configuration.
      */
     setup_argv[3] = (char *) "require_classes";
-    setup_argv[4] = (char *) "8-19:lower,upper 8-15:digit 8-11:symbol";
+    setup_argv[4] = (char *) "8-19:lower,upper 8-15:digit 8-11:symbol 24-24:3";
     setup_argv[5] = NULL;
     run_setup((const char **) setup_argv);
 
@@ -286,15 +315,12 @@ main(void)
     code = vtable->open(ctx, NULL, &data);
     is_int(0, code, "Plugin initialization (complex character class)");
     if (code != 0)
-        bail("cannot continue after plugin initialization failure");
+        bail_krb5(ctx, code, "plugin initialization failure");
     for (i = 0; i < ARRAY_SIZE(classes_tests); i++)
         is_password_test(ctx, vtable, data, &classes_tests[i]);
     vtable->close(ctx, data);
 
-    /*
-     * Add length restrictions.  This should only do length checks without any
-     * dictionary checks.
-     */
+    /* Re-run the length restriction checks with no dictionary at all. */
     setup_argv[3] = (char *) "minimum_length";
     setup_argv[4] = (char *) "12";
     setup_argv[5] = NULL;
@@ -326,8 +352,6 @@ main(void)
     setup_argv[4] = dictionary;
     setup_argv[5] = NULL;
     run_setup((const char **) setup_argv);
-    test_file_path_free(setup_argv[0]);
-    test_file_path_free(path);
 
     /* Obtain a new Kerberos context with that krb5.conf file. */
     krb5_free_context(ctx);
@@ -354,6 +378,48 @@ main(void)
 
 #endif /* !HAVE_CDB */
 
+#ifdef HAVE_SQLITE
+
+    /*
+     * If built with SQLite, set up krb5.conf to use a SQLite dictionary
+     * instead.
+     */
+    test_file_path_free(dictionary);
+    dictionary = test_file_path("data/wordlist.sqlite");
+    if (dictionary == NULL)
+        bail("cannot find data/wordlist.sqlite in the test suite");
+    setup_argv[3] = (char *) "password_dictionary_sqlite";
+    setup_argv[4] = dictionary;
+    setup_argv[5] = NULL;
+    run_setup((const char **) setup_argv);
+    test_file_path_free(setup_argv[0]);
+    test_file_path_free(path);
+
+    /* Obtain a new Kerberos context with that krb5.conf file. */
+    krb5_free_context(ctx);
+    code = krb5_init_context(&ctx);
+    if (code != 0)
+        bail_krb5(ctx, code, "cannot initialize Kerberos context");
+
+    /* Run the SQLite and principal tests. */
+    code = vtable->open(ctx, NULL, &data);
+    is_int(0, code, "Plugin initialization (SQLite dictionary)");
+    if (code != 0)
+        bail("cannot continue after plugin initialization failure");
+    for (i = 0; i < ARRAY_SIZE(sqlite_tests); i++)
+        is_password_test(ctx, vtable, data, &sqlite_tests[i]);
+    for (i = 0; i < ARRAY_SIZE(principal_tests); i++)
+        is_password_test(ctx, vtable, data, &principal_tests[i]);
+    vtable->close(ctx, data);
+
+#else /* !HAVE_SQLITE */
+
+    /* Otherwise, mark the SQLite tests as skipped. */
+    count = ARRAY_SIZE(sqlite_tests) + ARRAY_SIZE(principal_tests);
+    skip_block(count * 2 + 1, "not built with SQLite support");
+
+#endif /* !HAVE_SQLITE */
+
     /* Manually clean up after the results of make-krb5-conf. */
     basprintf(&path, "%s/krb5.conf", tmpdir);
     unlink(path);