diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2022-01-30 20:59:26 +0100 |
---|---|---|
committer | Thomas Wolf <thomas.wolf@paranor.ch> | 2022-01-30 20:59:26 +0100 |
commit | 002e13f0f639311f2a1ecd307d4bb18367eab9be (patch) | |
tree | cf3dced7204b8f10f32836ccd688992e11b1eaa0 | |
parent | 8bca5245e0585efb46ece2e3f5ec06a87cd808b6 (diff) | |
download | jgit-002e13f0f639311f2a1ecd307d4bb18367eab9be.tar.gz jgit-002e13f0f639311f2a1ecd307d4bb18367eab9be.zip |
[test] Fix OpenSshConfigFileTest for Windows
The tests assumed that a path like "/tmp" was an absolute path, and
also compared against strings with forward slashes. On Windows, "/tmp"
is not an absolute path and thus resolved against the current directory,
and the separator is a backslash.
Change the tests to use ~/ notation, and test paths resolved against
the (mocked) user home directory. That way, the tests are independent
of the file system used.
Bug: 550111
Change-Id: I1c31608ca83c8d8586256d1586a792e4a33cfaa4
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/ssh/OpenSshConfigFileTest.java | 49 |
1 files changed, 28 insertions, 21 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 1b420e9d86..d065280778 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 @@ -369,20 +369,21 @@ public class OpenSshConfigFileTest extends RepositoryTestCase { @Test public void testListValueSingle() throws Exception { - config("Host orcz\nUserKnownHostsFile /foo/bar\n"); + config("Host orcz\nUserKnownHostsFile ~/foo/bar\n"); final HostConfig c = lookup("orcz"); assertNotNull(c); - assertEquals("/foo/bar", c.getValue("UserKnownHostsFile")); + assertEquals(new File(home, "foo/bar").getPath(), + c.getValue("UserKnownHostsFile")); } @Test public void testListValueMultiple() throws Exception { // Tilde expansion occurs within the parser - config("Host orcz\nUserKnownHostsFile \"~/foo/ba z\" /foo/bar \n"); + config("Host orcz\nUserKnownHostsFile \"~/foo/ba z\" ~/foo/bar \n"); final HostConfig c = lookup("orcz"); assertNotNull(c); assertArrayEquals(new Object[] { new File(home, "foo/ba z").getPath(), - "/foo/bar" }, + new File(home, "foo/bar").getPath() }, c.getValues("UserKnownHostsFile").toArray()); } @@ -403,22 +404,23 @@ public class OpenSshConfigFileTest extends RepositoryTestCase { @Test public void testIdentityFile() throws Exception { - config("Host orcz\nIdentityFile \"~/foo/ba z\"\nIdentityFile /foo/bar"); + config("Host orcz\nIdentityFile \"~/foo/ba z\"\nIdentityFile ~/foo/bar"); final HostConfig h = lookup("orcz"); assertNotNull(h); // Does tilde replacement assertArrayEquals(new Object[] { new File(home, "foo/ba z").getPath(), - "/foo/bar" }, + new File(home, "foo/bar").getPath() }, h.getValues(SshConstants.IDENTITY_FILE).toArray()); } @Test public void testMultiIdentityFile() throws Exception { - config("IdentityFile \"~/foo/ba z\"\nHost orcz\nIdentityFile /foo/bar\nHOST *\nIdentityFile /foo/baz"); + config("IdentityFile \"~/foo/ba z\"\nHost orcz\nIdentityFile ~/foo/bar\nHOST *\nIdentityFile ~/foo/baz"); final HostConfig h = lookup("orcz"); assertNotNull(h); assertArrayEquals(new Object[] { new File(home, "foo/ba z").getPath(), - "/foo/bar", "/foo/baz" }, + new File(home, "foo/bar").getPath(), + new File(home, "foo/baz").getPath() }, h.getValues(SshConstants.IDENTITY_FILE).toArray()); } @@ -434,23 +436,23 @@ public class OpenSshConfigFileTest extends RepositoryTestCase { @Test public void testPattern() throws Exception { - config("Host repo.or.cz\nIdentityFile ~/foo/bar\nHOST *.or.cz\nIdentityFile /foo/baz"); + config("Host repo.or.cz\nIdentityFile ~/foo/bar\nHOST *.or.cz\nIdentityFile ~/foo/baz"); final HostConfig h = lookup("repo.or.cz"); assertNotNull(h); assertIdentity(new File(home, "foo/bar"), h); assertArrayEquals(new Object[] { new File(home, "foo/bar").getPath(), - "/foo/baz" }, + new File(home, "foo/baz").getPath() }, h.getValues(SshConstants.IDENTITY_FILE).toArray()); } @Test public void testMultiHost() throws Exception { - config("Host orcz *.or.cz\nIdentityFile ~/foo/bar\nHOST *.or.cz\nIdentityFile /foo/baz"); + config("Host orcz *.or.cz\nIdentityFile ~/foo/bar\nHOST *.or.cz\nIdentityFile ~/foo/baz"); final HostConfig h1 = lookup("repo.or.cz"); assertNotNull(h1); assertIdentity(new File(home, "foo/bar"), h1); assertArrayEquals(new Object[] { new File(home, "foo/bar").getPath(), - "/foo/baz" }, + new File(home, "foo/baz").getPath() }, h1.getValues(SshConstants.IDENTITY_FILE).toArray()); final HostConfig h2 = lookup("orcz"); assertNotNull(h2); @@ -547,18 +549,20 @@ public class OpenSshConfigFileTest extends RepositoryTestCase { @Test public void testEnVarSubstitution() throws Exception { - config("Host orcz\nIdentityFile /tmp/${TST_VAR}\n" - + "CertificateFile /tmp/${}/foo\nUser ${TST_VAR}\nIdentityAgent /tmp/${TST_VAR/bar"); + config("Host orcz\nIdentityFile ~/tmp/${TST_VAR}\n" + + "CertificateFile ~/tmp/${}/foo\nUser ${TST_VAR}\nIdentityAgent ~/tmp/${TST_VAR/bar"); HostConfig h = lookup("orcz"); assertNotNull(h); - assertEquals("/tmp/TEST", + File tmp = new File(home, "tmp"); + assertEquals(new File(tmp, "TEST").getPath(), h.getValue(SshConstants.IDENTITY_FILE)); // No variable name - assertEquals("/tmp/${}/foo", h.getValue(SshConstants.CERTIFICATE_FILE)); + assertEquals(new File(new File(tmp, "${}"), "foo").getPath(), + h.getValue(SshConstants.CERTIFICATE_FILE)); // User doesn't get env var substitution: assertUser("${TST_VAR}", h); // Unterminated: - assertEquals("/tmp/${TST_VAR/bar", + assertEquals(new File(new File(tmp, "${TST_VAR"), "bar").getPath(), h.getValue(SshConstants.IDENTITY_AGENT)); } @@ -623,13 +627,16 @@ public class OpenSshConfigFileTest extends RepositoryTestCase { @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"); + 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"); HostConfig h = lookup("foo.bar"); assertNotNull(h); assertPort(29418, h); - assertArrayEquals(new Object[] { "/foo", "/bar", "/baz" }, + assertArrayEquals( + new Object[] { new File(home, "foo").getPath(), + new File(home, "bar").getPath(), + new File(home, "baz").getPath() }, h.getValues(SshConstants.IDENTITY_FILE).toArray()); } |