3 # Test suite for the CDB handling in the krb5-strength-wordlist utility.
5 # Written by Russ Allbery <eagle@eyrie.org>
7 # The Board of Trustees of the Leland Stanford Junior University
9 # See LICENSE for licensing terms.
11 . "$SOURCE/tap/libtap.sh"
14 # We can't run this test without the cdb utility.
15 if ! command -v cdb >/dev/null 2>&1 ; then
16 skip_all 'cdb utility required for test'
19 # Output the test plan.
22 # Create a temporary directory and wordlist and ensure it's writable.
24 wordlist=`test_file_path data/wordlist`
25 if [ -z "$wordlist" ] ; then
26 bail 'cannot find data/wordlist in test suite'
28 cp "$wordlist" "$tmpdir/wordlist"
29 chmod 644 "$tmpdir/wordlist"
31 # Add a non-ASCII word to the wordlist.
32 echo 'عربى' >> "$tmpdir/wordlist"
34 # Test generation of the basic cdb file.
35 makelist="$SOURCE/../tools/krb5-strength-wordlist"
36 ok_program 'Database generation' 0 '' \
37 "$makelist" -c "$tmpdir/wordlist.cdb" "$tmpdir/wordlist"
40 ok_program 'Database contains password' 0 '1' \
41 cdb -q "$tmpdir/wordlist.cdb" password
42 ok_program 'Database contains one' 0 '1' \
43 cdb -q "$tmpdir/wordlist.cdb" one
44 ok_program 'Database does not contain three' 100 '' \
45 cdb -q "$tmpdir/wordlist.cdb" three
46 ok_program 'Database contains non-ASCII password' 0 '1' \
47 cdb -q "$tmpdir/wordlist.cdb" 'عربى'
49 # Regenerate the database, filtering out short passwords.
50 ok_program 'Database generation with no short passwords' 0 '' \
51 "$makelist" -c "$tmpdir/wordlist.cdb" -l 8 "$tmpdir/wordlist"
52 ok_program 'Database still contains password' 0 '1' \
53 cdb -q "$tmpdir/wordlist.cdb" password
54 ok_program 'Database does not contain one' 100 '' \
55 cdb -q "$tmpdir/wordlist.cdb" one
57 # Regenerate the database, filtering out non-ASCII words.
58 ok_program 'Database generation with no non-ASCII' 0 '' \
59 "$makelist" -c "$tmpdir/wordlist.cdb" -a "$tmpdir/wordlist"
60 ok_program 'Database still contains password' 0 '1' \
61 cdb -q "$tmpdir/wordlist.cdb" password
62 ok_program 'Database does not contain non-ASCII password' 100 '' \
63 cdb -q "$tmpdir/wordlist.cdb" 'عربى'
65 # Regenerate the database, filtering out long passwords.
66 ok_program 'Database generation with no long passwords' 0 '' \
67 "$makelist" -c "$tmpdir/wordlist.cdb" -L 10 "$tmpdir/wordlist"
68 ok_program 'Database still contains bitterbane' 0 '1' \
69 cdb -q "$tmpdir/wordlist.cdb" bitterbane
70 ok_program 'Database does not contain happenstance' 100 '' \
71 cdb -q "$tmpdir/wordlist.cdb" happenstance
73 # Regenerate the database, filtering out words starting with b or ending in d.
74 ok_program 'Database generation with no b passwords' 0 '' \
75 "$makelist" -c "$tmpdir/wordlist.cdb" -x '\Ab' -x '.*d' "$tmpdir/wordlist"
76 ok_program 'Database does not contain bitterbane' 100 '' \
77 cdb -q "$tmpdir/wordlist.cdb" bitterbane
78 ok_program 'Database still contains happenstance' 0 '1' \
79 cdb -q "$tmpdir/wordlist.cdb" happenstance
80 ok_program 'Database does not contain password' 100 '' \
81 cdb -q "$tmpdir/wordlist.cdb" password
83 # Try filtering the wordlist into a new wordlist.
84 ok_program 'Wordlist filtering' 0 '' \
85 "$makelist" -a -x '.*d' -l 8 -o "$tmpdir/wordlist.new" "$tmpdir/wordlist"
86 ( echo 'bitterbane'; echo 'happenstance' ) > "$tmpdir/wordlist.expected"
87 ok_program 'Filtered wordlist is correct' 0 '' \
88 cmp "$tmpdir/wordlist.expected" "$tmpdir/wordlist.new"
89 rm -f "$tmpdir/wordlist.expected" "$tmpdir/wordlist.new"
92 rm -f "$tmpdir/wordlist.cdb"
93 rm -f "$tmpdir/wordlist"
94 rmdir "$tmpdir" 2>/dev/null