]> ruderich.org/simon Gitweb - tlsproxy/tlsproxy.git/blob - tests/tests-authentication.sh
7db352b36fa8e5228414f9f9083535f35f37fbb6
[tlsproxy/tlsproxy.git] / tests / tests-authentication.sh
1 #!/bin/sh
2
3 # Test authentication.
4
5 # Copyright (C) 2013  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 test "x$srcdir" = x && srcdir=.
22 . "$srcdir/common.sh"
23
24
25 # Create necessary files.
26 cleanup
27 tlsproxy_setup
28
29 echo 'dXNlcm5hbWU6cGFzc3dvcmQ=' >digest-authentication
30 tlsproxy_background -a digest-authentication 4711
31 server_background --x509certfile "$srcdir/server.pem" \
32                   --x509keyfile "$srcdir/server-key.pem"
33 wait_for_ports 4711 4712
34 rm -f digest-authentication
35
36 echo missing authentication 1
37 client localhost 4712 invalid \
38     && abort 'client localhost 4712 invalid'
39 test_proxy_authentication_failure
40
41 # Create the proxy certificate.
42 tlsproxy_add localhost server.pem
43
44 echo missing authentication 2
45 client localhost 4712 localhost \
46     && abort 'client localhost 4712 localhost'
47 test_proxy_authentication_failure
48
49 echo invalid authentication 1
50 client localhost 4712 localhost 'username:password' \
51     && abort 'client localhost 4712 localhost username:password'
52 test_proxy_authentication_failure
53
54 echo invalid authentication 2
55 client localhost 4712 localhost 'dXNlcm5hbWU6cGFzc3dvcmQ' \
56     && abort 'client localhost 4712 localhost dXNlcm5hbWU6cGFzc3dvcmQ'
57 test_proxy_authentication_failure
58
59 echo invalid authentication 3
60 client localhost 4712 localhost 'dXNlcm5hbWU6cGFzc3dvcmQ=X' \
61     && abort 'client localhost 4712 localhost dXNlcm5hbWU6cGFzc3dvcmQ=X'
62 test_proxy_authentication_failure
63
64 echo valid authentication
65 client localhost 4712 localhost 'dXNlcm5hbWU6cGFzc3dvcmQ=' \
66     || abort 'client localhost 4712 localhost dXNlcm5hbWU6cGFzc3dvcmQ='
67 test_proxy_successful
68
69 echo valid authentication with invalid certificate
70 tlsproxy_add localhost server-bad.pem
71 client localhost 4712 localhost 'dXNlcm5hbWU6cGFzc3dvcmQ=' \
72     && abort 'client localhost 4712 invalid dXNlcm5hbWU6cGFzc3dvcmQ='
73 test_proxy_successful
74 test_invalid_certificate
75
76
77 # stop_servers in trap-handler
78 cleanup
79
80 exit 0