Search in sources :

Example 11 with ConfiguredWithCode

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

the class SSHCredentialsTest method shouldNotExportOrLogCredentials.

@Test
@ConfiguredWithCode("SSHCredentialsTest.yml")
@Issue("SECURITY-1279")
public void shouldNotExportOrLogCredentials() throws Exception {
    StandardUsernamePasswordCredentials creds = getCredentials(StandardUsernamePasswordCredentials.class);
    assertEquals(CREDENTIALS_PASSWORD, creds.getPassword().getPlainText());
    assertNotInLog(logging, CREDENTIALS_PASSWORD);
    BasicSSHUserPrivateKey certKey = getCredentials(BasicSSHUserPrivateKey.class);
    // JENKINS-50181 made getPrivateKey always append a trailing newline.
    assertEquals(PRIVATE_KEY + "\n", certKey.getPrivateKey());
    assertNotInLog(logging, PRIVATE_KEY);
    // Verify that the password does not get exported
    String exportedConfig = j.exportToString(false);
    assertThat("There should be no password in the exported YAML", exportedConfig, not(containsString(CREDENTIALS_PASSWORD)));
    assertThat("There should be no private key in the exported YAML", exportedConfig, not(containsString(PRIVATE_KEY)));
}
Also used : StandardUsernamePasswordCredentials(com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BasicSSHUserPrivateKey(com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 12 with ConfiguredWithCode

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

the class SeedJobTest method configure_seed_job_with_env_vars.

@Test
@ConfiguredWithCode("SeedJobTest_withEnvVars.yml")
public void configure_seed_job_with_env_vars() {
    final Jenkins jenkins = Jenkins.get();
    assertNotNull(jenkins.getItem("seedJobWithEnvVars"));
}
Also used : Jenkins(jenkins.model.Jenkins) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 13 with ConfiguredWithCode

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

the class SeedJobTest method configure_seed_job_with_security_config.

@Test
@ConfiguredWithCode("SeedJobTest_withSecurityConfig.yml")
@Envs(@Env(name = "SEED_JOB_FOLDER_FILE_PATH", value = "."))
public void configure_seed_job_with_security_config() throws Exception {
    final Jenkins jenkins = Jenkins.get();
    final GlobalJobDslSecurityConfiguration dslSecurity = GlobalConfiguration.all().get(GlobalJobDslSecurityConfiguration.class);
    assertNotNull(dslSecurity);
    assertThat("ScriptSecurity", dslSecurity.isUseScriptSecurity(), is(false));
    FreeStyleProject seedJobWithSecurityConfig = (FreeStyleProject) jenkins.getItem("seedJobWithSecurityConfig");
    assertNotNull(seedJobWithSecurityConfig);
    assertTrue(seedJobWithSecurityConfig.isInQueue());
    FreeStyleBuild freeStyleBuild = j.buildAndAssertSuccess(seedJobWithSecurityConfig);
    j.assertLogContains("Processing DSL script testJob2.groovy", freeStyleBuild);
    j.assertLogContains("Added items:", freeStyleBuild);
    j.assertLogContains("GeneratedJob{name='testJob2'}", freeStyleBuild);
}
Also used : Jenkins(jenkins.model.Jenkins) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) GlobalJobDslSecurityConfiguration(javaposse.jobdsl.plugin.GlobalJobDslSecurityConfiguration) Test(org.junit.Test) Envs(io.jenkins.plugins.casc.misc.Envs) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 14 with ConfiguredWithCode

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

the class SystemCredentialsTest method configure_system_credentials.

@Test
@ConfiguredWithCode("SystemCredentialsTest.yml")
public void configure_system_credentials() throws Exception {
    Jenkins jenkins = Jenkins.get();
    List<UsernamePasswordCredentials> ups = CredentialsProvider.lookupCredentials(UsernamePasswordCredentials.class, jenkins, ACL.SYSTEM, Collections.emptyList());
    assertThat(ups, hasSize(1));
    final UsernamePasswordCredentials up = ups.get(0);
    assertThat(up.getPassword().getPlainText(), equalTo("1234"));
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    final ConfigurationContext context = new ConfigurationContext(registry);
    final CNode node = context.lookup(up.getClass()).describe(up, context);
    assertThat(node.asMapping().getScalarValue("password"), not(equals("1234")));
    List<CertificateCredentials> certs = CredentialsProvider.lookupCredentials(CertificateCredentials.class, jenkins, ACL.SYSTEM, Collections.emptyList());
    assertThat(certs, hasSize(0));
    // TODO: add test for uploaded certificate
    // assertThat(certs.get(0).getPassword().getPlainText(), equalTo("ABCD"));
    List<BasicSSHUserPrivateKey> sshPrivateKeys = CredentialsProvider.lookupCredentials(BasicSSHUserPrivateKey.class, jenkins, ACL.SYSTEM, Collections.emptyList());
    assertThat(sshPrivateKeys, hasSize(1));
    final BasicSSHUserPrivateKey ssh_with_passphrase = sshPrivateKeys.get(0);
    assertThat(ssh_with_passphrase.getPassphrase().getPlainText(), equalTo("ABCD"));
    final DirectEntryPrivateKeySource source = (DirectEntryPrivateKeySource) ssh_with_passphrase.getPrivateKeySource();
    assertThat(source.getPrivateKey().getPlainText(), equalTo("s3cr3t"));
    // credentials should not appear in plain text in log
    for (LogRecord logRecord : log.getRecords()) {
        assertThat(logRecord.getMessage(), not(containsString("1234")));
        assertThat(logRecord.getMessage(), not(containsString("ABCD")));
    }
}
Also used : Jenkins(jenkins.model.Jenkins) CNode(io.jenkins.plugins.casc.model.CNode) LogRecord(java.util.logging.LogRecord) CertificateCredentials(com.cloudbees.plugins.credentials.common.CertificateCredentials) DirectEntryPrivateKeySource(com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey.DirectEntryPrivateKeySource) BasicSSHUserPrivateKey(com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey) UsernamePasswordCredentials(com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 15 with ConfiguredWithCode

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

the class ToolDefaultPropertiesExportIgnoreListTest method export_tool_configuration.

@Test
@Issue("JENKINS-57122")
@ConfiguredWithCode("ToolDefaultPropertiesExportIgnoreList.yml")
public void export_tool_configuration() throws Exception {
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);
    CNode yourAttribute = getToolRoot(context);
    String exported = toYamlString(yourAttribute).replaceAll("git\\.exe", "git");
    String expected = toStringFromYamlFile(this, "ToolDefaultPropertiesExportIgnoreListExpected.yml");
    assertThat(exported, is(expected));
}
Also used : CNode(io.jenkins.plugins.casc.model.CNode) Util.toYamlString(io.jenkins.plugins.casc.misc.Util.toYamlString) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Aggregations

ConfiguredWithCode (io.jenkins.plugins.casc.misc.ConfiguredWithCode)52 Test (org.junit.Test)51 Issue (org.jvnet.hudson.test.Issue)18 CNode (io.jenkins.plugins.casc.model.CNode)16 Jenkins (jenkins.model.Jenkins)15 ConfigurationContext (io.jenkins.plugins.casc.ConfigurationContext)8 ConfiguratorRegistry (io.jenkins.plugins.casc.ConfiguratorRegistry)8 Util.toYamlString (io.jenkins.plugins.casc.misc.Util.toYamlString)8 Mapping (io.jenkins.plugins.casc.model.Mapping)7 BasicSSHUserPrivateKey (com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey)5 Configurator (io.jenkins.plugins.casc.Configurator)5 ProxyConfiguration (hudson.ProxyConfiguration)4 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)3 UsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials)3 AdminWhitelistRule (jenkins.security.s2m.AdminWhitelistRule)3 CredentialsRootConfigurator (com.cloudbees.plugins.credentials.casc.CredentialsRootConfigurator)2 Role (com.michelin.cio.hudson.plugins.rolestrategy.Role)2 RoleBasedAuthorizationStrategy (com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy)2 FreeStyleProject (hudson.model.FreeStyleProject)2 User (hudson.model.User)2