diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2019-12-03 09:39:19 -0500 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2019-12-03 10:50:46 -0500 |
commit | 951519da879384a08e6f4e161ca00ef3a7d290b1 (patch) | |
tree | 5271a74007157caa32f9cf7534e53d156446de63 | |
parent | 004462b40ea156b783456463b042a8f71bd22d1e (diff) |
Fill in rest of Match exec tests - all pass
-rw-r--r-- | tests/configs/match-exec | 8 | ||||
-rw-r--r-- | tests/configs/match-exec-canonical | 10 | ||||
-rw-r--r-- | tests/configs/match-exec-negation | 5 | ||||
-rw-r--r-- | tests/configs/match-exec-no-arg | 2 | ||||
-rw-r--r-- | tests/test_config.py | 52 |
5 files changed, 62 insertions, 15 deletions
diff --git a/tests/configs/match-exec b/tests/configs/match-exec index 88d3f769..763346ea 100644 --- a/tests/configs/match-exec +++ b/tests/configs/match-exec @@ -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 diff --git a/tests/configs/match-exec-canonical b/tests/configs/match-exec-canonical new file mode 100644 index 00000000..794ee9d5 --- /dev/null +++ b/tests/configs/match-exec-canonical @@ -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 diff --git a/tests/configs/match-exec-negation b/tests/configs/match-exec-negation new file mode 100644 index 00000000..937c910e --- /dev/null +++ b/tests/configs/match-exec-negation @@ -0,0 +1,5 @@ +Match !exec "this succeeds" + User nope + +Match !exec "this fails" + User yup diff --git a/tests/configs/match-exec-no-arg b/tests/configs/match-exec-no-arg new file mode 100644 index 00000000..20c16d16 --- /dev/null +++ b/tests/configs/match-exec-no-arg @@ -0,0 +1,2 @@ +Match exec + User uh-oh diff --git a/tests/test_config.py b/tests/test_config.py index bc700f94..29845607 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -722,20 +722,47 @@ class TestMatchExec(object): 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): @@ -775,8 +802,6 @@ class TestMatchHost(object): 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" @@ -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" |