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