Skip to content

Commit

Permalink
Fill in rest of Match exec tests - all pass
Browse files Browse the repository at this point in the history
  • Loading branch information
bitprophet committed Dec 3, 2019
1 parent 004462b commit 951519d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 15 deletions.
8 changes: 8 additions & 0 deletions tests/configs/match-exec
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ Match exec unquoted

Match exec "quoted spaced"
User neil

# Just to prepopulate values for tokenizing subsequent exec
Host target
User intermediate
HostName configured

Match exec "%d %h %L %l %n %p %r %u"
Port 1337
10 changes: 10 additions & 0 deletions tests/configs/match-exec-canonical
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CanonicalDomains paramiko.org
CanonicalizeHostname always

# This will match in the first, uncanonicalized pass
Match !canonical exec uncanonicalized
User defenseless

# And this will match the second time
Match canonical exec canonicalized
Port 8007
5 changes: 5 additions & 0 deletions tests/configs/match-exec-negation
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Match !exec "this succeeds"
User nope

Match !exec "this fails"
User yup
2 changes: 2 additions & 0 deletions tests/configs/match-exec-no-arg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Match exec
User uh-oh
52 changes: 37 additions & 15 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,20 +722,47 @@ def test_does_not_match_nonzero_exit_codes(self, run):
result = load_config("match-exec").lookup("whatever")
assert "user" not in result

def test_tokenizes_argument(self):
# TODO: spot check a few common ones like %h, %p, %l?
assert False
@patch("paramiko.config.getpass")
@patch("paramiko.config.invoke.run")
def test_tokenizes_argument(self, run, getpass, socket):
socket.gethostname.return_value = "local.fqdn"
getpass.getuser.return_value = "gandalf"
# Actual exec value is "%d %h %L %l %n %p %r %u"
parts = (
expanduser("~"),
"configured",
"local",
"some.fake.fqdn",
"target",
"22",
"intermediate",
"gandalf",
)
run.side_effect = _expect(" ".join(parts))
result = load_config("match-exec").lookup("target")
assert result["port"] == "1337"

def test_works_with_canonical(self, socket):
# TODO: before AND after. same file, different key/values, prove both
# show up?
assert False
@patch("paramiko.config.invoke.run")
def test_works_with_canonical(self, run, socket):
# Ensure both stanzas' exec components appear to match
run.side_effect = _expect(["uncanonicalized", "canonicalized"])
result = load_config("match-exec-canonical").lookup("who-cares")
# Prove both config values got loaded up, across the two passes
assert result["user"] == "defenseless"
assert result["port"] == "8007"

def test_may_be_negated(self):
assert False
@patch("paramiko.config.invoke.run")
def test_may_be_negated(self, run):
run.side_effect = _expect("this succeeds")
result = load_config("match-exec-negation").lookup("so-confusing")
# If negation did not work, the first of the two Match exec directives
# would have set User to 'nope' (and/or the second would have NOT set
# User to 'yup')
assert result["user"] == "yup"

def test_requires_an_argument(self):
assert False
with raises(ConfigParseError):
load_config("match-exec-no-arg")


class TestMatchHost(object):
Expand Down Expand Up @@ -775,8 +802,6 @@ def test_matches_canonicalized_name(self, socket):

def test_works_with_canonical_keyword(self, socket):
# NOTE: distinct from 'happens to be canonicalized' above
# TODO: before AND after. same file, different key/values, prove both
# show up?
result = load_config("match-host-canonicalized").lookup("docs")
assert result["user"] == "eric"

Expand Down Expand Up @@ -915,9 +940,6 @@ class TestComplexMatching(object):
# NOTE: this is still a cherry-pick of a few levels of complexity, there's
# no point testing literally all possible combinations.

def test_canonical_exec(self, socket):
assert False

def test_originalhost_host(self):
result = load_config("match-complex").lookup("target")
assert result["hostname"] == "bogus"
Expand Down

0 comments on commit 951519d

Please sign in to comment.