]> eyrie.org Git - kerberos/krb5-strength.git/blob - tests/tools/cdbmake-wordlist-t
ca4b53df9a5e142625e8a4f3e96f49969056b5eb
[kerberos/krb5-strength.git] / tests / tools / cdbmake-wordlist-t
1 #!/bin/sh
2 #
3 # Test suite for the cdbmake-wordlist utility.
4 #
5 # Written by Russ Allbery <eagle@eyrie.org>
6 # Copyright 2013
7 #     The Board of Trustees of the Leland Stanford Junior University
8 #
9 # See LICENSE for licensing terms.
10
11 . "$SOURCE/tap/libtap.sh"
12 cd "$BUILD"
13
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'
17 fi
18
19 # Output the test plan.
20 plan 18
21
22 # Create a temporary directory and wordlist and ensure it's writable.
23 tmpdir=`test_tmpdir`
24 wordlist=`test_file_path data/wordlist`
25 if [ -z "$wordlist" ] ; then
26     bail 'cannot find data/wordlist in test suite'
27 fi
28 cp "$wordlist" "$tmpdir/wordlist"
29 chmod 644 "$tmpdir/wordlist"
30
31 # Add a non-ASCII word to the wordlist.
32 echo 'عربى' >> "$tmpdir/wordlist"
33
34 # Test generation of the basic cdb file.
35 cdbmake="$SOURCE/../tools/cdbmake-wordlist"
36 ok_program 'Database generation' 0 '' "$cdbmake" "$tmpdir/wordlist"
37
38 # Check the contents.
39 ok_program 'Database contains password' 0 '1' \
40     cdb -q "$tmpdir/wordlist.cdb" password
41 ok_program 'Database contains one' 0 '1' \
42     cdb -q "$tmpdir/wordlist.cdb" one
43 ok_program 'Database does not contain three' 100 '' \
44     cdb -q "$tmpdir/wordlist.cdb" three
45 ok_program 'Database contains non-ASCII password' 0 '1' \
46     cdb -q "$tmpdir/wordlist.cdb" 'عربى'
47
48 # Regenerate the database, filtering out short passwords.
49 ok_program 'Database generation with no short passwords' 0 '' \
50     "$cdbmake" -l 8 "$tmpdir/wordlist"
51 ok_program 'Database still contains password' 0 '1' \
52     cdb -q "$tmpdir/wordlist.cdb" password
53 ok_program 'Database does not contain one' 100 '' \
54     cdb -q "$tmpdir/wordlist.cdb" one
55
56 # Regenerate the database, filtering out non-ASCII words.
57 ok_program 'Database generation with no non-ASCII' 0 '' \
58     "$cdbmake" -a "$tmpdir/wordlist"
59 ok_program 'Database still contains password' 0 '1' \
60     cdb -q "$tmpdir/wordlist.cdb" password
61 ok_program 'Database does not contain non-ASCII password' 100 '' \
62     cdb -q "$tmpdir/wordlist.cdb" 'عربى'
63
64 # Regenerate the database, filtering out long passwords.
65 ok_program 'Database generation with no long passwords' 0 '' \
66     "$cdbmake" -L 10 "$tmpdir/wordlist"
67 ok_program 'Database still contains bitterbane' 0 '1' \
68     cdb -q "$tmpdir/wordlist.cdb" bitterbane
69 ok_program 'Database does not contain happenstance' 100 '' \
70     cdb -q "$tmpdir/wordlist.cdb" happenstance
71
72 # Regenerate the database, filtering out words starting with b or ending in d.
73 ok_program 'Database generation with no b passwords' 0 '' \
74     "$cdbmake" -x '\Ab' -x '.*d' "$tmpdir/wordlist"
75 ok_program 'Database does not contain bitterbane' 100 '' \
76     cdb -q "$tmpdir/wordlist.cdb" bitterbane
77 ok_program 'Database still contains happenstance' 0 '1' \
78     cdb -q "$tmpdir/wordlist.cdb" happenstance
79 ok_program 'Database does not contain password' 100 '' \
80     cdb -q "$tmpdir/wordlist.cdb" password
81
82 # Clean up.
83 rm -f "$tmpdir/wordlist.cdb"
84 rm -f "$tmpdir/wordlist"
85 rmdir "$tmpdir" 2>/dev/null