]> eyrie.org Git - kerberos/krb5-strength.git/blob - tests/mit/plugin-t
Add new plugin API for MIT Kerberos
[kerberos/krb5-strength.git] / tests / mit / plugin-t
1 #!/bin/sh
2 #
3 # Test suite wrapper for the MIT Kerberos shared module API.
4 #
5 # Written by Russ Allbery <rra@stanford.edu>
6 # Copyright 2009, 2010 Board of Trustees, Leland Stanford Jr. University
7 #
8 # See LICENSE for licensing terms.
9
10 . "$SOURCE/tap/libtap.sh"
11 cd "$BUILD/data"
12
13 # Run the plugin program to check a password.  Takes the test description,
14 # the principal, the password, the expected exit status, and the expected
15 # output to standard error.
16 ok_password () {
17     local desc princ password w_status w_stderr status stderr
18     desc="$1"
19     princ="$2"
20     password="$3"
21     w_status="$4"
22     w_stderr="$5"
23     stderr=`"$BUILD/mit/plugin" "$princ" "$password" 2>&1`
24     status="$?"
25     echo "# status: $status"
26     echo "# stderr: $stderr"
27     ok "$desc: status" [ "$status" -eq "$w_status" ]
28     ok "$desc: stderr" [ "$stderr" = "$w_stderr" ]
29 }
30
31 # We need a modified krb5.conf file to add the password_dictionary setting.
32 # We first generate a modified copy of the krb5.conf file that doesn't contain
33 # this setting so that we can test error handling.
34 krb5conf=
35 for p in /etc/krb5.conf /usr/local/etc/krb5.conf data/krb5.conf ; do
36     if [ -r "$p" ] ; then
37         krb5conf="$p"
38         sed -e '/^[     ]*password_dictionary[  ]*=/d' "$p" > ./krb5.conf
39         KRB5_CONFIG="./krb5.conf"
40         export KRB5_CONFIG
41         break
42     fi
43 done
44 if [ -z "$krb5conf" ] ; then
45     skip_all 'no krb5.conf found, put one in tests/data/krb5.conf'
46 fi
47
48 # Check whether we can run the test at all.
49 "$BUILD/mit/plugin" 'test@EXAMPLE.COM' 'test' >/dev/null 2>&1
50 if [ $? = 42 ] ; then
51     rm -f krb5.conf
52     skip_all 'not built against MIT Kerberos libraries'
53 fi
54
55 # Okay, we should be good to run the test suite.
56 plan 28
57
58 # We don't have a password_dictionary setting, so we should fail with an
59 # initialization error.
60 ok_password "no dictionary configured" 'test@EXAMPLE.ORG' 'password' 1 \
61     'password_dictionary not configured in krb5.conf'
62
63 # Now add the password dictionary configuration.
64 cat <<EOF >> ./krb5.conf
65
66 [appdefaults]
67     krb5-strength = {
68         password_dictionary = $BUILD/data/dictionary
69     }
70
71 EOF
72
73 # Check the basic functionality.
74 ok_password "good password" 'test@EXAMPLE.ORG' 'known good password' 0 ''
75 ok_password "password in dictionary" 'test@EXAMPLE.ORG' 'password' 1 \
76     'it is based on a dictionary word'
77 ok_password "password in dictionary" 'test@EXAMPLE.ORG' 'bitter' 1 \
78     'it is based on a dictionary word'
79 ok_password "password in dictionary" 'test@EXAMPLE.ORG' 'rettib' 1 \
80     'it is based on a (reversed) dictionary word'
81 ok_password "password too short" 'test@EXAMPLE.ORG' 'food' 1 \
82     "it is too short"
83 ok_password "password way too short" 'test@EXAMPLE.ORG' 'foo' 1 \
84     "it's WAY too short"
85 ok_password "password empty" 'test@EXAMPLE.ORG' '' 1 \
86     "it's WAY too short"
87 ok_password "password all whitespace" 'test@EXAMPLE.ORG' '          ' 1 \
88     'it does not contain enough DIFFERENT characters'
89 ok_password "password too simplistic" 'test@EXAMPLE.ORG' 'abcdefghi' 1 \
90     'it is too simplistic/systematic'
91 ok_password "not enough characters" 'test@EXAMPLE.ORG' '22413411' 1 \
92     'it does not contain enough DIFFERENT characters'
93 ok_password "password based on principal" 'someuser@EXAMPLE.ORG' 'someuser' \
94     1 'Password based on username'
95 ok_password "password based on principal" 'someuser@EXAMPLE.ORG' 'resuemos' \
96     1 'Password based on username'
97 ok_password "password is principal" 'test@EXAMPLE.ORG' 'test@EXAMPLE.ORG' \
98     1 'Password based on username'
99
100 # Clean up.
101 rm -f krb5.conf