# 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
#
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);
$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');
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');