@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());
}
@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());
}
@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);
@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));
}
@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());
}