# 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;
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';
# 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',
title => 'CDB tests',
config =>
{ password_dictionary_cdb => test_file_path('data/wordlist.cdb') },
+ needs => 'CDB',
tests => [qw(cdb principal)],
},
{
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
# 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);
# 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);
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;
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) {
#
# 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 });
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) {
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);
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);
}