Mercurial > hg
annotate tests/test-sshserver.py @ 52316:a820a7a1fce0 default tip
setup: require TLS 1.2 support from the Python interpreter (BC)
Before it was optional, and either 1.1 or 1.2 was sufficient. Now that the
default minimum is 1.2, it needs to be present to work out of the box.
The code here is more convoluted than the corresponding checks in `sslutil.py`,
but I'm leaving it alone because it can all be simplified when py38 is dropped.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 21 Nov 2024 11:46:10 -0500 |
parents | 13c004b54cbe |
children |
rev | line source |
---|---|
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
1 import io |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
2 import unittest |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
3 |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
4 import silenttestrunner |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
5 |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
6 from mercurial import ( |
35859
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35772
diff
changeset
|
7 wireprotoserver, |
37785
b4d85bc122bd
wireproto: rename wireproto to wireprotov1server (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37120
diff
changeset
|
8 wireprotov1server, |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
9 ) |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
10 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
11 from mercurial.utils import procutil |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
12 |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36214
diff
changeset
|
13 |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
14 class SSHServerGetArgsTests(unittest.TestCase): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
15 def testparseknown(self): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
16 tests = [ |
36212
7a46f0735904
py3: add b'' to test-sshserver.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36065
diff
changeset
|
17 (b'* 0\nnodes 0\n', [b'', {}]), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
18 ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
19 b'* 0\nnodes 40\n1111111111111111111111111111111111111111\n', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
20 [b'1111111111111111111111111111111111111111', {}], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
21 ), |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
22 ] |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
23 for input, expected in tests: |
36212
7a46f0735904
py3: add b'' to test-sshserver.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36065
diff
changeset
|
24 self.assertparse(b'known', input, expected) |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
25 |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
26 def assertparse(self, cmd, input, expected): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
27 server = mockserver(input) |
51572
13c004b54cbe
wireprotoserver: ensure that output stream gets flushed on exception
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48946
diff
changeset
|
28 ui = server._ui |
13c004b54cbe
wireprotoserver: ensure that output stream gets flushed on exception
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48946
diff
changeset
|
29 proto = wireprotoserver.sshv1protocolhandler(ui, ui.fin, ui.fout) |
37785
b4d85bc122bd
wireproto: rename wireproto to wireprotov1server (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37120
diff
changeset
|
30 _func, spec = wireprotov1server.commands[cmd] |
36214
3b3a987bbbaa
wireprotoserver: move SSH server operation to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36212
diff
changeset
|
31 self.assertEqual(proto.getargs(spec), expected) |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
32 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
33 |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
34 def mockserver(inbytes): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
35 ui = mockui(inbytes) |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
36 repo = mockrepo(ui) |
51572
13c004b54cbe
wireprotoserver: ensure that output stream gets flushed on exception
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48946
diff
changeset
|
37 # note: this test unfortunately doesn't really test anything about |
13c004b54cbe
wireprotoserver: ensure that output stream gets flushed on exception
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48946
diff
changeset
|
38 # `sshserver` class anymore: the entirety of logic of that class lives |
13c004b54cbe
wireprotoserver: ensure that output stream gets flushed on exception
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
48946
diff
changeset
|
39 # in `serveuntil`, and that function is not even called by this test. |
35859
1bf5263fe5cc
wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35772
diff
changeset
|
40 return wireprotoserver.sshserver(ui, repo) |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
41 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
42 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
43 class mockrepo: |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
44 def __init__(self, ui): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
45 self.ui = ui |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
46 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
47 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
48 class mockui: |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
49 def __init__(self, inbytes): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
50 self.fin = io.BytesIO(inbytes) |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
51 self.fout = io.BytesIO() |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
52 self.ferr = io.BytesIO() |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
53 |
41285
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
37785
diff
changeset
|
54 def protectfinout(self): |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
37785
diff
changeset
|
55 return self.fin, self.fout |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
37785
diff
changeset
|
56 |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
37785
diff
changeset
|
57 def restorefinout(self, fin, fout): |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
37785
diff
changeset
|
58 pass |
cf8677cd7286
ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents:
37785
diff
changeset
|
59 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41285
diff
changeset
|
60 |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
61 if __name__ == '__main__': |
35772
7764ff13318e
test-sshserver: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
35752
diff
changeset
|
62 # Don't call into msvcrt to set BytesIO to binary mode |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36214
diff
changeset
|
63 procutil.setbinary = lambda fp: True |
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
64 silenttestrunner.main(__name__) |