]> eyrie.org Git - kerberos/krb5-strength.git/commitdiff
Handle errors in heimdal-strength tests better
authorRuss Allbery <eagle@eyrie.org>
Mon, 19 Dec 2016 02:58:34 +0000 (18:58 -0800)
committerRuss Allbery <eagle@eyrie.org>
Mon, 19 Dec 2016 02:58:34 +0000 (18:58 -0800)
In Travis CI, the heimdal-strength test was failing with a broken
pipe.  Apparently the timing was such that the child process would
exit with an error before IPC::Run could try to write the input,
and then IPC::Run would die with a broken pipe.  Work around this
by allowing a flag to be passed to run_heimdal_strength saying whether
to expect an error, and don't send input in that case.

tests/tools/heimdal-strength-t

index 1c958ac9028b564f0e349526ba74fcfb3df360ec..4f2657e03f419c07891f5273cbd9ec6360dec098 100755 (executable)
@@ -3,6 +3,7 @@
 # Test suite for basic Heimdal external strength checking functionality.
 #
 # Written by Russ Allbery <eagle@eyrie.org>
+# Copyright 2016 Russ Allbery <eagle@eyrie.org>
 # Copyright 2009, 2012, 2013, 2014
 #     The Board of Trustees of the Leland Stanford Junior University
 #
@@ -24,28 +25,33 @@ use_prereq('Perl6::Slurp', 'slurp');
 use_prereq('Test::More',   '0.87_01');
 
 # Run the newly-built heimdal-strength command and return the status, output,
-# and error output as a list.
+# and error output as a list.  If told to expect an immediate error, does not
+# pass input to the process.
 #
 # $principal - Principal to pass to the command
 # $password  - Password to pass to the command
+# $error     - Whether to expect an immediate error
 #
 # Returns: The exit status, standard output, and standard error as a list
 #  Throws: Text exception on failure to run the test program
 sub run_heimdal_strength {
-    my ($principal, $password) = @_;
+    my ($principal, $password, $error) = @_;
 
     # Build the input to the strength checking program.
-    my $in = "principal: $principal\n";
-    $in .= "new-password: $password\n";
-    $in .= "end\n";
+    my $in = q{};
+    if (!$error) {
+        $in .= "principal: $principal\n";
+        $in .= "new-password: $password\n";
+        $in .= "end\n";
+    }
 
     # Find the newly-built password checking program.
     my $program = test_file_path('../tools/heimdal-strength');
 
     # Run the password strength checker.
     my ($out, $err);
-    run([$program, $principal], \$in, \$out, \$err);
-    my $status = ($? >> 8);
+    my $harness = run([$program, $principal], \$in, \$out, \$err);
+    my $status = $? >> 8;
 
     # Return the results.
     return ($status, $out, $err);
@@ -293,7 +299,7 @@ SKIP: {
 $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');
+($status, $output, $err) = run_heimdal_strength('test', 'password', 1);
 is($status, 1,   'Bad character class (status)');
 is($output, q{}, '...no output');
 is($err, "$error_prefix: unknown character class bogus\n", '...correct error');
@@ -306,7 +312,7 @@ 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');
+    ($status, $output, $err) = run_heimdal_strength('test', 'password', 1);
     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');