Search in sources :

Example 1 with SshPrivateKeyCredential

use of org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential in project acceptance-test-harness by jenkinsci.

the class ForemanNodeSharingPluginTest method setUp.

/**
 * Setup instance before each test.
 * @throws Exception if occurs.
 */
@Before
public void setUp() throws Exception {
    jenkins.runScript("import hudson.slaves.NodeProvisioner; NodeProvisioner.NodeProvisionerInvoker." + "INITIALDELAY = NodeProvisioner.NodeProvisionerInvoker.RECURRENCEPERIOD = 60;");
    foreman = dockerForeman.get();
    sshslave1 = docker1.get();
    CredentialsPage c = new CredentialsPage(jenkins, ManagedCredentials.DEFAULT_DOMAIN);
    c.open();
    final SshPrivateKeyCredential sc = c.add(SshPrivateKeyCredential.class);
    sc.username.set("test");
    sc.selectEnterDirectly().privateKey.set(sshslave1.getPrivateKeyString());
    sc.scope.select("GLOBAL");
    c.create();
    // CS IGNORE MagicNumber FOR NEXT 2 LINES. REASON: Mock object.
    elasticSleep(10000);
    if (populateForeman(foreman.getUrl().toString() + "/api/v2", sshslave1.getIpAddress(), labelExpression1) != 0) {
        throw new Exception("failed to populate foreman");
    }
    if (populateForeman(foreman.getUrl().toString() + "/api/v2", "dummy", labelExpression2) != 0) {
        throw new Exception("failed to populate foreman");
    }
    jenkins.configure();
    cloud = addCloud(jenkins.getConfigPage());
    // CS IGNORE MagicNumber FOR NEXT 2 LINES. REASON: Mock object.
    elasticSleep(10000);
}
Also used : SshPrivateKeyCredential(org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential) CredentialsPage(org.jenkinsci.test.acceptance.plugins.credentials.CredentialsPage) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Before(org.junit.Before)

Example 2 with SshPrivateKeyCredential

use of org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential in project acceptance-test-harness by jenkinsci.

the class SshSlaveController method install.

@Override
public Future<Slave> install(Jenkins j) {
    ManagedCredentials credential = new ManagedCredentials(j);
    try {
        credential.open();
        if (credential.checkIfCredentialsExist(fingerprint) == null) {
            CredentialsPage cp = new CredentialsPage(j, ManagedCredentials.DEFAULT_DOMAIN);
            SshPrivateKeyCredential sc = cp.add(SshPrivateKeyCredential.class);
            sc.username.set(machine.getUser());
            sc.description.set(fingerprint);
            sc.selectEnterDirectly().privateKey.set(keyPair.readPrivateKey());
            cp.create();
        }
    } catch (IOException e) {
        throw new AssertionError(e);
    }
    final Slave s = create(machine.getPublicIpAddress(), j);
    // Slave is configured, now wait till its online
    return new Future<Slave>() {

        @Override
        public boolean cancel(boolean mayInterruptIfRunning) {
            return false;
        }

        @Override
        public boolean isCancelled() {
            return slaveWaitComplete.get();
        }

        @Override
        public boolean isDone() {
            return slaveWaitComplete.get() || s.isOnline();
        }

        @Override
        public Slave get() throws InterruptedException, ExecutionException {
            waitForOnLineSlave(s, slaveReadyTimeOutInSec);
            return s;
        }

        @Override
        public Slave get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
            if (unit != TimeUnit.SECONDS) {
                timeout = unit.toSeconds(timeout);
            }
            waitForOnLineSlave(s, (int) timeout);
            return s;
        }
    };
}
Also used : SshPrivateKeyCredential(org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential) DumbSlave(org.jenkinsci.test.acceptance.po.DumbSlave) Slave(org.jenkinsci.test.acceptance.po.Slave) CredentialsPage(org.jenkinsci.test.acceptance.plugins.credentials.CredentialsPage) Future(java.util.concurrent.Future) TimeUnit(java.util.concurrent.TimeUnit) IOException(java.io.IOException) ManagedCredentials(org.jenkinsci.test.acceptance.plugins.credentials.ManagedCredentials)

Example 3 with SshPrivateKeyCredential

use of org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential in project acceptance-test-harness by jenkinsci.

the class TSRCreateSlaveTest method newSlave.

