use of com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey.DirectEntryPrivateKeySource in project configuration-as-code-plugin by jenkinsci.
the class TopReadmeTest method configure_demo_first_code_block.
@Test
@ConfiguredWithReadme("README.md#0")
public void configure_demo_first_code_block() {
final Jenkins jenkins = Jenkins.get();
assertEquals("Jenkins configured automatically by Jenkins Configuration as Code plugin\n\n", jenkins.getSystemMessage());
final LDAPSecurityRealm securityRealm = (LDAPSecurityRealm) jenkins.getSecurityRealm();
assertEquals(1, securityRealm.getConfigurations().size());
assertEquals(50000, jenkins.getSlaveAgentPort());
assertEquals(1, jenkins.getNodes().size());
assertEquals("static-agent", jenkins.getNode("static-agent").getNodeName());
final GitTool.DescriptorImpl gitTool = (GitTool.DescriptorImpl) jenkins.getDescriptor(GitTool.class);
assertEquals(1, gitTool.getInstallations().length);
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"));
}
use of com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey.DirectEntryPrivateKeySource 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")));
}
}
Aggregations