Skip to content

Commit

Permalink
Prettify, add %C as acceptable controlpath token, mock gethostname
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrand42 authored and bitprophet committed Mar 11, 2022
1 parent 3f3451f commit f6342fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
8 changes: 3 additions & 5 deletions paramiko/config.py
Expand Up @@ -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"],
Expand Down Expand Up @@ -433,13 +433,11 @@ def _tokenize(self, config, target_hostname, key, value):
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?
Expand Down
1 change: 1 addition & 0 deletions tests/test_config.py
Expand Up @@ -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


Expand Down

0 comments on commit f6342fc

Please sign in to comment.