diff options
author | Florian Zschocke <florian.zschocke@devolo.de> | 2019-11-10 13:04:29 +0100 |
---|---|---|
committer | Florian Zschocke <florian.zschocke@devolo.de> | 2019-11-10 18:13:29 +0100 |
commit | 01e27d26a5f20fb0a0d8e8ca02f78944639f858a (patch) | |
tree | 71c2aa9d80f4853d636336df85b598f1ddee99d1 /src/test/java/com | |
parent | 4d7311ba9f65869b39c4e117ab6d45f7a6eb4adc (diff) | |
download | gitblit-01e27d26a5f20fb0a0d8e8ca02f78944639f858a.tar.gz gitblit-01e27d26a5f20fb0a0d8e8ca02f78944639f858a.zip |
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.
Diffstat (limited to 'src/test/java/com')
-rw-r--r-- | src/test/java/com/gitblit/tests/SshUnitTest.java | 55 |
1 files changed, 55 insertions, 0 deletions
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 |