use of io.jenkins.blueocean.test.ssh.SSHServer in project blueocean-plugin by jenkinsci.
the class GitReadSaveTest method startSSH.
private void startSSH(@Nullable User u) throws Exception {
if (sshd == null) {
// Set up an SSH server with access to a git repo
User user;
if (u == null) {
user = login();
} else {
user = u;
}
final BasicSSHUserPrivateKey key = UserSSHKeyManager.getOrCreate(user);
final JSch jsch = new JSch();
final KeyPair pair = KeyPair.load(jsch, key.getPrivateKey().getBytes(), null);
File keyFile = new File(System.getProperty("TEST_SSH_SERVER_KEY_FILE", File.createTempFile("hostkey", "ser").getCanonicalPath()));
int port = Integer.parseInt(System.getProperty("TEST_SSH_SERVER_PORT", "0"));
boolean allowLocalUser = Boolean.getBoolean("TEST_SSH_SERVER_ALLOW_LOCAL");
String userPublicKey = Base64.encode(pair.getPublicKeyBlob());
sshd = new SSHServer(repoForSSH.getRoot(), keyFile, port, allowLocalUser, ImmutableMap.of("bob", userPublicKey), true);
// Go, go, go
sshd.start();
}
}