Search in sources :

Example 1 with ConfiguredWithReadme

use of io.jenkins.plugins.casc.misc.ConfiguredWithReadme in project configuration-as-code-plugin by jenkinsci.

the class ActiveDirectoryTest method configure_active_directory.

@Test
@ConfiguredWithReadme("active-directory/README.md")
public void configure_active_directory() {
    final Jenkins jenkins = Jenkins.get();
    final ActiveDirectorySecurityRealm realm = (ActiveDirectorySecurityRealm) jenkins.getSecurityRealm();
    assertEquals(1, realm.domains.size());
    final ActiveDirectoryDomain domain = realm.domains.get(0);
    assertEquals("acme", domain.name);
    assertEquals("admin", domain.bindName);
    assertEquals("ADMIN123", domain.bindPassword.getPlainText());
    assertEquals("ad1.acme.com:123,ad2.acme.com:456", domain.servers);
    assertEquals("jenkins", realm.getJenkinsInternalUser());
    assertTrue(realm.removeIrrelevantGroups);
    assertTrue(realm.startTls);
    assertNotNull(realm.getCache());
    assertEquals(500, realm.getCache().getSize());
    assertEquals(600, realm.getCache().getTtl());
}
Also used : Jenkins(jenkins.model.Jenkins) ActiveDirectorySecurityRealm(hudson.plugins.active_directory.ActiveDirectorySecurityRealm) ActiveDirectoryDomain(hudson.plugins.active_directory.ActiveDirectoryDomain) Test(org.junit.Test) ConfiguredWithReadme(io.jenkins.plugins.casc.misc.ConfiguredWithReadme)

Example 2 with ConfiguredWithReadme

use of io.jenkins.plugins.casc.misc.ConfiguredWithReadme in project configuration-as-code-plugin by jenkinsci.

the class BuildAgentsTest method configure_build_agents.

@Test
@ConfiguredWithReadme(value = "build_agents/README.md")
public void configure_build_agents() {
    assertThat(j.getInstance().getComputers().length, is(3));
    Slave slave = (Slave) j.getInstance().getNode("utility-node");
    assertThat(slave.getRemoteFS(), is("/home/user1"));
    JNLPLauncher jnlpLauncher = ((JNLPLauncher) slave.getLauncher());
    assertThat(jnlpLauncher.getWorkDirSettings().getWorkDirPath(), is("/tmp"));
    assertThat(jnlpLauncher.getWorkDirSettings().getInternalDir(), is("remoting"));
    assertTrue(jnlpLauncher.getWorkDirSettings().isDisabled());
    assertFalse(jnlpLauncher.getWorkDirSettings().isFailIfWorkDirIsMissing());
    assertThat(j.getInstance().getNode("utility-node-2").getNumExecutors(), is(4));
    assertThat(j.getInstance().getNode("utility-node-2").getMode(), is(Mode.NORMAL));
    slave = (Slave) j.getInstance().getNode("utility-node-2");
    assertThat(slave.getRemoteFS(), is("/home/user2"));
    SSHLauncher launcher = ((SSHLauncher) slave.getLauncher());
    assertThat(launcher.getHost(), is("192.168.1.1"));
    assertThat(launcher.getPort(), is(22));
    assertThat(launcher.getCredentialsId(), is("test"));
    assertThat(launcher.getMaxNumRetries(), is(3));
    assertThat(launcher.getRetryWaitTime(), is(30));
}
Also used : Slave(hudson.model.Slave) SSHLauncher(hudson.plugins.sshslaves.SSHLauncher) JNLPLauncher(hudson.slaves.JNLPLauncher) Test(org.junit.Test) ConfiguredWithReadme(io.jenkins.plugins.casc.misc.ConfiguredWithReadme)

Example 3 with ConfiguredWithReadme

use of io.jenkins.plugins.casc.misc.ConfiguredWithReadme in project configuration-as-code-plugin by jenkinsci.

the class CredentialsReadmeTest method testGlobalScopedCredentials.

