summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Brand <jbrand42@users.noreply.github.com>2022-02-16 00:22:37 +0000
committerJeff Forcier <jeff@bitprophet.org>2022-03-11 18:33:50 -0500
commitf6342fc5f00b48e679e7c2c3579b1b27d94ffc1f (patch)
treee57a2033adf50cc1ef48155cd061a2446de12d1c
parent3f3451fd46353fa173f6c083b1c38438d04a68ea (diff)
downloadparamiko-f6342fc5f00b48e679e7c2c3579b1b27d94ffc1f.tar.gz
Prettify, add %C as acceptable controlpath token, mock gethostname
-rw-r--r--paramiko/config.py8
-rw-r--r--tests/test_config.py1
2 files changed, 4 insertions, 5 deletions
diff --git a/paramiko/config.py b/paramiko/config.py
index 27fdca4f..c2a58e4e 100644
--- a/paramiko/config.py
+++ b/paramiko/config.py
@@ -60,7 +60,7 @@ class SSHConfig(object):
# TODO: do a full scan of ssh.c & friends to make sure we're fully
# compatible across the board, e.g. OpenSSH 8.1 added %n to ProxyCommand.
TOKENS_BY_CONFIG_KEY = {
- "controlpath": ["%h", "%l", "%L", "%n", "%p", "%r", "%u"],
+ "controlpath": ["%C", "%h", "%l", "%L", "%n", "%p", "%r", "%u"],
"hostname": ["%h"],
"identityfile": ["~", "%d", "%h", "%l", "%u", "%r"],
"proxycommand": ["~", "%h", "%p", "%r"],
@@ -433,13 +433,11 @@ class SSHConfig(object):
local_hostname = socket.gethostname().split(".")[0]
local_fqdn = LazyFqdn(config, local_hostname)
homedir = os.path.expanduser("~")
+ tohash = local_hostname + target_hostname + repr(port) + remoteuser
# The actual tokens!
replacements = {
# TODO: %%???
- "%C": sha1((local_hostname +
- target_hostname +
- str(port) +
- remoteuser).encode("utf-8")).hexdigest(),
+ "%C": sha1(tohash.encode()).hexdigest(),
"%d": homedir,
"%h": configured_hostname,
# TODO: %i?
diff --git a/tests/test_config.py b/tests/test_config.py
index 5e9aa059..892b4c92 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -42,6 +42,7 @@ def socket():
# Patch out getfqdn to return some real string for when it gets called;
# some code (eg tokenization) gets mad w/ MagicMocks
mocket.getfqdn.return_value = "some.fake.fqdn"
+ mocket.gethostname.return_value = "local.fake.fqdn"
yield mocket