chiark / gitweb /
WIP input file handling
[innduct.git] / tests / authprogs / domain.t
1 #! /bin/sh
2 # $Id: domain.t 5948 2002-12-08 04:20:46Z rra $
3 #
4 # Test suite for domain.
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 domain, expecting it to succeed.  Feed it the client host the way that
15 # nnrpd would.  Takes the client host, the domain to check it against, and the
16 # user expected.
17 runsuccess () {
18     output=`( echo ClientHost: $1 ; echo ClientIP: 127.0.0.1 ; \
19               echo ClientPort: 0 ; echo LocalIP: 127.0.0.1 ; \
20               echo LocalPort: 119) | $domain $2 2>&1`
21     status=$?
22     if test $status = 0 && test x"$output" = x"$3" ; then
23         printcount "ok"
24     else
25         printcount "not ok"
26         echo "  saw: $output"
27         echo "  not: $3"
28     fi
29 }
30
31 # Run domain, expecting it to fail, and make sure it fails with status 1 and
32 # prints out the right error message.  Takes the client host, the domain to
33 # check it against, and the expected output string.
34 runfailure () {
35     output=`( echo ClientHost: $1 ; echo ClientIP: 127.0.0.1 ; \
36               echo ClientPort: 0 ; echo LocalIP: 127.0.0.1 ; \
37               echo LocalPort: 119) | $domain $2 2>&1`
38     status=$?
39     if test $status = 1 && test x"$output" = x"$3" ; then
40         printcount "ok"
41     else
42         printcount "not ok"
43         echo "  saw: $output"
44         echo "  not: $3"
45     fi
46 }
47
48 # Make sure we're in the right directory.
49 domain=domain
50 for dir in authprogs ../authprogs ../../authprogs ; do
51     test -x "$dir/domain" && domain="$dir/domain"
52 done
53
54 # Print the test count.
55 echo 8
56
57 # First, run the tests that we expect to succeed.
58 runsuccess "foo.example.com"     ".example.com" "User:foo"
59 runsuccess "foo.example.com"     "example.com"  "User:foo"
60 runsuccess "foo.bar.example.com" ".example.com" "User:foo.bar"
61 runsuccess "foo.bar.example.com" "example.com"  "User:foo.bar"
62 runsuccess "foo.example.com"     "com"          "User:foo.example"
63
64 # Now, run the tests that we expect to fail.
65 runfailure "example.com"     "example.com" \
66     "domain: host example.com matches the domain exactly"
67 runfailure "foo.example.com" "example.net" \
68     "domain: host foo.example.com didn't match domain example.net"
69 runfailure "fooexample.com"  "example.com" \
70     "domain: host fooexample.com didn't match domain example.com"