]> ruderich.org/simon Gitweb - tlsproxy/tlsproxy.git/blob - tests/tests.sh
21fa8f7835fcc934835ab7f8a9bce0aca542c0f6
[tlsproxy/tlsproxy.git] / tests / tests.sh
1 #!/bin/sh
2
3 # tlsproxy test "suite".
4
5
6 # Handle empty $srcdir.
7 [ "x$srcdir" = x ] && srcdir=.
8
9 abort() {
10     echo abort
11     pkill -n gnutls-serv
12     pkill -n tlsproxy
13     exit 1
14 }
15 server() {
16     gnutls-serv --http --port 4712 "$@" >/dev/null 2>/dev/null &
17 }
18 client() {
19     ./client ./proxy-ca.pem "$@" > tmp 2>&1
20 }
21
22 test_proxy_failure() {
23     grep 'proxy failure' tmp >/dev/null || abort
24     grep 'response: HTTP/1.0 503 Forwarding failure' tmp >/dev/null \
25         || abort
26 }
27 test_proxy_successful() {
28     grep 'response: HTTP/1.0 200 Connection established' tmp >/dev/null \
29         || abort
30 }
31 test_invalid_certificate() {
32     grep 'certificate invalid' tmp >/dev/null || abort
33 }
34 test_no_invalid_certificate() {
35     grep 'certificate invalid' tmp >/dev/null && abort
36 }
37
38
39 # Create necessary files.
40 $srcdir/../src/tlsproxy-setup >/dev/null 2>/dev/null
41
42 # Normal tests.
43 ../src/tlsproxy -d2 4711 >/dev/null &
44 server --x509certfile $srcdir/server.pem \
45        --x509keyfile $srcdir/server-key.pem
46 sleep 1
47
48
49 echo invalid hostname
50 client unknown-host 80 - && abort
51 test_proxy_failure
52 test_no_invalid_certificate
53
54 echo missing proxy and server certificate
55 client localhost 4712 invalid || abort
56 test_proxy_successful
57 test_invalid_certificate
58
59 # Create the proxy certificate.
60 $srcdir/../src/tlsproxy-add localhost $srcdir/server.pem \
61     >/dev/null 2>/dev/null
62 rm -f certificate-localhost-server.pem
63
64 echo missing server certificate
65 client localhost 4712 invalid || abort
66 test_proxy_successful
67 test_invalid_certificate
68
69 # Create the proxy and server certificate.
70 $srcdir/../src/tlsproxy-add localhost $srcdir/server.pem \
71     >/dev/null 2>/dev/null
72
73 echo normal connection
74 client localhost 4712 localhost || abort
75 test_proxy_successful
76 test_no_invalid_certificate
77
78
79 # Stop server and try a "MITM" with a bad certificate.
80 echo
81 pkill -n gnutls-serv
82 server --x509certfile $srcdir/server-bad.pem \
83        --x509keyfile $srcdir/server-key.pem
84 sleep 1
85
86
87 echo mitm invalid hostname
88 client unknown-host 80 - && abort
89 test_proxy_failure
90 test_no_invalid_certificate
91
92 echo mitm missing proxy and server certificate
93 client localhost 4712 invalid || abort
94 test_proxy_successful
95 test_invalid_certificate
96
97 # Create the proxy certificate.
98 $srcdir/../src/tlsproxy-add localhost $srcdir/server.pem \
99     >/dev/null 2>/dev/null
100 rm -f certificate-localhost-server.pem
101
102 echo mitm missing server certificate
103 client localhost 4712 invalid || abort
104 test_proxy_successful
105 test_invalid_certificate
106
107 # Create the proxy and server certificate.
108 $srcdir/../src/tlsproxy-add localhost $srcdir/server.pem \
109     >/dev/null 2>/dev/null
110
111 echo mitm normal connection
112 client localhost 4712 invalid || abort
113 test_proxy_successful
114 test_invalid_certificate
115
116
117 pkill -n gnutls-serv
118 pkill -n tlsproxy
119
120 rm -f tmp \
121     certificate-localhost-proxy.pem certificate-localhost-server.pem \
122     proxy-ca-key.pem proxy-ca.pem proxy-invalid.pem proxy-key.pem
123
124 exit 0