Skip to content

Commit

Permalink
Never actually handled optional-ness of Invoke import
Browse files Browse the repository at this point in the history
Was just silently failing, wahoops
  • Loading branch information
bitprophet committed Dec 3, 2019
1 parent 6da063a commit 1919964
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions paramiko/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ def _does_match(self, match_list, target_hostname, canonical, options):
exec_cmd = self._tokenize(
options, target_hostname, "match-exec", param
)
# This is the laziest spot in which we can get mad about an
# inability to import Invoke.
if invoke is None:
raise invoke_import_error
# Like OpenSSH, we 'redirect' stdout but let stderr bubble up
passed = invoke.run(exec_cmd, hide="stdout", warn=True).ok
# Tackle any 'passed, but was negated' results from above
Expand Down
9 changes: 9 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,15 @@ def inner(command, *args, **kwargs):


class TestMatchExec(object):
@patch("paramiko.config.invoke", new=None)
@patch("paramiko.config.invoke_import_error", new=ImportError("meh"))
def test_raises_invoke_ImportErrors_at_runtime(self):
# Not an ideal test, but I don't know of a non-bad way to fake out
# module-time ImportErrors. So we mock the symptoms. Meh!
with raises(ImportError) as info:
load_config("match-exec").lookup("oh-noes")
assert str(info.value) == "meh"

@patch("paramiko.config.invoke.run")
@mark.parametrize(
"cmd,user",
Expand Down

0 comments on commit 1919964

Please sign in to comment.