@Test
@ConfiguredWithReadme("credentials/README.md#1")
@Envs({ @Env(name = "SSH_KEY_PASSWORD", value = PASSPHRASE), @Env(name = "SSH_PRIVATE_KEY", value = PRIVATE_KEY), @Env(name = "SSH_PRIVATE_FILE_PATH", value = "private-key.pem"), @Env(name = "SOME_USER_PASSWORD", value = PASSWORD), @Env(name = "SECRET_TEXT", value = TEXT), @Env(name = "AWS_ACCESS_KEY", value = ACCESS_KEY), @Env(name = "AWS_SECRET_ACCESS_KEY", value = SECRET_ACCESS_KEY), @Env(name = "SECRET_FILE_PATH", value = MYSECRETFILE_TXT), @Env(name = "SECRET_PASSWORD_CERT", value = PASSWORD), @Env(name = "SECRET_CERT_FILE_PATH", value = TEST_CERT) })
public void testGlobalScopedCredentials() throws Exception {
    List<Credentials> creds = CredentialsProvider.lookupCredentials(Credentials.class, Jenkins.get(), null, Collections.emptyList());
    assertThat(creds, hasSize(8));
    for (Credentials credentials : creds) {
        if (credentials instanceof BasicSSHUserPrivateKey) {
            BasicSSHUserPrivateKey key = (BasicSSHUserPrivateKey) credentials;
            assertThat(key.getPassphrase(), hasPlainText(PASSPHRASE));
            assertThat(key.getPrivateKey(), equalTo(PRIVATE_KEY));
            assertThat(key.getId(), anyOf(is("ssh_with_passphrase_provided"), is("ssh_with_passphrase_provided_via_file")));
            assertThat(key.getUsername(), is("ssh_root"));
            assertThat(key.getScope(), is(CredentialsScope.SYSTEM));
        } else if (credentials instanceof UsernamePasswordCredentials) {
            UsernamePasswordCredentials user = (UsernamePasswordCredentials) credentials;
            assertThat(user.getUsername(), is("some-user"));
            assertThat(user.getPassword(), hasPlainText(PASSWORD));
            assertThat(user.getScope(), is(CredentialsScope.GLOBAL));
        } else if (credentials instanceof StringCredentials) {
            StringCredentials string = (StringCredentials) credentials;
            assertThat(string.getId(), is("secret-text"));
            assertThat(string.getSecret(), hasPlainText(TEXT));
            assertThat(string.getScope(), is(CredentialsScope.GLOBAL));
        } else if (credentials instanceof AWSCredentialsImpl) {
            AWSCredentialsImpl aws = (AWSCredentialsImpl) credentials;
            assertThat(aws.getId(), is("AWS"));
            assertThat(aws.getAccessKey(), equalTo(ACCESS_KEY));
            assertThat(aws.getSecretKey(), hasPlainText(SECRET_ACCESS_KEY));
            assertThat(aws.getScope(), is(CredentialsScope.GLOBAL));
        } else if (credentials instanceof FileCredentials) {
            FileCredentials file = (FileCredentials) credentials;
            assertThat(file.getId(), anyOf(is("secret-file"), is("secret-file_via_binary_file")));
            assertThat(file.getFileName(), is(MYSECRETFILE_TXT));
            String fileContent = IOUtils.toString(file.getContent(), StandardCharsets.UTF_8);
            assertThat(fileContent, containsString("SUPER SECRET"));
            assertThat(file.getScope(), is(CredentialsScope.GLOBAL));
        } else if (credentials instanceof CertificateCredentialsImpl) {
            CertificateCredentialsImpl cert = (CertificateCredentialsImpl) credentials;
            assertThat(cert.getId(), is("secret-certificate"));
            assertThat(cert.getPassword(), hasPlainText(PASSWORD));
            byte[] fileContent = Files.readAllBytes(Paths.get(getClass().getResource(TEST_CERT).toURI()));
            SecretBytes secretBytes = SecretBytes.fromString(Base64.getEncoder().encodeToString(fileContent));
            UploadedKeyStoreSource keyStoreSource = (UploadedKeyStoreSource) cert.getKeyStoreSource();
            assertThat(keyStoreSource.getUploadedKeystore().getPlainData(), is(secretBytes.getPlainData()));
            assertThat(cert.getKeyStore().containsAlias("1"), is(true));
            assertThat(cert.getKeyStore().getCertificate("1").getType(), is("X.509"));
            assertThat(CredentialsNameProvider.name(cert), is("EMAILADDRESS=me@myhost.mydomain, CN=pkcs12, O=Fort-Funston, L=SanFrancisco, ST=CA, C=US (my secret cert)"));
            assertThat(cert.getScope(), is(CredentialsScope.GLOBAL));
        }
    }
}
Also used : AWSCredentialsImpl(com.cloudbees.jenkins.plugins.awscredentials.AWSCredentialsImpl) UploadedKeyStoreSource(com.cloudbees.plugins.credentials.impl.CertificateCredentialsImpl.UploadedKeyStoreSource) SecretBytes(com.cloudbees.plugins.credentials.SecretBytes) FileCredentials(org.jenkinsci.plugins.plaincredentials.FileCredentials) CertificateCredentialsImpl(com.cloudbees.plugins.credentials.impl.CertificateCredentialsImpl) StringCredentials(org.jenkinsci.plugins.plaincredentials.StringCredentials) Matchers.containsString(org.hamcrest.Matchers.containsString) Credentials(com.cloudbees.plugins.credentials.Credentials) StringCredentials(org.jenkinsci.plugins.plaincredentials.StringCredentials) StandardUsernamePasswordCredentials(com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials) UsernamePasswordCredentials(com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials) FileCredentials(org.jenkinsci.plugins.plaincredentials.FileCredentials) BasicSSHUserPrivateKey(com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey) StandardUsernamePasswordCredentials(com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials) UsernamePasswordCredentials(com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials) Test(org.junit.Test) Envs(io.jenkins.plugins.casc.misc.Envs) ConfiguredWithReadme(io.jenkins.plugins.casc.misc.ConfiguredWithReadme)

