Configures SshSessionFactory only if there is at least one git uri with ssh scheme (#2288)

This commit is contained in:
Kaveh Shamsi
2023-06-14 20:08:44 +02:00
committed by GitHub
parent 0febbc0a92
commit e9c8570803
3 changed files with 98 additions and 6 deletions

View File

@@ -24,6 +24,7 @@ import org.eclipse.jgit.api.TransportConfigCallback;
import org.eclipse.jgit.transport.FetchConnection;
import org.eclipse.jgit.transport.PushConnection;
import org.eclipse.jgit.transport.SshConfigStore;
import org.eclipse.jgit.transport.SshSessionFactory;
import org.eclipse.jgit.transport.SshTransport;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.transport.sshd.SshdSessionFactory;
@@ -339,6 +340,71 @@ public class TransportConfigurationIntegrationTests {
}
public static class CallbackWithHttpUrlsOnly {
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { TestConfigServerApplication.class, SshPropertyValidator.class },
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "spring.cloud.config.server.git.uri=https://gitserver.com/team/repo.git" })
@ActiveProfiles({ "test", "git" })
public static class StaticTest {
@Autowired
private MultipleJGitEnvironmentRepository jGitEnvironmentRepository;
@Test
public void sshTransportCallbackIsConfigured() {
TransportConfigCallback transportConfigCallback = this.jGitEnvironmentRepository
.getTransportConfigCallback();
assertThat(transportConfigCallback).isNotNull();
}
@Test
public void noSessionFactoryIsConfiguredForSshTransports() throws Exception {
this.jGitEnvironmentRepository.afterPropertiesSet();
SshTransport sshTransport = DummySshTransport.newInstance();
SshSessionFactory defaultSessionFactory = sshTransport.getSshSessionFactory();
this.jGitEnvironmentRepository.getTransportConfigCallback().configure(sshTransport);
assertThat(sshTransport.getSshSessionFactory()).isSameAs(defaultSessionFactory);
}
}
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { TestConfigServerApplication.class, SshPropertyValidator.class },
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "spring.cloud.config.server.composite[0].type=git",
"spring.cloud.config.server.composite[0].uri=https://gitserver.com/team/repo.git" })
@ActiveProfiles({ "test", "composite" })
public static class ListTest {
@Autowired
private MultipleJGitEnvironmentRepository jGitEnvironmentRepository;
@Test
public void sshTransportCallbackIsConfigured() {
TransportConfigCallback transportConfigCallback = this.jGitEnvironmentRepository
.getTransportConfigCallback();
assertThat(transportConfigCallback).isNotNull();
}
@Test
public void noSessionFactoryIsConfiguredForSshTransports() throws Exception {
this.jGitEnvironmentRepository.afterPropertiesSet();
SshTransport sshTransport = DummySshTransport.newInstance();
SshSessionFactory defaultSessionFactory = sshTransport.getSshSessionFactory();
this.jGitEnvironmentRepository.getTransportConfigCallback().configure(sshTransport);
assertThat(sshTransport.getSshSessionFactory()).isSameAs(defaultSessionFactory);
}
}
}
private static class DummySshTransport extends SshTransport {
DummySshTransport(String uri) throws URISyntaxException {