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));
    }
  }
}

Comment From: ryanjbaxter

Would you want to submit a PR with this change?

Comment From: kvmw

Would you want to submit a PR with this change?

@ryanjbaxter PR is ready: #2287