summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.ssh.jsch.test
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2021-03-20 18:46:13 +0100
committerThomas Wolf <thomas.wolf@paranor.ch>2021-04-01 19:01:13 +0200
commit1de2a9fbe73930504b72904539a3d98d9f9c9738 (patch)
tree13d206c5adfb750edffb785cae639416cba61b5d /org.eclipse.jgit.ssh.jsch.test
parent8edde18c8c3240dadd7f3411d2065d8df28cdc5c (diff)
downloadjgit-1de2a9fbe73930504b72904539a3d98d9f9c9738.tar.gz
jgit-1de2a9fbe73930504b72904539a3d98d9f9c9738.zip
ssh config: do environment variable replacement
OpenSSH 8.4 has introduced simple environment variable substitution for some keys. Implement that feature in our ssh config file parser, too. Bug: 572103 Change-Id: I360f2c5510eea4ec3329aeedf3d29dfefc9163f0 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.ssh.jsch.test')
-rw-r--r--org.eclipse.jgit.ssh.jsch.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java20
1 files changed, 20 insertions, 0 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 4c7e99ea80..4be2271a8c 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
@@ -58,6 +58,7 @@ public class OpenSshConfigTest extends RepositoryTestCase {
FileUtils.mkdir(configFile.getParentFile());
mockSystemReader.setProperty(Constants.OS_USER_NAME_KEY, "jex_junit");
+ mockSystemReader.setProperty("TST_VAR", "TEST");
osc = new OpenSshConfig(home, configFile);
}
@@ -497,4 +498,23 @@ public class OpenSshConfigTest extends RepositoryTestCase {
assertEquals("^ssh-rsa",
c.getValue(SshConstants.PUBKEY_ACCEPTED_ALGORITHMS));
}
+
+ @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");
+ Host h = osc.lookup("orcz");
+ assertNotNull(h);
+ Config c = h.getConfig();
+ assertEquals("/tmp/TEST",
+ c.getValue(SshConstants.IDENTITY_FILE));
+ // No variable name
+ assertEquals("/tmp/${}/foo", c.getValue(SshConstants.CERTIFICATE_FILE));
+ // User doesn't get env var substitution:
+ assertEquals("${TST_VAR}", c.getValue(SshConstants.USER));
+ assertEquals("${TST_VAR}", h.getUser());
+ // Unterminated:
+ assertEquals("/tmp/${TST_VAR/bar",
+ c.getValue(SshConstants.IDENTITY_AGENT));
+ }
}