Search in sources :

Example 1 with CredentialsPage

use of org.jenkinsci.test.acceptance.plugins.credentials.CredentialsPage 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 CredentialsPage

use of org.jenkinsci.test.acceptance.plugins.credentials.CredentialsPage 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 CredentialsPage

use of org.jenkinsci.test.acceptance.plugins.credentials.CredentialsPage in project acceptance-test-harness by jenkinsci.

the class CredentialsBindingTest method testTextBinding.

@Test
public void testTextBinding() {
    CredentialsPage mc = new CredentialsPage(jenkins, ManagedCredentials.DEFAULT_DOMAIN);
    mc.open();
    StringCredentials cred = mc.add(StringCredentials.class);
    cred.scope.select("GLOBAL");
    cred.secret.set(SECRET_TEXT);
    mc.create();
    FreeStyleJob job = jenkins.jobs.create();
    job.configure();
    job.check("Use secret text(s) or file(s)");
    ManagedCredentialsBinding mcb = new ManagedCredentialsBinding(job);
    SecretStringCredentialsBinding cb = mcb.addCredentialBinding(SecretStringCredentialsBinding.class);
    cb.variable.set("BINDED_SECRET");
    ShellBuildStep shell = job.addBuildStep(ShellBuildStep.class);
    shell.command("if [ \"$BINDED_SECRET\" = \"" + SECRET_TEXT + "\" ] \n then \n echo \"" + SECRET_OUTPUT + "\" \n fi");
    job.save();
    Build b = job.scheduleBuild();
    b.shouldSucceed();
    assertThat(b.getConsole(), containsString(SECRET_OUTPUT));
}
Also used : SecretStringCredentialsBinding(org.jenkinsci.test.acceptance.plugins.credentialsbinding.SecretStringCredentialsBinding) ManagedCredentialsBinding(org.jenkinsci.test.acceptance.plugins.credentialsbinding.ManagedCredentialsBinding) CredentialsPage(org.jenkinsci.test.acceptance.plugins.credentials.CredentialsPage) Build(org.jenkinsci.test.acceptance.po.Build) StringCredentials(org.jenkinsci.test.acceptance.plugins.credentials.StringCredentials) ShellBuildStep(org.jenkinsci.test.acceptance.po.ShellBuildStep) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test)

Example 4 with CredentialsPage

use of org.jenkinsci.test.acceptance.plugins.credentials.CredentialsPage in project acceptance-test-harness by jenkinsci.

the class TSRCreateSlaveTest method newSlaveWithExistingCredential.

@Test
@WithPlugins("credentials@2.0.7")
public void newSlaveWithExistingCredential() throws Exception {
    String username = "xyz";
    String description = "SSH Key setup";
    String privateKey = "1212121122121212";
    CredentialsPage c = new CredentialsPage(jenkins, "_");
    c.open();
    SshPrivateKeyCredential sc = c.add(SshPrivateKeyCredential.class);
    sc.username.set(username);
    sc.description.set(description);
    sc.selectEnterDirectly().privateKey.set(privateKey);
    c.create();
    // now verify
    c.open();
    ManagedCredentials mc = new ManagedCredentials(jenkins);
    String href = mc.credentialById("ssh_creds");
    c.setConfigUrl(href);
    verifyValueForCredential(c, sc.username, username);
    verifyValueForCredential(c, sc.selectEnterDirectly().privateKey, privateKey);
    // 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);
    l.host.set("127.0.0.1");
    l.credentialsId.select(String.format("%s (%s)", username, description));
}
Also used : SshPrivateKeyCredential(org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential) SshSlaveLauncher(org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher) CredentialsPage(org.jenkinsci.test.acceptance.plugins.credentials.CredentialsPage) Matchers.containsString(org.hamcrest.Matchers.containsString) DumbSlave(org.jenkinsci.test.acceptance.po.DumbSlave) ManagedCredentials(org.jenkinsci.test.acceptance.plugins.credentials.ManagedCredentials) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 5 with CredentialsPage

use of org.jenkinsci.test.acceptance.plugins.credentials.CredentialsPage in project acceptance-test-harness by jenkinsci.

the class SshSlavesPluginTest method newSlaveWithExistingCredential.

@Test
public void newSlaveWithExistingCredential() throws Exception {
    String username = "xyz";
    String description = "ssh_creds";
    String privateKey = "1212121122121212";
    CredentialsPage c = new CredentialsPage(jenkins, "_");
    c.open();
    SshPrivateKeyCredential sc = c.add(SshPrivateKeyCredential.class);
    sc.username.set(username);
    sc.description.set(description);
    sc.selectEnterDirectly().privateKey.set(privateKey);
    c.create();
    // now verify
    ManagedCredentials mc = new ManagedCredentials(jenkins);
    String href = mc.credentialById("ssh_creds");
    c.setConfigUrl(href);
    verifyValueForCredential(c, sc.username, username);
    // See https://jenkins.io/doc/developer/security/secrets/#secrets-and-configuration-forms, available from Jenkins 2.171
    if (jenkins.getVersion().isNewerThan(new VersionNumber("2.170"))) {
        verifyUnexpectedValueForCredential("Credentials in plain text should not be accessible from Web UI", c, sc.selectEnterDirectly().privateKey, privateKey);
    }
    // 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);
    l.host.set("127.0.0.1");
    l.credentialsId.select(String.format("%s (%s)", username, description));
}
Also used : SshPrivateKeyCredential(org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential) SshSlaveLauncher(org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher) CredentialsPage(org.jenkinsci.test.acceptance.plugins.credentials.CredentialsPage) Matchers.containsString(org.hamcrest.Matchers.containsString) DumbSlave(org.jenkinsci.test.acceptance.po.DumbSlave) ManagedCredentials(org.jenkinsci.test.acceptance.plugins.credentials.ManagedCredentials) VersionNumber(hudson.util.VersionNumber) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) DockerTest(org.jenkinsci.test.acceptance.junit.DockerTest)

Aggregations

CredentialsPage (org.jenkinsci.test.acceptance.plugins.credentials.CredentialsPage)7 SshPrivateKeyCredential (org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential)4 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)3 ManagedCredentials (org.jenkinsci.test.acceptance.plugins.credentials.ManagedCredentials)3 DumbSlave (org.jenkinsci.test.acceptance.po.DumbSlave)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 UserPwdCredential (org.jenkinsci.test.acceptance.plugins.credentials.UserPwdCredential)2 SshSlaveLauncher (org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher)2 Before (org.junit.Before)2 VersionNumber (hudson.util.VersionNumber)1 URISyntaxException (java.net.URISyntaxException)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1 DockerTest (org.jenkinsci.test.acceptance.junit.DockerTest)1 WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)1 StringCredentials (org.jenkinsci.test.acceptance.plugins.credentials.StringCredentials)1 ManagedCredentialsBinding (org.jenkinsci.test.acceptance.plugins.credentialsbinding.ManagedCredentialsBinding)1 SecretStringCredentialsBinding (org.jenkinsci.test.acceptance.plugins.credentialsbinding.SecretStringCredentialsBinding)1