From 01e27d26a5f20fb0a0d8e8ca02f78944639f858a Mon Sep 17 00:00:00 2001 From: Florian Zschocke Date: Sun, 10 Nov 2019 13:04:29 +0100 Subject: In SSH tests ignore an external SSH tool The SshDaemonTest would fail under Windows. That is because JGit looks at the `GIT_SSH` environment variable. If it is set, the tool the variable is pointing to is used for the SSH connection. This is a problem when it is set to "Plink" under Windows, because Plink will not recognize the server key and will not find it in the registry, cached as a known host. Since a test can/should not add the key to the registry but simply wants to ignore it, but there is no way to tell Plink to do so, the tests would fail. This patch filters the `GIT_SSH` environment variable from JGit's `SystemReader`, so that the internal SSH client is used. --- src/test/java/com/gitblit/tests/SshUnitTest.java | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/test/java/com/gitblit/tests/SshUnitTest.java b/src/test/java/com/gitblit/tests/SshUnitTest.java index 075ab43a..2f65fe99 100644 --- a/src/test/java/com/gitblit/tests/SshUnitTest.java +++ b/src/test/java/com/gitblit/tests/SshUnitTest.java @@ -37,6 +37,10 @@ import org.apache.sshd.client.keyverifier.ServerKeyVerifier; import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.common.config.keys.FilePasswordProvider; import org.apache.sshd.common.util.SecurityUtils; +import org.eclipse.jgit.lib.Config; +import org.eclipse.jgit.storage.file.FileBasedConfig; +import org.eclipse.jgit.util.FS; +import org.eclipse.jgit.util.SystemReader; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -63,6 +67,57 @@ public abstract class SshUnitTest extends GitblitUnitTest { public static void startGitblit() throws Exception { generator = SecurityUtils.getKeyPairGenerator("RSA"); started.set(GitBlitSuite.startGitblit()); + + final SystemReader dsr = SystemReader.getInstance(); + SystemReader.setInstance(new SystemReader() + { + final SystemReader defaultsr = dsr; + + @Override + public String getHostname() + { + return defaultsr.getHostname(); + } + + @Override + public String getenv(String variable) + { + if ("GIT_SSH".equalsIgnoreCase(variable)) { + return null; + } + return defaultsr.getenv(variable); + } + + @Override + public String getProperty(String key) + { + return defaultsr.getProperty(key); + } + + @Override + public FileBasedConfig openUserConfig(Config parent, FS fs) + { + return defaultsr.openUserConfig(parent, fs); + } + + @Override + public FileBasedConfig openSystemConfig(Config parent, FS fs) + { + return defaultsr.openSystemConfig(parent, fs); + } + + @Override + public long getCurrentTime() + { + return defaultsr.getCurrentTime(); + } + + @Override + public int getTimezone(long when) + { + return defaultsr.getTimezone(when); + } + }); } @AfterClass -- cgit v1.2.3