Search in sources :

Example 1 with CredentialsRootConfigurator

use of com.cloudbees.plugins.credentials.casc.CredentialsRootConfigurator in project configuration-as-code-plugin by jenkinsci.

the class CredentialsTest method testExportFileCredentials.

@Test
@ConfiguredWithCode("GlobalCredentials.yml")
public void testExportFileCredentials() throws Exception {
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);
    CredentialsRootConfigurator root = ExtensionList.lookupSingleton(CredentialsRootConfigurator.class);
    CNode node = root.describe(root.getTargetComponent(context), context);
    assertNotNull(node);
    final Mapping mapping = node.asMapping();
    Mapping fileCredential = mapping.get("system").asMapping().get("domainCredentials").asSequence().get(0).asMapping().get("credentials").asSequence().get(2).asMapping().get("file").asMapping();
    assertThat(fileCredential.getScalarValue("scope"), is("GLOBAL"));
    assertThat(fileCredential.getScalarValue("id"), is("secret-file"));
    assertThat(fileCredential.getScalarValue("fileName"), is("mysecretfile.txt"));
    assertThat(fileCredential.getScalarValue("secretBytes"), not("WJjZAo="));
}
Also used : CNode(io.jenkins.plugins.casc.model.CNode) CredentialsRootConfigurator(com.cloudbees.plugins.credentials.casc.CredentialsRootConfigurator) Mapping(io.jenkins.plugins.casc.model.Mapping) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 2 with CredentialsRootConfigurator

use of com.cloudbees.plugins.credentials.casc.CredentialsRootConfigurator in project configuration-as-code-plugin by jenkinsci.

the class CredentialsTest method testExportSSHCredentials.

@ConfiguredWithCode("GlobalCredentials.yml")
@Test
public void testExportSSHCredentials() throws Exception {
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);
    CredentialsRootConfigurator root = ExtensionList.lookupSingleton(CredentialsRootConfigurator.class);
    CNode node = root.describe(root.getTargetComponent(context), context);
    assertNotNull(node);
    final Mapping mapping = node.asMapping();
    Mapping sshCredential = mapping.get("system").asMapping().get("domainCredentials").asSequence().get(0).asMapping().get("credentials").asSequence().get(1).asMapping().get("basicSSHUserPrivateKey").asMapping();
    assertThat(sshCredential.getScalarValue("scope"), is("SYSTEM"));
    assertThat(sshCredential.getScalarValue("id"), is("agent-private-key"));
    assertThat(sshCredential.getScalarValue("username"), is("agentuser"));
    String passphrase = sshCredential.getScalarValue("passphrase");
    assertThat(passphrase, not("password"));
    assertThat(requireNonNull(Secret.decrypt(passphrase), "Failed to decrypt the password from " + passphrase).getPlainText(), is("password"));
    String sshKeyExported = sshCredential.get("privateKeySource").asMapping().get("directEntry").asMapping().get("privateKey").asScalar().getValue();
    assertThat(sshKeyExported, not("sp0ds9d+skkfjf"));
    assertThat(requireNonNull(Secret.decrypt(sshKeyExported)).getPlainText(), is("sp0ds9d+skkfjf"));
}
Also used : CNode(io.jenkins.plugins.casc.model.CNode) CredentialsRootConfigurator(com.cloudbees.plugins.credentials.casc.CredentialsRootConfigurator) Mapping(io.jenkins.plugins.casc.model.Mapping) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Aggregations

CredentialsRootConfigurator (com.cloudbees.plugins.credentials.casc.CredentialsRootConfigurator)2 ConfiguredWithCode (io.jenkins.plugins.casc.misc.ConfiguredWithCode)2 CNode (io.jenkins.plugins.casc.model.CNode)2 Mapping (io.jenkins.plugins.casc.model.Mapping)2 Test (org.junit.Test)2