Search in sources :

Example 1 with SSHServer

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();
    }
}
Also used : KeyPair(com.jcraft.jsch.KeyPair) SSHServer(io.jenkins.blueocean.test.ssh.SSHServer) User(hudson.model.User) JSch(com.jcraft.jsch.JSch) File(java.io.File) BasicSSHUserPrivateKey(com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey)

Aggregations

BasicSSHUserPrivateKey (com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey)1 JSch (com.jcraft.jsch.JSch)1 KeyPair (com.jcraft.jsch.KeyPair)1 User (hudson.model.User)1 SSHServer (io.jenkins.blueocean.test.ssh.SSHServer)1 File (java.io.File)1