]> ruderich.org/simon Gitweb - tlsproxy/tlsproxy.git/blob - tests/tests-normal.sh
tests: Separate common test data, move tests in tests-normal.sh.
[tlsproxy/tlsproxy.git] / tests / tests-normal.sh
1 #!/bin/sh
2
3 # Normal tlsproxy tests.
4 #
5 # Copyright (C) 2011  Simon Ruderich
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20
21 # Handle empty $srcdir.
22 [ "x$srcdir" = x ] && srcdir=.
23
24 . $srcdir/common.sh
25
26
27 # Create necessary files.
28 $srcdir/../src/tlsproxy-setup >/dev/null 2>/dev/null
29
30 # Normal tests.
31 ../src/tlsproxy -d2 4711 >/dev/null &
32 server --x509certfile $srcdir/server.pem \
33        --x509keyfile $srcdir/server-key.pem
34 sleep 1
35
36
37 echo invalid hostname
38 client unknown-host 80 - && abort
39 test_proxy_failure
40 test_no_invalid_certificate
41
42 echo missing proxy and server certificate
43 client localhost 4712 invalid || abort
44 test_proxy_successful
45 test_invalid_certificate
46
47 # Create the proxy certificate.
48 $srcdir/../src/tlsproxy-add localhost $srcdir/server.pem \
49     >/dev/null 2>/dev/null
50 rm -f certificate-localhost-server.pem
51
52 echo missing server certificate
53 client localhost 4712 invalid || abort
54 test_proxy_successful
55 test_invalid_certificate
56
57 # Create the proxy and server certificate.
58 $srcdir/../src/tlsproxy-add localhost $srcdir/server.pem \
59     >/dev/null 2>/dev/null
60
61 echo normal connection
62 client localhost 4712 localhost || abort
63 test_proxy_successful
64 test_no_invalid_certificate
65
66
67 # Stop server and try a "MITM" with a bad certificate.
68 echo
69 pkill -n gnutls-serv
70 server --x509certfile $srcdir/server-bad.pem \
71        --x509keyfile $srcdir/server-key.pem
72 sleep 1
73
74
75 echo mitm invalid hostname
76 client unknown-host 80 - && abort
77 test_proxy_failure
78 test_no_invalid_certificate
79
80 echo mitm missing proxy and server certificate
81 client localhost 4712 invalid || abort
82 test_proxy_successful
83 test_invalid_certificate
84
85 # Create the proxy certificate.
86 $srcdir/../src/tlsproxy-add localhost $srcdir/server.pem \
87     >/dev/null 2>/dev/null
88 rm -f certificate-localhost-server.pem
89
90 echo mitm missing server certificate
91 client localhost 4712 invalid || abort
92 test_proxy_successful
93 test_invalid_certificate
94
95 # Create the proxy and server certificate.
96 $srcdir/../src/tlsproxy-add localhost $srcdir/server.pem \
97     >/dev/null 2>/dev/null
98
99 echo mitm normal connection
100 client localhost 4712 invalid || abort
101 test_proxy_successful
102 test_invalid_certificate
103
104
105 pkill -n gnutls-serv
106 pkill -n tlsproxy
107
108 rm -f tmp \
109     certificate-localhost-proxy.pem certificate-localhost-server.pem \
110     proxy-ca-key.pem proxy-ca.pem proxy-invalid.pem proxy-key.pem
111
112 exit 0