diff options
Diffstat (limited to 'org.eclipse.jgit.ssh.jsch.test')
-rw-r--r-- | org.eclipse.jgit.ssh.jsch.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java | 74 |
1 files changed, 73 insertions, 1 deletions
diff --git a/org.eclipse.jgit.ssh.jsch.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java b/org.eclipse.jgit.ssh.jsch.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java index 4be2271a8c..93d85e2e90 100644 --- a/org.eclipse.jgit.ssh.jsch.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java +++ b/org.eclipse.jgit.ssh.jsch.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2017 Google Inc. and others + * Copyright (C) 2008, 2021 Google Inc. and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -517,4 +517,76 @@ public class OpenSshConfigTest extends RepositoryTestCase { assertEquals("/tmp/${TST_VAR/bar", c.getValue(SshConstants.IDENTITY_AGENT)); } + + @Test + public void testNegativeMatch() throws Exception { + config("Host foo.bar !foobar.baz *.baz\n" + "Port 29418\n"); + Host h = osc.lookup("foo.bar"); + assertNotNull(h); + assertEquals(29418, h.getPort()); + h = osc.lookup("foobar.baz"); + assertNotNull(h); + assertEquals(22, h.getPort()); + h = osc.lookup("foo.baz"); + assertNotNull(h); + assertEquals(29418, h.getPort()); + } + + @Test + public void testNegativeMatch2() throws Exception { + // Negative match after the positive match. + config("Host foo.bar *.baz !foobar.baz\n" + "Port 29418\n"); + Host h = osc.lookup("foo.bar"); + assertNotNull(h); + assertEquals(29418, h.getPort()); + h = osc.lookup("foobar.baz"); + assertNotNull(h); + assertEquals(22, h.getPort()); + h = osc.lookup("foo.baz"); + assertNotNull(h); + assertEquals(29418, h.getPort()); + } + + @Test + public void testNoMatch() throws Exception { + config("Host !host1 !host2\n" + "Port 29418\n"); + Host h = osc.lookup("host1"); + assertNotNull(h); + assertEquals(22, h.getPort()); + h = osc.lookup("host2"); + assertNotNull(h); + assertEquals(22, h.getPort()); + h = osc.lookup("host3"); + assertNotNull(h); + assertEquals(22, h.getPort()); + } + + @Test + public void testMultipleMatch() throws Exception { + config("Host foo.bar\nPort 29418\nIdentityFile /foo\n\n" + + "Host *.bar\nPort 22\nIdentityFile /bar\n" + + "Host foo.bar\nPort 47\nIdentityFile /baz\n"); + Host h = osc.lookup("foo.bar"); + assertNotNull(h); + assertEquals(29418, h.getPort()); + assertArrayEquals(new Object[] { "/foo", "/bar", "/baz" }, + h.getConfig().getValues("IdentityFile")); + } + + @Test + public void testWhitespace() throws Exception { + config("Host foo \tbar baz\nPort 29418\n"); + Host h = osc.lookup("foo"); + assertNotNull(h); + assertEquals(29418, h.getPort()); + h = osc.lookup("bar"); + assertNotNull(h); + assertEquals(29418, h.getPort()); + h = osc.lookup("baz"); + assertNotNull(h); + assertEquals(29418, h.getPort()); + h = osc.lookup("\tbar"); + assertNotNull(h); + assertEquals(22, h.getPort()); + } } |