]> eyrie.org Git - kerberos/krb5-strength.git/commitdiff
Add tests for configuration syntax errors
authorRuss Allbery <eagle@eyrie.org>
Fri, 13 Dec 2013 20:50:41 +0000 (12:50 -0800)
committerRuss Allbery <eagle@eyrie.org>
Fri, 13 Dec 2013 20:51:45 +0000 (12:51 -0800)
This should really be abstracted out into data, but we'll get to
that at some later date.

TODO
tests/tools/heimdal-strength-t

diff --git a/TODO b/TODO
index 0d3b030682a5e81a0f76911c4553fc8a215df8f5..19e6b97cdaef19081d344e514b6193cea06b6c69 100644 (file)
--- a/TODO
+++ b/TODO
@@ -14,3 +14,6 @@
 
  * Use the realm of the principal changing its password to determine the
    krb5.conf configuration rather than always using the default realm.
+
+ * Refactor the tests for configuration errors in the heimdal-strength
+   test suite into JSON.
index ec39a89fd4d77fca6d120c993d05e36a50e573b0..8a70bade35879f600fa050d37af75501fb8a03e1 100755 (executable)
@@ -158,8 +158,9 @@ for my $type (qw(cdb classes cracklib length letter principal)) {
 # We run the principal tests twice, once for CrackLib and once for CDB.
 $count += scalar(@{ $tests{principal} });
 
-# We can now calculate our plan based on three tests for each password test.
-plan(tests => $count * 3);
+# We can now calculate our plan based on three tests for each password test,
+# plus 21 additional tests for error handling.
+plan(tests => $count * 3 + 21);
 
 # Install the krb5.conf file with a configuration pointing to the test
 # CrackLib dictionary.
@@ -239,6 +240,29 @@ SKIP: {
     }
 }
 
+# Test error for an unknown character class.
+$krb5_conf = create_krb5_conf({ require_classes => 'bogus' });
+local $ENV{KRB5_CONFIG} = $krb5_conf;
+my $error_prefix = 'Cannot initialize strength checking';
+($status, $output, $err) = run_heimdal_strength('test', 'password');
+is($status, 1,   'Bad character class (status)');
+is($output, q{}, '...no output');
+is($err, "$error_prefix: unknown character class bogus\n", '...correct error');
+
+# Test a variety of configuration syntax errors in require_classes.
+my @bad_classes = qw(
+  8 8bogus 8:bogus 4-:bogus 4-bogus 4-8bogus
+);
+my $bad_message = 'bad character class requirement in configuration';
+for my $bad_class (@bad_classes) {
+    $krb5_conf = create_krb5_conf({ require_classes => $bad_class });
+    local $ENV{KRB5_CONFIG} = $krb5_conf;
+    ($status, $output, $err) = run_heimdal_strength('test', 'password');
+    is($status, 1,   "Bad class specification '$bad_class' (status)");
+    is($output, q{}, '...no output');
+    is($err, "$error_prefix: $bad_message: $bad_class\n", '...correct error');
+}
+
 # Clean up our temporary krb5.conf file on any exit.
 END {
     my $tmpdir = $ENV{BUILD} ? "$ENV{BUILD}/tmp" : 'tests/tmp';