Both FileBasedSshSessionFactory and PropertyBasedSshSessionFactory are expecting at least one ssh URL in the git configuration. So a HTTP/HTTPS URL for git.uri can cause java.lang.AssertionError, if -enableassertions flag is true.
The issue in often not visible because above flag is false by default. But in development or test environment, which the flag might be enabled, one can see the issue.
Sample
Running any sample config-server application with above flag enabled can show the issue.
java -ea -jar ./build/libs/config-server-sample-0.0.1-SNAPSHOT.jar
Possible Solution
FileBasedSshTransportConfigCallback and PropertyBasedSshTransportConfigCallback should configure the SshTransport only if there is at least one SSH URL in the configuration.
current code:
@Override
public void configure(Transport transport) {
if (transport instanceof SshTransport) {
((SshTransport) transport).setSshSessionFactory(new FileBasedSshSessionFactory(
new SshUriPropertyProcessor(this.sshUriProperties).getSshKeysByHostname()));
}
}
proposed change:
@Override
public void configure(Transport transport) {
if (transport instanceof SshTransport) {
var sshKeysByHostname = new SshUriPropertyProcessor(this.sshUriProperties).getSshKeysByHostname();
if (!sshKeysByHostname.isEmpty()) { // Only if the map is not empty
((SshTransport) transport).setSshSessionFactory(new FileBasedSshSessionFactory(sshKeysByHostname));
}
}
}
Both FileBasedSshSessionFactory and PropertyBasedSshSessionFactory are expecting at least one
sshURL in the git configuration. So a HTTP/HTTPS URL forgit.urican causejava.lang.AssertionError, if-enableassertionsflag is true.The issue in often not visible because above flag is
falseby default. But in development or test environment, which the flag might be enabled, one can see the issue.Sample
Running any sample config-server application with above flag enabled can show the issue.
Possible Solution
FileBasedSshTransportConfigCallbackandPropertyBasedSshTransportConfigCallbackshould configure theSshTransportonly if there is at least one SSH URL in the configuration.current code:
proposed change: