]> eyrie.org Git - kerberos/krb5-strength.git/blob - tests/mit/plugin-t
Add support for new MIT plugin interface, drop old patch
[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, 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/data"
13
14 # Run the plugin program to check a password.  Takes the test description,
15 # the principal, the password, the expected exit status, and the expected
16 # output to standard error.
17 ok_password () {
18     desc="$1"
19     princ="$2"
20     password="$3"
21     w_status="$4"
22     w_stderr="$5"
23     dict="${BUILD}/data/dictionary"
24     stderr=`"$BUILD/mit/plugin" "$princ" "$password" "$dict" 2>&1`
25     status="$?"
26     echo "# status: $status"
27     echo "# stderr: $stderr"
28     ok "$desc: status" [ "$status" -eq "$w_status" ]
29     ok "$desc: stderr" [ "$stderr" = "$w_stderr" ]
30 }
31
32 # We need a modified krb5.conf file to add the password_dictionary setting.
33 # We first generate a modified copy of the krb5.conf file that doesn't contain
34 # this setting so that we can test error handling.
35 krb5conf=
36 for p in /etc/krb5.conf /usr/local/etc/krb5.conf data/krb5.conf ; do
37     if [ -r "$p" ] ; then
38         krb5conf="$p"
39         sed -e '/^[     ]*password_dictionary[  ]*=/d' "$p" > ./krb5.conf
40         KRB5_CONFIG="./krb5.conf"
41         export KRB5_CONFIG
42         break
43     fi
44 done
45 if [ -z "$krb5conf" ] ; then
46     skip_all 'no krb5.conf found, put one in tests/data/krb5.conf'
47 fi
48
49 # Check whether we can run the test at all.
50 "$BUILD/mit/plugin" 'test@EXAMPLE.COM' 'test' >/dev/null 2>&1
51 if [ $? = 42 ] ; then
52     rm -f krb5.conf
53     skip_all 'not built against MIT Kerberos libraries'
54 fi
55
56 # Okay, we should be good to run the test suite.
57 plan `expr 13 \* 2`
58
59 # Check the basic functionality.
60 ok_password "good password" 'test@EXAMPLE.ORG' 'known good password' 0 ''
61 ok_password "password in dictionary" 'test@EXAMPLE.ORG' 'password' 1 \
62     'it is based on a dictionary word'
63 ok_password "password in dictionary" 'test@EXAMPLE.ORG' 'bitterbane' 1 \
64     'it is based on a dictionary word'
65 ok_password "password in dictionary" 'test@EXAMPLE.ORG' 'enabrettib' 1 \
66     'it is based on a (reversed) dictionary word'
67 ok_password "password too short" 'test@EXAMPLE.ORG' 'food' 1 \
68     "it is too short"
69 ok_password "password way too short" 'test@EXAMPLE.ORG' 'foo' 1 \
70     "it's WAY too short"
71 ok_password "password empty" 'test@EXAMPLE.ORG' '' 1 \
72     "it's WAY too short"
73 ok_password "password all whitespace" 'test@EXAMPLE.ORG' '            ' 1 \
74     'it does not contain enough DIFFERENT characters'
75 ok_password "password too simplistic" 'test@EXAMPLE.ORG' 'abcdefghi' 1 \
76     'it is too simplistic/systematic'
77 ok_password "not enough characters" 'test@EXAMPLE.ORG' '22413411' 1 \
78     'it does not contain enough DIFFERENT characters'
79 ok_password "password based on principal" 'someuser@EXAMPLE.ORG' 'someuser' \
80     1 'Password based on username'
81 ok_password "password based on principal" 'someuser@EXAMPLE.ORG' 'resuemos' \
82     1 'Password based on username'
83 ok_password "password is principal" 'test@EXAMPLE.ORG' 'test@EXAMPLE.ORG' \
84     1 'Password based on username'
85
86 # Clean up.
87 rm -f krb5.conf