chiark / gitweb /
debugging for thing that crashed
[innduct.git] / tests / authprogs / ckpasswd.t
1 #! /bin/sh
2 # $Id: ckpasswd.t 5572 2002-08-12 06:01:09Z rra $
3 #
4 # Test suite for ckpasswd.
5
6 # The count starts at 1 and is updated each time ok is printed.  printcount
7 # takes "ok" or "not ok".
8 count=1
9 printcount () {
10     echo "$1 $count $2"
11     count=`expr $count + 1`
12 }
13
14 # Run ckpasswd, expecting it to succeed.  Takes a username, a password, any
15 # additional options, and the expected output string.
16 runsuccess () {
17     output=`$ckpasswd -u "$1" -p "$2" $3 2>&1`
18     status=$?
19     if test $status = 0 && test x"$output" = x"$4" ; then
20         printcount "ok"
21     else
22         printcount "not ok"
23         echo "  saw: $output"
24         echo "  not: $4"
25     fi
26 }
27
28 # Run ckpasswd, feeding it the username and password on stdin in the same way
29 # that nnrpd would.  Takes a username, a password, any additional options, and
30 # the expected output string.
31 runpipe () {
32     output=`( echo ClientAuthname: $1 ; echo ClientPassword: $2 ) \
33                 | $ckpasswd $3 2>&1`
34     status=$?
35     if test $status = 0 && test x"$output" = x"$4" ; then
36         printcount "ok"
37     else
38         printcount "not ok"
39         echo "  saw: $output"
40         echo "  not: $4"
41     fi
42 }
43
44 # Run ckpasswd, expecting it to fail, and make sure it fails with status 1 and
45 # prints out the right error message.  Takes a username, a password, any
46 # additional options, and the expected output string.
47 runfailure () {
48     output=`$ckpasswd -u "$1" -p "$2" $3 2>&1`
49     status=$?
50     if test $status = 1 && test x"$output" = x"$4" ; then
51         printcount "ok"
52     else
53         printcount "not ok"
54         echo "  saw: $output"
55         echo "  not: $4"
56     fi
57 }
58
59 # Make sure we're in the right directory.
60 for dir in . authprogs tests/authprogs ; do
61     test -f "$dir/passwd" && cd $dir
62 done
63 ckpasswd=../../authprogs/ckpasswd
64
65 # Print the test count.
66 echo 7
67
68 # First, run the tests that we expect to succeed.
69 runsuccess "foo" "foopass" "-f passwd" "User:foo"
70 runsuccess "bar" "barpass" "-f passwd" "User:bar"
71 runsuccess "baz" ""        "-f passwd" "User:baz"
72 runpipe "foo" "foopass" "-f passwd" "User:foo"
73
74 # Now, run the tests that we expect to fail.
75 runfailure "foo" "barpass" "-f passwd" \
76     "ckpasswd: invalid password for user foo"
77 runfailure "who" "foopass" "-f passwd" \
78     "ckpasswd: user who unknown"
79 runfailure "" "foopass" "-f passwd" \
80     "ckpasswd: null username"