]> eyrie.org Git - kerberos/krb5-strength.git/commitdiff
Separate krb5-strength-wordlist filtering to another test
authorRuss Allbery <eagle@eyrie.org>
Tue, 25 Mar 2014 18:21:34 +0000 (11:21 -0700)
committerRuss Allbery <eagle@eyrie.org>
Tue, 25 Mar 2014 18:21:34 +0000 (11:21 -0700)
Rather than merging the wordlist filtering test with the CDB test,
move it to a different unit test program.  This is probably overkill
for the tiny test that we do, but oh well.  It will make adding more
tests later somewhat easier if we ever do.

Makefile.am
tests/TESTS
tests/tools/wordlist-cdb-t
tests/tools/wordlist-t [new file with mode: 0755]

index 3debeb823a3a725caa03e5bf81fc7a287fe49c71..1aaaed1ce0d107a8c3c749e36f2fa40be7063821 100644 (file)
@@ -19,7 +19,8 @@ EXTRA_DIST = .gitignore LICENSE autogen cracklib/HISTORY cracklib/LICENCE  \
        tests/tap/perl/Test/RRA/Config.pm                                  \
        tests/tap/perl/Test/RRA/Automake.pm tests/tools/heimdal-history-t  \
        tests/tools/heimdal-strength-t tests/tools/wordlist-cdb-t          \
-       tests/util/xmalloc-t tools/heimdal-strength.pod
+       tests/tools/wordlist-t tests/util/xmalloc-t                        \
+       tools/heimdal-strength.pod
 
 # Do this globally.  Everything needs to find the Kerberos headers and
 # libraries, and if we're using the system CrackLib, TinyCDB, or SQLite, add
index 72157f3477b91b6809948e7b084b63badd5da87e..fd37488132e1483ab0187008080130231b87e3b9 100644 (file)
@@ -11,6 +11,7 @@ portable/snprintf
 portable/strndup
 tools/heimdal-history
 tools/heimdal-strength
+tools/wordlist
 tools/wordlist-cdb
 util/messages
 util/messages-krb5
index d6fde6a26d7e3781ddb75630880224c50474cabf..32a69992dd4c548aff02022053158556724ec97e 100755 (executable)
@@ -17,7 +17,7 @@ if ! command -v cdb >/dev/null 2>&1 ; then
 fi
 
 # Output the test plan.
-plan 20
+plan 18
 
 # Create a temporary directory and wordlist and ensure it's writable.
 tmpdir=`test_tmpdir`
@@ -84,14 +84,6 @@ ok_program 'Database still contains happenstance' 0 '1' \
 ok_program 'Database does not contain password' 100 '' \
     cdb -q "$tmpdir/wordlist.cdb" password
 
-# Try filtering the wordlist into a new wordlist.
-ok_program 'Wordlist filtering' 0 '' \
-    "$makelist" -a -x '.*d' -l 8 -o "$tmpdir/wordlist.new" "$tmpdir/wordlist"
-( echo 'bitterbane'; echo 'happenstance' ) > "$tmpdir/wordlist.expected"
-ok_program 'Filtered wordlist is correct' 0 '' \
-    cmp "$tmpdir/wordlist.expected" "$tmpdir/wordlist.new"
-rm -f "$tmpdir/wordlist.expected" "$tmpdir/wordlist.new"
-
 # Clean up.
 rm -f "$tmpdir/wordlist.cdb"
 rm -f "$tmpdir/wordlist"
diff --git a/tests/tools/wordlist-t b/tests/tools/wordlist-t
new file mode 100755 (executable)
index 0000000..030a960
--- /dev/null
@@ -0,0 +1,88 @@
+#!/usr/bin/perl
+#
+# Test suite for krb5-strength-wordlist filtering functions.
+#
+# Written by Russ Allbery <eagle@eyrie.org>
+# Copyright 2014
+#     The Board of Trustees of the Leland Stanford Junior University
+#
+# See LICENSE for licensing terms.
+
+use 5.006;
+use strict;
+use warnings;
+
+use lib "$ENV{SOURCE}/tap/perl";
+
+use Encode qw(encode);
+use Test::More;
+use Test::RRA qw(use_prereq);
+use Test::RRA::Automake qw(automake_setup test_file_path test_tmpdir);
+
+# Load prerequisite modules.
+use_prereq('IPC::Run',     'run');
+use_prereq('Perl6::Slurp', 'slurp');
+
+# Set up for testing of an Automake project.
+automake_setup();
+
+# Declare the plan.
+plan tests => 5;
+
+# Run krb5-strength-wordlist with the given arguments and verify that it exits
+# successfully with no output.  For planning purposes, this function will
+# report three tests.
+#
+# @args - Arguments to krb5-strength-wordlist
+#
+# Returns: undef
+sub run_wordlist {
+    my (@args) = @_;
+
+    # Find the krb5-strength-wordlist program in the distribution.
+    my $wordlist = test_file_path('../tools/krb5-strength-wordlist');
+
+    # Run the program, capturing its output and status.
+    my ($out, $err);
+    run([$wordlist, @args], \undef, \$out, \$err);
+    my $status = ($? >> 8);
+
+    # Check the results.
+    is($status, 0,   "krb5-strength-wordlist @args");
+    is($out,    q{}, '...with no output');
+    is($err,    q{}, '...and no errors');
+    return;
+}
+
+# Read the word list that we'll use for testing.
+my @wordlist = slurp(test_file_path('data/wordlist'));
+
+# Generate a filtered version that should match the eventual output of
+# krb5-strength-wordlist, removing words containing the letter d and any
+# shorter than 8 characters.
+my @filtered = grep { !m{d}xms && length($_) >= 8 } @wordlist;
+
+# Add a non-ASCII word to test non-ASCII filtering.
+push(@wordlist, encode('UTF-8', "\N{U+0639}\N{U+0631}\N{U+0628}\N{U+649}"));
+
+# Write the new wordlist, including the non-ASCII word, to a new file.
+my $tmpdir = test_tmpdir();
+open(my $wordlist_fh, q{>}, "$tmpdir/wordlist")
+  or BAIL_OUT("cannot create to $tmpdir/wordlist: $!");
+print {$wordlist_fh} join("\n", @wordlist), "\n"
+  or BAIL_OUT("cannot write to $tmpdir/wordlist: $!");
+close($wordlist_fh)
+  or BAIL_OUT("cannot flush $tmpdir/wordlist: $!");
+
+# Generate a new, filtered word list.  Remove non-ASCII, words containing the
+# letter d, and words shorter than eight characters.
+my @options = qw(-a -x .*d -l 8);
+run_wordlist(@options, '-o', "$tmpdir/wordlist.new", "$tmpdir/wordlist");
+
+# Verify that the new filtered list exists and has the correct content.
+my @got = eval { slurp("$tmpdir/wordlist.new") };
+is($@, q{}, 'New word list exists');
+is_deeply(\@got, \@filtered, '...with correct contents');
+
+# Remove the files created by the test.
+unlink("$tmpdir/wordlist", "$tmpdir/wordlist.new");