Adding ssh proxy capability (#1054)

Adding the capability to configure a proxy host and port for ssh git
repo connections.
This commit is contained in:
bisigc
2018-06-27 15:56:30 +02:00
committed by Ryan Baxter
parent dbf29ad12c
commit 496412bd8e
4 changed files with 88 additions and 3 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.config.server.ssh;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -35,6 +36,7 @@ import org.springframework.core.io.Resource;
import com.jcraft.jsch.HostKey;
import com.jcraft.jsch.HostKeyRepository;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.ProxyHTTP;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.UserInfo;
@@ -169,6 +171,39 @@ public class PropertyBasedSshSessionFactoryTest {
Assert.assertEquals("/ssh/known_hosts", captor.getValue());
}
@Test
public void proxyHostIsSet() {
SshUri sshKey = new SshUriProperties.SshUriPropertiesBuilder()
.uri("git@gitlab.example.local:someorg/somerepo.git")
.privateKey(PRIVATE_KEY)
.hostKey(HOST_KEY)
.hostKeyAlgorithm(HOST_KEY_ALGORITHM)
.proxyHost("localhost")
.proxyPort(8080)
.build();
setupSessionFactory(sshKey);
factory.configure(hc, session);
ArgumentCaptor<ProxyHTTP> captor = ArgumentCaptor.forClass(ProxyHTTP.class);
verify(session).setProxy(captor.capture());
Assert.assertNotNull(captor.getValue());
}
@Test(expected = IllegalArgumentException.class)
public void proxyPortIsMissing() {
SshUri sshKey = new SshUriProperties.SshUriPropertiesBuilder()
.uri("git@gitlab.example.local:someorg/somerepo.git")
.privateKey(PRIVATE_KEY)
.hostKey(HOST_KEY)
.hostKeyAlgorithm(HOST_KEY_ALGORITHM)
.proxyHost("localhost")
.build();
setupSessionFactory(sshKey);
factory.configure(hc, session);
}
private void setupSessionFactory(SshUri sshKey) {
Map<String, SshUri> sshKeysByHostname = new HashMap<>();
sshKeysByHostname.put(SshUriPropertyProcessor.getHostname(sshKey.getUri()), sshKey);