Debian Codegraph @

tests/test-patchbomb-tls.t

raw
1 #require serve ssl
2
3 $ wait_log() {
4 > pattern="$1"
5 > for s in $TESTDIR/seq.py 10; do
6 > if grep "$pattern" $TESTTMP/log > /dev/null ; then
7 > break
8 > fi
9 > sleep 1
10 > done
11 > }
12
13 Set up SMTP server:
14
15 $ CERTSDIR="$TESTDIR/sslcerts"
16 $ cat "$CERTSDIR/priv.pem" "$CERTSDIR/pub.pem" >> server.pem
17
18 $ "$PYTHON" "$TESTDIR/dummysmtpd.py" -p $HGPORT --pid-file a.pid --logfile log -d \
19 > --tls smtps --certificate `pwd`/server.pem
20 $ cat a.pid >> $DAEMON_PIDS
21
22 Set up repository:
23
24 $ hg init t
25 $ cd t
26 $ cat <<EOF >> .hg/hgrc
27 > [extensions]
28 > patchbomb =
29 > [email]
30 > method = smtp
31 > [smtp]
32 > host = localhost
33 > port = $HGPORT
34 > tls = smtps
35 > EOF
36
37 $ echo a > a
38 $ hg commit -Ama -d '1 0'
39 adding a
40
41 Utility functions:
42
43 $ DISABLECACERTS=
44 $ try () {
45 > hg email $DISABLECACERTS -f quux -t foo -c bar -r tip "$@"
46 > }
47
48 Our test cert is not signed by a trusted CA. It should fail to verify if
49 we are able to load CA certs:
50
51 #if no-defaultcacertsloaded
52 $ try
53 this patch series consists of 1 patches.
54
55
56 (an attempt was made to load CA certificates but none were loaded; see https://mercurial-scm.org/wiki/SecureConnections for how to configure Mercurial to avoid this error)
57 (?i)abort: .*?certificate.verify.failed.* (re)
58 [255]
59
60 $ wait_log "ssl error:"
61 $ cat ../log
62 * ssl error: * (glob)
63 $ : > ../log
64
65 #endif
66
67 #if defaultcacertsloaded
68 $ try
69 this patch series consists of 1 patches.
70
71
72 (the full certificate chain may not be available locally; see "hg help debugssl") (windows !)
73 (?i)abort: .*?certificate.verify.failed.* (re)
74 [255]
75
76 $ wait_log "ssl error:"
77 $ cat ../log
78 * ssl error: * (glob)
79 $ : > ../log
80
81 #endif
82
83 $ DISABLECACERTS="--config devel.disableloaddefaultcerts=true"
84
85 Without certificates:
86
87 $ try --debug
88 this patch series consists of 1 patches.
89
90
91 (using smtps)
92 sending mail: smtp host localhost, port * (glob)
93 (verifying remote certificate)
94 abort: unable to verify security of localhost (no loaded CA certificates); refusing to connect
95 (see https://mercurial-scm.org/wiki/SecureConnections for how to configure Mercurial to avoid this error or set hostsecurity.localhost:fingerprints=sha256:20:de:b3:ad:b4:cd:a5:42:f0:74:41:1c:a2:70:1e:da:6e:c0:5c:16:9e:e7:22:0f:f1:b7:e5:6e:e4:92:af:7e to trust this server)
96 [150]
97
98 $ wait_log "no hello:"
99 $ cat ../log
100 connection from * (glob)
101 no hello: (b''|EOF) (re)
102 $ : > ../log
103
104 With global certificates:
105
106 $ try --debug --config web.cacerts="$CERTSDIR/pub.pem"
107 this patch series consists of 1 patches.
108
109
110 (using smtps)
111 sending mail: smtp host localhost, port * (glob)
112 (verifying remote certificate)
113 sending [PATCH] a ...
114
115 $ wait_log "Thu Jan 01 00:00:01 1970"
116 $ cat ../log
117 connection from * (glob)
118 * from=quux to=foo, bar (glob)
119 MIME-Version: 1.0
120 Content-Type: text/plain; charset="us-ascii"
121 Content-Transfer-Encoding: 7bit
122 Subject: [PATCH] a
123 X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
124 X-Mercurial-Series-Index: 1
125 X-Mercurial-Series-Total: 1
126 Message-Id: <*@test-hostname> (glob)
127 X-Mercurial-Series-Id: <*@test-hostname> (glob)
128 User-Agent: Mercurial-patchbomb* (glob)
129 Date: * (glob)
130 From: quux
131 To: foo
132 Cc: bar
133
134 # HG changeset patch
135 # User test
136 # Date 1 0
137 # Thu Jan 01 00:00:01 1970 +0000
138 # Node ID 8580ff50825a50c8f716709acdf8de0deddcd6ab
139 # Parent 0000000000000000000000000000000000000000
140 a
141
142 diff -r 0000000000000000000000000000000000000000 -r 8580ff50825a50c8f716709acdf8de0deddcd6ab a
143 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
144 +++ b/a Thu Jan 01 00:00:01 1970 +0000
145 @@ -0,0 +1,1 @@
146 +a
147
148 $ : > ../log
149
150 With invalid certificates:
151
152 $ try --config web.cacerts="$CERTSDIR/pub-other.pem"
153 this patch series consists of 1 patches.
154
155
156 (the full certificate chain may not be available locally; see "hg help debugssl") (windows !)
157 (?i)abort: .*?certificate.verify.failed.* (re)
158 [255]
159
160 $ wait_log "ssl error:"
161 $ cat ../log
162 * ssl error: * (glob)
163 $ : > ../log
164
165 $ cd ..