Mercurial > public > mercurial-scm > hg-stable
diff tests/test-ssh-proto.t @ 36253:464bedc0fdb4
wireprotoserver: handle SSH protocol version 2 upgrade requests
This commit teaches the SSH server to recognize the "upgrade"
request line that clients send when they wish to switch the
channel to version 2 of the SSH protocol.
Servers don't honor upgrade requests unless an experimental config
option is set.
Since the built-in server now supports upgrade requests, our test
server to test the handshake has been deleted. Existing tests
use the built-in server and their output doesn't change.
The upgrade is handled in our state machine. The end result is a bit
wonky, as the server transitions back to version 1 state immediately
after upgrading. But this will change as soon as version 2 has an
actual protocol that differs from version 1.
Tests demonstrating that the new server is a bit more strict about
the upgrade handshake have been added.
Differential Revision: https://phab.mercurial-scm.org/D2204
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 12 Feb 2018 16:33:54 -0800 |
parents | 465858451347 |
children | 7218e93ade47 |
line wrap: on
line diff
--- a/tests/test-ssh-proto.t Thu Feb 08 15:09:59 2018 -0800 +++ b/tests/test-ssh-proto.t Mon Feb 12 16:33:54 2018 -0800 @@ -453,9 +453,17 @@ local: no pushable: yes +Enable version 2 support on server. We need to do this in hgrc because we can't +use --config with `hg serve --stdio`. + + $ cat >> server/.hg/hgrc << EOF + > [experimental] + > sshserver.support-v2 = true + > EOF + Send an upgrade request to a server that supports upgrade - $ SSHSERVERMODE=upgradev2 hg -R server serve --stdio << EOF + $ hg -R server serve --stdio << EOF > upgrade this-is-some-token proto=exp-ssh-v2-0001 > hello > between @@ -466,7 +474,7 @@ 383 capabilities: lookup changegroupsubset branchmap pushkey known getbundle unbundlehash batch streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN - $ SSHSERVERMODE=upgradev2 hg --config experimental.sshpeer.advertise-v2=true --debug debugpeer ssh://user@dummy/server + $ hg --config experimental.sshpeer.advertise-v2=true --debug debugpeer ssh://user@dummy/server running * "*/tests/dummyssh" 'user@dummy' 'hg -R server serve --stdio' (glob) (no-windows !) running * "*\tests/dummyssh" "user@dummy" "hg -R server serve --stdio" (glob) (windows !) sending upgrade request: * proto=exp-ssh-v2-0001 (glob) @@ -482,7 +490,7 @@ Verify the peer has capabilities - $ SSHSERVERMODE=upgradev2 hg --config experimental.sshpeer.advertise-v2=true --debug debugcapabilities ssh://user@dummy/server + $ hg --config experimental.sshpeer.advertise-v2=true --debug debugcapabilities ssh://user@dummy/server running * "*/tests/dummyssh" 'user@dummy' 'hg -R server serve --stdio' (glob) (no-windows !) running * "*\tests/dummyssh" "user@dummy" "hg -R server serve --stdio" (glob) (windows !) sending upgrade request: * proto=exp-ssh-v2-0001 (glob) @@ -527,3 +535,96 @@ remote-changegroup http https + +Command after upgrade to version 2 is processed + + $ hg -R server serve --stdio << EOF + > upgrade this-is-some-token proto=exp-ssh-v2-0001 + > hello + > between + > pairs 81 + > 0000000000000000000000000000000000000000-0000000000000000000000000000000000000000hello + > EOF + upgraded this-is-some-token exp-ssh-v2-0001 + 383 + capabilities: lookup changegroupsubset branchmap pushkey known getbundle unbundlehash batch streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN + 384 + capabilities: lookup changegroupsubset branchmap pushkey known getbundle unbundlehash batch streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN + +Multiple upgrades is not allowed + + $ hg -R server serve --stdio << EOF + > upgrade this-is-some-token proto=exp-ssh-v2-0001 + > hello + > between + > pairs 81 + > 0000000000000000000000000000000000000000-0000000000000000000000000000000000000000upgrade another-token proto=irrelevant + > hello + > EOF + upgraded this-is-some-token exp-ssh-v2-0001 + 383 + capabilities: lookup changegroupsubset branchmap pushkey known getbundle unbundlehash batch streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN + cannot upgrade protocols multiple times + - + + +Malformed upgrade request line (not exactly 3 space delimited tokens) + + $ hg -R server serve --stdio << EOF + > upgrade + > EOF + 0 + + $ hg -R server serve --stdio << EOF + > upgrade token + > EOF + 0 + + $ hg -R server serve --stdio << EOF + > upgrade token foo=bar extra-token + > EOF + 0 + +Upgrade request to unsupported protocol is ignored + + $ hg -R server serve --stdio << EOF + > upgrade this-is-some-token proto=unknown1,unknown2 + > hello + > between + > pairs 81 + > 0000000000000000000000000000000000000000-0000000000000000000000000000000000000000 + > EOF + 0 + 384 + capabilities: lookup changegroupsubset branchmap pushkey known getbundle unbundlehash batch streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN + 1 + + +Upgrade request must be followed by hello + between + + $ hg -R server serve --stdio << EOF + > upgrade token proto=exp-ssh-v2-0001 + > invalid + > EOF + malformed handshake protocol: missing hello + - + + + $ hg -R server serve --stdio << EOF + > upgrade token proto=exp-ssh-v2-0001 + > hello + > invalid + > EOF + malformed handshake protocol: missing between + - + + + $ hg -R server serve --stdio << EOF + > upgrade token proto=exp-ssh-v2-0001 + > hello + > between + > invalid + > EOF + malformed handshake protocol: missing pairs 81 + - +