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)));
}
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"));
}
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);
}
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")));
}
}
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));
}
Aggregations