annotate tests/dummysmtpd.py @ 52296:4361d787e6cf

rust-cpython: remove outdated test This test wasn't testing anything anymore since the feature has been removed. This was caught by clippy 1.82.0.
author Raphaël Gomès <rgomes@octobus.net>
date Tue, 29 Oct 2024 11:35:41 +0100
parents dbd2d56224d1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47500
23f5ed6dbcb1 run-tests: stop writing a `python3` symlink pointing to python2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45830
diff changeset
1 #!/usr/bin/env python
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
2
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
3 """dummy SMTP server for use in tests"""
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
4
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
5
52093
dbd2d56224d1 tests: force `dummysmtpd.py` to write its log file with '\n' on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 51710
diff changeset
6 import io
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
7 import optparse
50732
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
8 import os
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
9 import socket
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
10 import ssl
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
11 import sys
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
12
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
13 from mercurial import (
36566
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
14 pycompat,
30506
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 29556
diff changeset
15 server,
29556
1b8b6adb2365 tests: use sslutil.wrapserversocket()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29332
diff changeset
16 sslutil,
1b8b6adb2365 tests: use sslutil.wrapserversocket()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29332
diff changeset
17 ui as uimod,
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
18 )
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
19
52093
dbd2d56224d1 tests: force `dummysmtpd.py` to write its log file with '\n' on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 51710
diff changeset
20 if pycompat.iswindows:
dbd2d56224d1 tests: force `dummysmtpd.py` to write its log file with '\n' on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 51710
diff changeset
21 sys.stdout = io.TextIOWrapper(
dbd2d56224d1 tests: force `dummysmtpd.py` to write its log file with '\n' on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 51710
diff changeset
22 sys.stdout.buffer,
dbd2d56224d1 tests: force `dummysmtpd.py` to write its log file with '\n' on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 51710
diff changeset
23 sys.stdout.encoding,
dbd2d56224d1 tests: force `dummysmtpd.py` to write its log file with '\n' on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 51710
diff changeset
24 sys.stdout.errors,
dbd2d56224d1 tests: force `dummysmtpd.py` to write its log file with '\n' on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 51710
diff changeset
25 newline="\n",
dbd2d56224d1 tests: force `dummysmtpd.py` to write its log file with '\n' on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 51710
diff changeset
26 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
27
50732
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
28 if os.environ.get('HGIPV6', '0') == '1':
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
29 family = socket.AF_INET6
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
30 else:
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
31 family = socket.AF_INET
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
32
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
33
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
34 def log(msg):
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
35 sys.stdout.write(msg)
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
36 sys.stdout.flush()
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
37
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
38
50732
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
39 def mocksmtpserversession(conn, addr):
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
40 conn.send(b'220 smtp.example.com ESMTP\r\n')
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
41
51710
8fe7c0e1df1e dummysmtpd: fix EOF handling on newer versions of OpenSSL
Raphaël Gomès <rgomes@octobus.net>
parents: 51700
diff changeset
42 try:
8fe7c0e1df1e dummysmtpd: fix EOF handling on newer versions of OpenSSL
Raphaël Gomès <rgomes@octobus.net>
parents: 51700
diff changeset
43 # Newer versions of OpenSSL raise on EOF
8fe7c0e1df1e dummysmtpd: fix EOF handling on newer versions of OpenSSL
Raphaël Gomès <rgomes@octobus.net>
parents: 51700
diff changeset
44 line = conn.recv(1024)
8fe7c0e1df1e dummysmtpd: fix EOF handling on newer versions of OpenSSL
Raphaël Gomès <rgomes@octobus.net>
parents: 51700
diff changeset
45 except ssl.SSLError:
8fe7c0e1df1e dummysmtpd: fix EOF handling on newer versions of OpenSSL
Raphaël Gomès <rgomes@octobus.net>
parents: 51700
diff changeset
46 log('no hello: EOF\n')
8fe7c0e1df1e dummysmtpd: fix EOF handling on newer versions of OpenSSL
Raphaël Gomès <rgomes@octobus.net>
parents: 51700
diff changeset
47 return
8fe7c0e1df1e dummysmtpd: fix EOF handling on newer versions of OpenSSL
Raphaël Gomès <rgomes@octobus.net>
parents: 51700
diff changeset
48
50732
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
49 if not line.lower().startswith(b'ehlo '):
51710
8fe7c0e1df1e dummysmtpd: fix EOF handling on newer versions of OpenSSL
Raphaël Gomès <rgomes@octobus.net>
parents: 51700
diff changeset
50 # Older versions of OpenSSl don't raise
50732
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
51 log('no hello: %s\n' % line)
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
52 return
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
53
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
54 conn.send(b'250 Hello\r\n')
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
55
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
56 line = conn.recv(1024)
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
57 if not line.lower().startswith(b'mail from:'):
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
58 log('no mail from: %s\n' % line)
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
59 return
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
60 mailfrom = line[10:].decode().rstrip()
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
61 if mailfrom.startswith('<') and mailfrom.endswith('>'):
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
62 mailfrom = mailfrom[1:-1]
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
63
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
64 conn.send(b'250 Ok\r\n')
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
65
50732
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
66 rcpttos = []
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
67 while True:
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
68 line = conn.recv(1024)
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
69 if not line.lower().startswith(b'rcpt to:'):
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
70 break
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
71 rcptto = line[8:].decode().rstrip()
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
72 if rcptto.startswith('<') and rcptto.endswith('>'):
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
73 rcptto = rcptto[1:-1]
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
74 rcpttos.append(rcptto)
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
75
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
76 conn.send(b'250 Ok\r\n')
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
77
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
78 if not line.lower().strip() == b'data':
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
79 log('no rcpt to or data: %s' % line)
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
80
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
81 conn.send(b'354 Go ahead\r\n')
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
82
50732
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
83 data = b''
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
84 while True:
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
85 line = conn.recv(1024)
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
86 if not line:
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
87 log('connection closed before end of data')
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
88 break
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
89 data += line
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
90 if data.endswith(b'\r\n.\r\n'):
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
91 data = data[:-5]
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
92 break
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
93
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
94 conn.send(b'250 Ok\r\n')
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
95
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
96 log(
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
97 '%s from=%s to=%s\n%s\n'
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
98 % (addr[0], mailfrom, ', '.join(rcpttos), data.decode())
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
99 )
35776
75bae69747f0 dummysmtpd: don't die on client connection errors
Matt Harbison <matt_harbison@yahoo.com>
parents: 30559
diff changeset
100
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
101
50732
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
102 def run(host, port, certificate):
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
103 ui = uimod.ui.load()
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
104 with socket.socket(family, socket.SOCK_STREAM) as s:
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
105 s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
106 s.bind((host, port))
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
107 # log('listening at %s:%d\n' % (host, port))
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
108 s.listen(1)
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
109 try:
50732
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
110 while True:
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
111 conn, addr = s.accept()
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
112 if certificate:
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
113 try:
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
114 conn = sslutil.wrapserversocket(
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
115 conn, ui, certfile=certificate
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
116 )
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
117 except ssl.SSLError as e:
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
118 log('%s ssl error: %s\n' % (addr[0], e))
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
119 conn.close()
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
120 continue
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
121 log("connection from %s:%s\n" % addr)
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
122 mocksmtpserversession(conn, addr)
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
123 conn.close()
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
124 except KeyboardInterrupt:
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
125 pass
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
126
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
127
36566
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
128 def _encodestrsonly(v):
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
129 if isinstance(v, type(u'')):
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
130 return v.encode('ascii')
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
131 return v
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
132
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
133
36566
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
134 def bytesvars(obj):
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
135 unidict = vars(obj)
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
136 bd = {k.encode('ascii'): _encodestrsonly(v) for k, v in unidict.items()}
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
137 if bd[b'daemon_postexec'] is not None:
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
138 bd[b'daemon_postexec'] = [
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
139 _encodestrsonly(v) for v in bd[b'daemon_postexec']
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
140 ]
36566
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
141 return bd
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
142
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
143
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
144 def main():
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
145 op = optparse.OptionParser()
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
146 op.add_option('-d', '--daemon', action='store_true')
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
147 op.add_option('--daemon-postexec', action='append')
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
148 op.add_option('-p', '--port', type=int, default=8025)
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
149 op.add_option('-a', '--address', default='localhost')
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
150 op.add_option('--pid-file', metavar='FILE')
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
151 op.add_option('--tls', choices=['none', 'smtps'], default='none')
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
152 op.add_option('--certificate', metavar='FILE')
50729
5644f6286618 tests: show test-patchbomb-tls.t smtp server log
Mads Kiilerich <mads@kiilerich.com>
parents: 48875
diff changeset
153 op.add_option('--logfile', metavar='FILE')
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
154
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
155 opts, args = op.parse_args()
50731
8823e4d411ba tests: fix dummysmtpd argument check
Mads Kiilerich <mads@kiilerich.com>
parents: 50730
diff changeset
156 if (opts.tls == 'smtps') != bool(opts.certificate):
8823e4d411ba tests: fix dummysmtpd argument check
Mads Kiilerich <mads@kiilerich.com>
parents: 50730
diff changeset
157 op.error('--certificate must be specified with --tls=smtps')
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
158
36566
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
159 server.runservice(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
160 bytesvars(opts),
50732
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
161 runfn=lambda: run(opts.address, opts.port, opts.certificate),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
162 runargs=[pycompat.sysexecutable, pycompat.fsencode(__file__)]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
163 + pycompat.sysargv[1:],
50729
5644f6286618 tests: show test-patchbomb-tls.t smtp server log
Mads Kiilerich <mads@kiilerich.com>
parents: 48875
diff changeset
164 logfile=opts.logfile,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
165 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
166
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
167
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
168 if __name__ == '__main__':
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
169 main()