diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2021-11-13 13:09:01 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2021-11-15 22:26:19 +0100 |
commit | af0126e1d01100fad673b6d0a56a99633383a198 (patch) | |
tree | e7ef9ef6b35c7c91e5f981259a77e1d99be48b61 /org.eclipse.jgit.test/tst/org/eclipse/jgit | |
parent | c4b3ec72faf891120fdd93246503d0bee339f349 (diff) | |
download | jgit-af0126e1d01100fad673b6d0a56a99633383a198.tar.gz jgit-af0126e1d01100fad673b6d0a56a99633383a198.zip |
OpenSshConfigFile: line comments and quoted strings
Bring our SSH config parser up-to-date with respect to changes in
OpenSSH. In particular, they fixed[1] the handling of line comments
such that #-characters inside strings are not considered. This means
that we have to parse strings with escaped quotes correctly.
[1] https://bugzilla.mindrot.org/show_bug.cgi?id=3288
Change-Id: Ifbd9014127e8d51e7c8792e237f3fc2a9a0719d2
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/ssh/OpenSshConfigFileTest.java | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/ssh/OpenSshConfigFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/ssh/OpenSshConfigFileTest.java index 27bae3747c..11741b41aa 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/ssh/OpenSshConfigFileTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/ssh/OpenSshConfigFileTest.java @@ -166,7 +166,38 @@ public class OpenSshConfigFileTest extends RepositoryTestCase { assertPort(2222, lookup("unquoted")); assertPort(2222, lookup("hosts")); assertHost(" spaced\ttld ", lookup("spaced")); - assertHost("bad.tld\"", lookup("bad")); + assertHost("bad.tld", lookup("bad")); + } + + @Test + public void testAdvancedParsing() throws Exception { + // Escaped quotes, and line comments + config("Host foo\n" + + " HostName=\"foo\\\"d.tld\"\n" + + " User= someone#foo\n" + + "Host bar\n" + + " User ' some one#two' # Comment\n" + + " GlobalKnownHostsFile '/a folder/with spaces/hosts' '/other/more hosts' # Comment\n" + + "Host foobar\n" + + " User a\\ u\\ thor\n" + + "Host backslash\n" + + " User some\\one\\\\\\ foo\n" + + "Host backslash_before_quote\n" + + " User \\\"someone#\"el#se\" #Comment\n" + + "Host backslash_in_quote\n" + + " User 'some\\one\\\\\\ foo'\n"); + assertHost("foo\"d.tld", lookup("foo")); + assertUser("someone#foo", lookup("foo")); + HostConfig c = lookup("bar"); + assertUser(" some one#two", c); + assertArrayEquals( + new Object[] { "/a folder/with spaces/hosts", + "/other/more hosts" }, + c.getValues("GlobalKnownHostsFile").toArray()); + assertUser("a u thor", lookup("foobar")); + assertUser("some\\one\\ foo", lookup("backslash")); + assertUser("\"someone#el#se", lookup("backslash_before_quote")); + assertUser("some\\one\\\\ foo", lookup("backslash_in_quote")); } @Test @@ -258,7 +289,7 @@ public class OpenSshConfigFileTest extends RepositoryTestCase { @Test public void testAlias_InheritPreferredAuthentications() throws Exception { config("Host orcz\n" + "\tHostName repo.or.cz\n" + "\n" + "Host *\n" - + "\tPreferredAuthentications publickey, hostbased\n"); + + "\tPreferredAuthentications 'publickey, hostbased'\n"); final HostConfig h = lookup("orcz"); assertNotNull(h); assertEquals("publickey,hostbased", |