comparison tests/sshprotoext.py @ 43076:2372284d9457

formatting: blacken the codebase This is using my patch to black (https://github.com/psf/black/pull/826) so we don't un-wrap collection literals. Done with: hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S # skip-blame mass-reformatting only # no-check-commit reformats foo_bar functions Differential Revision: https://phab.mercurial-scm.org/D6971
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:45:02 -0400
parents b4d85bc122bd
children 6000f5b25c9b
comparison
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
23 configitem = registrar.configitem(configtable) 23 configitem = registrar.configitem(configtable)
24 24
25 configitem(b'sshpeer', b'mode', default=None) 25 configitem(b'sshpeer', b'mode', default=None)
26 configitem(b'sshpeer', b'handshake-mode', default=None) 26 configitem(b'sshpeer', b'handshake-mode', default=None)
27 27
28
28 class bannerserver(wireprotoserver.sshserver): 29 class bannerserver(wireprotoserver.sshserver):
29 """Server that sends a banner to stdout.""" 30 """Server that sends a banner to stdout."""
31
30 def serve_forever(self): 32 def serve_forever(self):
31 for i in range(10): 33 for i in range(10):
32 self._fout.write(b'banner: line %d\n' % i) 34 self._fout.write(b'banner: line %d\n' % i)
33 35
34 super(bannerserver, self).serve_forever() 36 super(bannerserver, self).serve_forever()
37
35 38
36 class prehelloserver(wireprotoserver.sshserver): 39 class prehelloserver(wireprotoserver.sshserver):
37 """Tests behavior when connecting to <0.9.1 servers. 40 """Tests behavior when connecting to <0.9.1 servers.
38 41
39 The ``hello`` wire protocol command was introduced in Mercurial 42 The ``hello`` wire protocol command was introduced in Mercurial
40 0.9.1. Modern clients send the ``hello`` command when connecting 43 0.9.1. Modern clients send the ``hello`` command when connecting
41 to SSH servers. This mock server tests behavior of the handshake 44 to SSH servers. This mock server tests behavior of the handshake
42 when ``hello`` is not supported. 45 when ``hello`` is not supported.
43 """ 46 """
47
44 def serve_forever(self): 48 def serve_forever(self):
45 l = self._fin.readline() 49 l = self._fin.readline()
46 assert l == b'hello\n' 50 assert l == b'hello\n'
47 # Respond to unknown commands with an empty reply. 51 # Respond to unknown commands with an empty reply.
48 wireprotoserver._sshv1respondbytes(self._fout, b'') 52 wireprotoserver._sshv1respondbytes(self._fout, b'')
49 l = self._fin.readline() 53 l = self._fin.readline()
50 assert l == b'between\n' 54 assert l == b'between\n'
51 proto = wireprotoserver.sshv1protocolhandler(self._ui, self._fin, 55 proto = wireprotoserver.sshv1protocolhandler(
52 self._fout) 56 self._ui, self._fin, self._fout
57 )
53 rsp = wireprotov1server.dispatch(self._repo, proto, b'between') 58 rsp = wireprotov1server.dispatch(self._repo, proto, b'between')
54 wireprotoserver._sshv1respondbytes(self._fout, rsp.data) 59 wireprotoserver._sshv1respondbytes(self._fout, rsp.data)
55 60
56 super(prehelloserver, self).serve_forever() 61 super(prehelloserver, self).serve_forever()
62
57 63
58 def performhandshake(orig, ui, stdin, stdout, stderr): 64 def performhandshake(orig, ui, stdin, stdout, stderr):
59 """Wrapped version of sshpeer._performhandshake to send extra commands.""" 65 """Wrapped version of sshpeer._performhandshake to send extra commands."""
60 mode = ui.config(b'sshpeer', b'handshake-mode') 66 mode = ui.config(b'sshpeer', b'handshake-mode')
61 if mode == b'pre-no-args': 67 if mode == b'pre-no-args':
71 ui.debug(b'sending unknown3 command\n') 77 ui.debug(b'sending unknown3 command\n')
72 stdin.write(b'unknown3\n') 78 stdin.write(b'unknown3\n')
73 stdin.flush() 79 stdin.flush()
74 return orig(ui, stdin, stdout, stderr) 80 return orig(ui, stdin, stdout, stderr)
75 else: 81 else:
76 raise error.ProgrammingError(b'unknown HANDSHAKECOMMANDMODE: %s' % 82 raise error.ProgrammingError(b'unknown HANDSHAKECOMMANDMODE: %s' % mode)
77 mode) 83
78 84
79 def extsetup(ui): 85 def extsetup(ui):
80 # It's easier for tests to define the server behavior via environment 86 # It's easier for tests to define the server behavior via environment
81 # variables than config options. This is because `hg serve --stdio` 87 # variables than config options. This is because `hg serve --stdio`
82 # has to be invoked with a certain form for security reasons and 88 # has to be invoked with a certain form for security reasons and