]> eyrie.org Git - kerberos/krb5-strength.git/blobdiff - tests/tools/heimdal-strength-t
Update to rra-c-util 10.5
[kerberos/krb5-strength.git] / tests / tools / heimdal-strength-t
index 5e7b1cb9da8cd9f53f8404335979749bddbc7d66..15cded061fa947ec4d0e6d59c601a76571496fd5 100755 (executable)
@@ -3,13 +3,13 @@
 # Test suite for basic Heimdal external strength checking functionality.
 #
 # Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2016-2017, 2020 Russ Allbery <eagle@eyrie.org>
+# Copyright 2016-2017, 2020, 2023 Russ Allbery <eagle@eyrie.org>
 # Copyright 2009, 2012-2014
 #     The Board of Trustees of the Leland Stanford Junior University
 #
 # SPDX-License-Identifier: MIT
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings;
 
@@ -22,7 +22,7 @@ use Test::RRA::Automake qw(test_file_path);
 use_prereq('IPC::Run', 'run');
 use_prereq('JSON');
 use_prereq('Perl6::Slurp', 'slurp');
-use_prereq('Test::More',   '0.87_01');
+use_prereq('Test::More', '0.87_01');
 
 # Data directory to use for dictionaries.
 my $DATADIR = $ENV{BUILD} ? "$ENV{BUILD}/data" : 'tests/data';
@@ -35,6 +35,7 @@ my $DATADIR = $ENV{BUILD} ? "$ENV{BUILD}/data" : 'tests/data';
 # config - Hash of Kerberos configuration to use
 # needs  - Dictionary type name we have to have to run this test
 # tests  - List of classes of tests to run (JSON files in tests/data/passwords)
+#<<<
 my @TESTS = (
     {
         title  => 'Generic tests',
@@ -83,6 +84,7 @@ my @TESTS = (
         title => 'CDB tests',
         config =>
           { password_dictionary_cdb => test_file_path('data/wordlist.cdb') },
+        needs => 'CDB',
         tests => [qw(cdb principal)],
     },
     {
@@ -91,9 +93,11 @@ my @TESTS = (
             password_dictionary_sqlite =>
               test_file_path('data/wordlist.sqlite'),
         },
+        needs => 'SQLite',
         tests => [qw(sqlite principal)],
     },
 );
+#>>>
 
 # Run the newly-built heimdal-strength command and return the status, output,
 # and error output as a list.  If told to expect an immediate error, does not
@@ -122,7 +126,7 @@ sub run_heimdal_strength {
     # Run the password strength checker.
     my ($out, $err);
     my $harness = run([$program, $principal], \$in, \$out, \$err);
-    my $status  = $? >> 8;
+    my $status = $? >> 8;
 
     # Return the results.
     return ($status, $out, $err);
@@ -143,8 +147,8 @@ sub run_heimdal_strength {
 #  Throws: Text exception on failure to run the test program
 sub check_password {
     my ($test_ref) = @_;
-    my $principal  = $test_ref->{principal};
-    my $password   = $test_ref->{password};
+    my $principal = $test_ref->{principal};
+    my $password = $test_ref->{password};
 
     # Run the heimdal-strength command.
     my ($status, $out, $err) = run_heimdal_strength($principal, $password);
@@ -157,9 +161,9 @@ sub check_password {
     is($status, $test_ref->{status} || 0, "$test_ref->{name} (status)");
     if (defined($test_ref->{error})) {
         is($err, $test_ref->{error}, '...error message');
-        is($out, q{},                '...no output');
+        is($out, q{}, '...no output');
     } else {
-        is($err, q{},        '...no errors');
+        is($err, q{}, '...no errors');
         is($out, 'APPROVED', '...approved');
     }
     return;
@@ -176,9 +180,9 @@ sub create_krb5_conf {
     my ($settings_ref) = @_;
 
     # Paths for krb5.conf creation.
-    my $old    = test_file_path('data/krb5.conf');
+    my $old = test_file_path('data/krb5.conf');
     my $tmpdir = $ENV{BUILD} ? "$ENV{BUILD}/tmp" : 'tests/tmp';
-    my $new    = "$tmpdir/krb5.conf";
+    my $new = "$tmpdir/krb5.conf";
 
     # Create a temporary directory for the new file.
     if (!-d $tmpdir) {
@@ -272,10 +276,10 @@ sub run_password_tests {
 #
 # Returns: undef
 sub test_require_classes_syntax {
-    my ($bad_class)  = @_;
+    my ($bad_class) = @_;
     my $error_prefix = 'Cannot initialize strength checking';
-    my $bad_message  = 'bad character class requirement in configuration';
-    my $bad_minimum  = 'bad character class minimum in configuration';
+    my $bad_message = 'bad character class requirement in configuration';
+    my $bad_minimum = 'bad character class minimum in configuration';
 
     # Run heimdal-strength.
     my $krb5_conf = create_krb5_conf({ require_classes => $bad_class });
@@ -283,7 +287,7 @@ sub test_require_classes_syntax {
     my ($status, $output, $err) = run_heimdal_strength('test', 'password', 1);
 
     # Check the results.
-    is($status, 1,   "Bad class specification '$bad_class' (status)");
+    is($status, 1, "Bad class specification '$bad_class' (status)");
     is($output, q{}, '...no output');
     my $expected;
     if ($bad_class =~ m{ \A (\d+ [^-]*) \z | : (\d+) \z }xms) {
@@ -332,13 +336,13 @@ my $krb5_conf = create_krb5_conf({ require_classes => 'bogus' });
 local $ENV{KRB5_CONFIG} = $krb5_conf;
 my $error_prefix = 'Cannot initialize strength checking';
 my ($status, $output, $err) = run_heimdal_strength('test', 'password', 1);
-is($status, 1,   'Bad character class (status)');
+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 10:3 10-11:5
+    8 8bogus 8:bogus 4-:bogus 4-bogus 4-8bogus 10:3 10-11:5
 );
 for my $bad_class (@bad_classes) {
     test_require_classes_syntax($bad_class);
@@ -348,7 +352,7 @@ for my $bad_class (@bad_classes) {
 END {
     my $tmpdir = $ENV{BUILD} ? "$ENV{BUILD}/tmp" : 'tests/tmp';
     my $config = "$tmpdir/krb5.conf";
-    if (-f $config) {
+    if (-e $config) {
         unlink($config) or warn "Cannot remove $config\n";
         rmdir($tmpdir);
     }