tests/dummysmtpd.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Fri, 23 Feb 2024 11:30:58 +0100
changeset 51432 e79c7320605f
parent 50732 b3a5af04da35
child 51698 8f0b0df79039
permissions -rwxr-xr-x
chainsaw-update: use a graph with branching in graph This will be relevant for the next improvement of `chainsaw-update`.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     6
import optparse
50732
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
     7
import os
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
     8
import socket
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     9
import ssl
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    10
import sys
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    11
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    12
from mercurial import (
36566
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
    13
    pycompat,
30506
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 29556
diff changeset
    14
    server,
29556
1b8b6adb2365 tests: use sslutil.wrapserversocket()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29332
diff changeset
    15
    sslutil,
1b8b6adb2365 tests: use sslutil.wrapserversocket()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29332
diff changeset
    16
    ui as uimod,
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    17
)
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    18
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
    19
50732
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    20
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
    21
    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
    22
else:
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    23
    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
    24
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    25
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    26
def log(msg):
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    27
    sys.stdout.write(msg)
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    28
    sys.stdout.flush()
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    29
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
    30
50732
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    31
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
    32
    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
    33
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    34
    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
    35
    if not line.lower().startswith(b'ehlo '):
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    36
        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
    37
        return
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    38
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    39
    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
    40
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    41
    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
    42
    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
    43
        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
    44
        return
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    45
    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
    46
    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
    47
        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
    48
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    49
    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
    50
50732
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    51
    rcpttos = []
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    52
    while True:
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    53
        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
    54
        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
    55
            break
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    56
        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
    57
        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
    58
            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
    59
        rcpttos.append(rcptto)
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    60
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    61
        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
    62
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    63
    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
    64
        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
    65
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    66
    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
    67
50732
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    68
    data = b''
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    69
    while True:
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    70
        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
    71
        if not line:
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    72
            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
    73
            break
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    74
        data += line
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    75
        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
    76
            data = data[:-5]
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    77
            break
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    78
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    79
    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
    80
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    81
    log(
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    82
        '%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
    83
        % (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
    84
    )
35776
75bae69747f0 dummysmtpd: don't die on client connection errors
Matt Harbison <matt_harbison@yahoo.com>
parents: 30559
diff changeset
    85
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
    86
50732
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    87
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
    88
    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
    89
    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
    90
        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
    91
        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
    92
        # 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
    93
        s.listen(1)
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    94
        try:
50732
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    95
            while True:
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    96
                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
    97
                if certificate:
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    98
                    try:
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
    99
                        conn = sslutil.wrapserversocket(
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
   100
                            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
   101
                        )
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
   102
                    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
   103
                        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
   104
                        conn.close()
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
   105
                        continue
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
   106
                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
   107
                mocksmtpserversession(conn, addr)
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
   108
                conn.close()
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
   109
        except KeyboardInterrupt:
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
   110
            pass
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   111
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
   112
36566
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
   113
def _encodestrsonly(v):
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
   114
    if isinstance(v, type(u'')):
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
   115
        return v.encode('ascii')
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
   116
    return v
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
   117
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
   118
36566
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
   119
def bytesvars(obj):
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
   120
    unidict = vars(obj)
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
   121
    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
   122
    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
   123
        bd[b'daemon_postexec'] = [
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
   124
            _encodestrsonly(v) for v in bd[b'daemon_postexec']
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
   125
        ]
36566
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
   126
    return bd
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
   127
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
   128
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   129
def main():
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   130
    op = optparse.OptionParser()
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   131
    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
   132
    op.add_option('--daemon-postexec', action='append')
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   133
    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
   134
    op.add_option('-a', '--address', default='localhost')
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   135
    op.add_option('--pid-file', metavar='FILE')
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   136
    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
   137
    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
   138
    op.add_option('--logfile', metavar='FILE')
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   139
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   140
    opts, args = op.parse_args()
50731
8823e4d411ba tests: fix dummysmtpd argument check
Mads Kiilerich <mads@kiilerich.com>
parents: 50730
diff changeset
   141
    if (opts.tls == 'smtps') != bool(opts.certificate):
8823e4d411ba tests: fix dummysmtpd argument check
Mads Kiilerich <mads@kiilerich.com>
parents: 50730
diff changeset
   142
        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
   143
36566
ed96d1116302 tests: help dummysmtpd work on python 3
Augie Fackler <augie@google.com>
parents: 35776
diff changeset
   144
    server.runservice(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
   145
        bytesvars(opts),
50732
b3a5af04da35 tests: use simple mock smtp server instead of deprecated asyncore smtpd
Mads Kiilerich <mads@kiilerich.com>
parents: 50731
diff changeset
   146
        runfn=lambda: run(opts.address, opts.port, opts.certificate),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
   147
        runargs=[pycompat.sysexecutable, pycompat.fsencode(__file__)]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
   148
        + pycompat.sysargv[1:],
50729
5644f6286618 tests: show test-patchbomb-tls.t smtp server log
Mads Kiilerich <mads@kiilerich.com>
parents: 48875
diff changeset
   149
        logfile=opts.logfile,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
   150
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39029
diff changeset
   151
29332
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   152
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   153
if __name__ == '__main__':
2bb0ddd8267b tests: add dummy SMTP daemon for SSL tests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   154
    main()