From 2f402436e3c9fdd0ee33473664bf66974822ef65 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Fri, 13 Dec 2013 12:50:41 -0800 Subject: [PATCH] Add tests for configuration syntax errors This should really be abstracted out into data, but we'll get to that at some later date. --- TODO | 3 +++ tests/tools/heimdal-strength-t | 28 ++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 0d3b030..19e6b97 100644 --- 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. diff --git a/tests/tools/heimdal-strength-t b/tests/tools/heimdal-strength-t index ec39a89..8a70bad 100755 --- a/tests/tools/heimdal-strength-t +++ b/tests/tools/heimdal-strength-t @@ -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'; -- 2.39.2