@Test
@Since("1.560")
public void newSlave() {
    // this test requires a newer version of credentials plugin that has inline "Add" button
    // I'm not sure exactly which version it is, but 1.532 LTS doesn't have it, and 1.555 has it,
    // so it's somewhere in between
    // TODO: this should be converted to "@WithPlugin("ssh-credentials") with specific version tag,
    // not the core version
    // Just to make sure the dumb slave is set up properly, we should seed it
    // with a FS root and executors
    final DumbSlave s = jenkins.slaves.create(DumbSlave.class);
    {
        SshSlaveLauncher l = s.setLauncher(SshSlaveLauncher.class);
        String username = "user1";
        String privateKey = "1212122112";
        String description = "Ssh key";
        l.host.set("127.0.0.1");
        // make sure this exists
        l.credentialsId.resolve();
        try {
            l.credentialsId.select(String.format("%s (%s)", username, description));
            fail();
        } catch (NoSuchElementException e) {
        // ignore
        }
        SshCredentialDialog f = l.addCredential();
        {
            SshPrivateKeyCredential sc = f.select(SshPrivateKeyCredential.class);
            sc.description.set(description);
            sc.username.set(username);
            sc.selectEnterDirectly().privateKey.set(privateKey);
        }
        f.add();
        l.credentialsId.select(String.format("%s (%s)", username, description));
    }
    s.save();
}
Also used : SshSlaveLauncher(org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher) SshPrivateKeyCredential(org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential) SshCredentialDialog(org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshCredentialDialog) Matchers.containsString(org.hamcrest.Matchers.containsString) DumbSlave(org.jenkinsci.test.acceptance.po.DumbSlave) NoSuchElementException(org.openqa.selenium.NoSuchElementException) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) Since(org.jenkinsci.test.acceptance.junit.Since)

Example 4 with SshPrivateKeyCredential

use of org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential in project acceptance-test-harness by jenkinsci.

the class SshSlaveLauncher method keyCredentials.

/**
 * Add username/key based credentials to the configuration
 *
 * @param username to use
 * @param key for the private key to use
 * @return the SshSlaveLauncher to be configured
 */
public SshSlaveLauncher keyCredentials(String username, String key, @CheckForNull String passphrase) {
    final SshCredentialDialog dia = this.addCredential();
    final SshPrivateKeyCredential cred = dia.select(SshPrivateKeyCredential.class);
    cred.username.set(username);
    if (passphrase != null) {
        cred.passphrase.set(passphrase);
    }
    cred.enterDirectly(key);
    cred.add();
    waitForCredentialVisible(username);
    return this;
}
Also used : SshPrivateKeyCredential(org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential) SshCredentialDialog(org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshCredentialDialog)

Example 5 with SshPrivateKeyCredential

use of org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential in project acceptance-test-harness by jenkinsci.

the class CredentialsTest method createSshKeys.

@Test
@WithPlugins("ssh-credentials")
public void createSshKeys() throws Exception {
    CredentialsPage cp = new CredentialsPage(jenkins, ManagedCredentials.DEFAULT_DOMAIN);
    cp.open();
    SshPrivateKeyCredential sc = cp.add(SshPrivateKeyCredential.class);
    sc.username.set(CRED_USER);
    sc.selectEnterDirectly().privateKey.set(CRED_PWD);
    sc.description.set("ssh_creds");
    cp.create();
    // now verify
    final ManagedCredentials c = new ManagedCredentials(jenkins);
    String href = c.credentialById("ssh_creds");
    cp.setConfigUrl(href);
    verifyValueForCredential(cp, sc.username, CRED_USER);
    verifyValueForCredentialKey(sc, CRED_PWD, false);
}
Also used : SshPrivateKeyCredential(org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential) Matchers.containsString(org.hamcrest.Matchers.containsString) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Aggregations

SshPrivateKeyCredential (org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential)8 Matchers.containsString (org.hamcrest.Matchers.containsString)5 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)5 DumbSlave (org.jenkinsci.test.acceptance.po.DumbSlave)5 Test (org.junit.Test)5 CredentialsPage (org.jenkinsci.test.acceptance.plugins.credentials.CredentialsPage)4 SshSlaveLauncher (org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher)4 ManagedCredentials (org.jenkinsci.test.acceptance.plugins.credentials.ManagedCredentials)3 SshCredentialDialog (org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshCredentialDialog)3 IOException (java.io.IOException)2 DockerTest (org.jenkinsci.test.acceptance.junit.DockerTest)2 Since (org.jenkinsci.test.acceptance.junit.Since)2 WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)2 NoSuchElementException (org.openqa.selenium.NoSuchElementException)2 VersionNumber (hudson.util.VersionNumber)1 URISyntaxException (java.net.URISyntaxException)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1 Slave (org.jenkinsci.test.acceptance.po.Slave)1 Before (org.junit.Before)1