Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed logging messages for transport security options (#2310) #2313

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion paramiko/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -3050,7 +3050,12 @@ def _set(self, name, orig, x):
possible = list(getattr(self._transport, orig).keys())
forbidden = [n for n in x if n not in possible]
if len(forbidden) > 0:
raise ValueError("unknown cipher")
name_parsed = name.replace("_preferred_", "")
raise ValueError(
"unknown {} name: {}, possible options: {}".format(
name_parsed, x, possible
0x7162 marked this conversation as resolved.
Show resolved Hide resolved
)
)
setattr(self._transport, name, x)

@property
Expand Down
19 changes: 19 additions & 0 deletions tests/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,25 @@ def testb_security_options_reset(self):
o.kex = o.kex
o.compression = o.compression

def test_security_options_log_message(self):
"""
Test proper logging user experience for security options
"""
opts = self.tc.get_security_options()
# we use mapping to work with legacy attribute names
mapping = {
"ciphers": "ciphers",
"digests": "macs",
"key_types": "keys",
"kex": "kex",
}
for prop in mapping.keys():
with self.assertRaises(ValueError) as exc:
setattr(opts, prop, ["unknown"])
assert str(exc.exception).startswith(
"unknown {} name".format(mapping[prop])
)

def test_compute_key(self):
self.tc.K = 123281095979686581523377256114209720774539068973101330872763622971399429481072519713536292772709507296759612401802191955568143056534122385270077606457721553469730659233569339356140085284052436697480759510519672848743794433460113118986816826624865291116513647975790797391795651716378444844877749505443714557929 # noqa
self.tc.H = b"\x0C\x83\x07\xCD\xE6\x85\x6F\xF3\x0B\xA9\x36\x84\xEB\x0F\x04\xC2\x52\x0E\x9E\xD3" # noqa
Expand Down