use of com.cloudbees.plugins.credentials.common.CertificateCredentials 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 com.cloudbees.plugins.credentials.common.CertificateCredentials 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.getInstance();
List<UsernamePasswordCredentials> ups = CredentialsProvider.lookupCredentials(UsernamePasswordCredentials.class, jenkins, ACL.SYSTEM, Collections.emptyList());
assertThat(ups, hasSize(1));
assertThat(ups.get(0).getPassword().getPlainText(), equalTo("1234"));
List<CertificateCredentials> certs = CredentialsProvider.lookupCredentials(CertificateCredentials.class, jenkins, ACL.SYSTEM, Collections.emptyList());
assertThat(certs, hasSize(1));
assertThat(certs.get(0).getPassword().getPlainText(), equalTo("ABCD"));
List<BasicSSHUserPrivateKey> sshPrivateKeys = CredentialsProvider.lookupCredentials(BasicSSHUserPrivateKey.class, jenkins, ACL.SYSTEM, Collections.emptyList());
assertThat(sshPrivateKeys, hasSize(2));
assertThat(sshPrivateKeys.get(0).getPassphrase().getPlainText(), equalTo("ABCD"));
}
Aggregations