From: Russ Allbery Date: Mon, 19 Dec 2016 02:58:34 +0000 (-0800) Subject: Handle errors in heimdal-strength tests better X-Git-Tag: release/3.1~5 X-Git-Url: https://git.eyrie.org/?a=commitdiff_plain;h=d9ef752c4e587bd5619d25d99210782f5d5c2caa;p=kerberos%2Fkrb5-strength.git Handle errors in heimdal-strength tests better 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. --- diff --git a/tests/tools/heimdal-strength-t b/tests/tools/heimdal-strength-t index 1c958ac..4f2657e 100755 --- a/tests/tools/heimdal-strength-t +++ b/tests/tools/heimdal-strength-t @@ -3,6 +3,7 @@ # Test suite for basic Heimdal external strength checking functionality. # # Written by Russ Allbery +# Copyright 2016 Russ Allbery # 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');