fix: configure ssh connect timeout value (#2394)
Modify `PropertyBasedSshSessionFactory` and `FileBasedSshSessionFactory` to configure `SshConstants.CONNECT_TIMEOUT` based on the supplied timeout property
This commit is contained in:
@@ -52,6 +52,8 @@ public class FileBasedSshSessionFactory extends SshdSessionFactory {
|
||||
hostEntry.setValue(SshConstants.STRICT_HOST_KEY_CHECKING,
|
||||
sshProperties.isStrictHostKeyChecking() ? SshConstants.YES : SshConstants.NO);
|
||||
|
||||
hostEntry.setValue(SshConstants.CONNECT_TIMEOUT, String.valueOf(sshProperties.getTimeout()));
|
||||
|
||||
return hostEntry;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -97,6 +97,8 @@ public class PropertyBasedSshSessionFactory extends SshdSessionFactory {
|
||||
private OpenSshConfigFile.HostEntry updateIfNeeded(OpenSshConfigFile.HostEntry hostEntry, String hostName) {
|
||||
JGitEnvironmentProperties sshProperties = sshKeysByHostname.get(hostName);
|
||||
|
||||
hostEntry.setValue(SshConstants.CONNECT_TIMEOUT, String.valueOf(sshProperties.getTimeout()));
|
||||
|
||||
if (sshProperties.getHostKey() == null || !sshProperties.isStrictHostKeyChecking()) {
|
||||
hostEntry.setValue(SshConstants.STRICT_HOST_KEY_CHECKING, SshConstants.NO);
|
||||
}
|
||||
|
||||
@@ -82,6 +82,17 @@ public class FileBasedSshSessionFactoryTest {
|
||||
assertThat(configStore).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectTimeoutIsUsed() {
|
||||
JGitEnvironmentProperties sshKey = new JGitEnvironmentProperties();
|
||||
sshKey.setUri("ssh://gitlab.example.local:3322/somerepo.git");
|
||||
setupSessionFactory(sshKey);
|
||||
|
||||
SshConfigStore.HostConfig sshConfig = getSshHostConfig("gitlab.example.local");
|
||||
|
||||
assertThat(sshConfig.getValue("ConnectTimeout")).isEqualTo("5");
|
||||
}
|
||||
|
||||
private SshConfigStore.HostConfig getSshHostConfig(String hostName) {
|
||||
return factory.createSshConfigStore(new File("dummy"), new File("dummy"), "localUserName").lookup(hostName, 22,
|
||||
"userName");
|
||||
|
||||
@@ -312,6 +312,17 @@ public class PropertyBasedSshSessionFactoryTest {
|
||||
assertThat(proxyData.getProxy().address().toString()).containsPattern("host\\.domain.*:8080");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectTimeoutIsUsed() {
|
||||
JGitEnvironmentProperties sshKey = new JGitEnvironmentProperties();
|
||||
sshKey.setUri("ssh://gitlab.example.local:3322/somerepo.git");
|
||||
setupSessionFactory(sshKey);
|
||||
|
||||
SshConfigStore.HostConfig sshConfig = getSshHostConfig("gitlab.example.local");
|
||||
|
||||
assertThat(sshConfig.getValue("ConnectTimeout")).isEqualTo("5");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sshConfigFileIsNotUsed() {
|
||||
setupSessionFactory(new JGitEnvironmentProperties());
|
||||
|
||||
Reference in New Issue
Block a user