Example 4 with ConfiguredWithReadme

use of io.jenkins.plugins.casc.misc.ConfiguredWithReadme in project configuration-as-code-plugin by jenkinsci.

the class Crowd2Test method configure_artifact_manager.

@Test
@ConfiguredWithReadme("crowd2/README.md")
public void configure_artifact_manager() {
    SecurityRealm realm = Jenkins.get().getSecurityRealm();
    assertThat(realm, instanceOf(CrowdSecurityRealm.class));
    CrowdSecurityRealm securityRealm = (CrowdSecurityRealm) realm;
    assertThat(securityRealm.applicationName, is("jenkins"));
    assertThat(securityRealm.group, is("jenkins-users"));
    assertThat(securityRealm.url, is("http://crowd.company.io"));
    assertThat(securityRealm.password, hasPlainText(PASSWORD_123));
}
Also used : CrowdSecurityRealm(de.theit.jenkins.crowd.CrowdSecurityRealm) SecurityRealm(hudson.security.SecurityRealm) CrowdSecurityRealm(de.theit.jenkins.crowd.CrowdSecurityRealm) Test(org.junit.Test) ConfiguredWithReadme(io.jenkins.plugins.casc.misc.ConfiguredWithReadme)

Example 5 with ConfiguredWithReadme

use of io.jenkins.plugins.casc.misc.ConfiguredWithReadme in project configuration-as-code-plugin by jenkinsci.

the class DockerCloudTest method update_docker_cloud.

@Test
@ConfiguredWithReadme("docker/README.md")
public void update_docker_cloud() throws Exception {
    DockerCloud docker = DockerCloud.getCloudByName("docker");
    assertNotNull(docker);
    assertNotNull(docker.getDockerApi());
    assertNotNull(docker.getDockerApi().getDockerHost());
    assertEquals("unix:///var/run/docker.sock", docker.getDockerApi().getDockerHost().getUri());
    DockerTemplate template = docker.getTemplate(Label.get("docker-agent"));
    checkTemplate(template, "docker-agent", "jenkins", "/home/jenkins/agent", "10", new String[] { "hello:/hello", "world:/world" }, "hello=world\nfoo=bar");
    ConfigurationAsCode.get().configure(getClass().getResource("DockerCloudTest2.yml").toExternalForm());
    docker = DockerCloud.getCloudByName("docker");
    assertNotNull(docker);
    assertNotNull(docker.getDockerApi());
    assertNotNull(docker.getDockerApi().getDockerHost());
    assertEquals("unix:///var/run/docker.sock", docker.getDockerApi().getDockerHost().getUri());
    template = docker.getTemplate(Label.get("docker-agent"));
    checkTemplate(template, "docker-agent", "jenkins", "/home/jenkins/agent", "10", new String[] { "hello:/hello", "world:/world" }, "hello=world\nfoo=bar");
    template = docker.getTemplate(Label.get("generic"));
    checkTemplate(template, "generic", "jenkins", "/home/jenkins/agent2", "5", new String[] { "hello:/hello", "world:/world" }, "hello=world\nfoo=bar");
}
Also used : DockerTemplate(com.nirima.jenkins.plugins.docker.DockerTemplate) DockerCloud(com.nirima.jenkins.plugins.docker.DockerCloud) Test(org.junit.Test) ConfiguredWithReadme(io.jenkins.plugins.casc.misc.ConfiguredWithReadme)

Aggregations

ConfiguredWithReadme (io.jenkins.plugins.casc.misc.ConfiguredWithReadme)46 Test (org.junit.Test)46 Jenkins (jenkins.model.Jenkins)12 User (hudson.model.User)3 LDAPSecurityRealm (hudson.security.LDAPSecurityRealm)3 SecurityRealm (hudson.security.SecurityRealm)3 InstallSourceProperty (hudson.tools.InstallSourceProperty)3 BasicSSHUserPrivateKey (com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey)2 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)2 DockerCloud (com.nirima.jenkins.plugins.docker.DockerCloud)2 DockerTemplate (com.nirima.jenkins.plugins.docker.DockerTemplate)2 HudsonPrivateSecurityRealm (hudson.security.HudsonPrivateSecurityRealm)2 Util.toYamlString (io.jenkins.plugins.casc.misc.Util.toYamlString)2 CNode (io.jenkins.plugins.casc.model.CNode)2 AWSCredentialsImpl (com.cloudbees.jenkins.plugins.awscredentials.AWSCredentialsImpl)1 DirectEntryPrivateKeySource (com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey.DirectEntryPrivateKeySource)1 Credentials (com.cloudbees.plugins.credentials.Credentials)1 SecretBytes (com.cloudbees.plugins.credentials.SecretBytes)1 SystemCredentialsProvider (com.cloudbees.plugins.credentials.SystemCredentialsProvider)1 UsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials)1