use of io.jenkins.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.
the class CredentialsTest method testGlobalScopedCredentials.
@ConfiguredWithCode("GlobalCredentials.yml")
@Test
public void testGlobalScopedCredentials() {
List<StandardUsernamePasswordCredentials> creds = CredentialsProvider.lookupCredentials(StandardUsernamePasswordCredentials.class, Jenkins.getInstanceOrNull(), null, Collections.emptyList());
assertThat(creds.size(), is(1));
assertEquals("user1", creds.get(0).getId());
assertEquals("Administrator", creds.get(0).getUsername());
assertEquals("secretPassword", creds.get(0).getPassword().getPlainText());
List<BasicSSHUserPrivateKey> creds2 = CredentialsProvider.lookupCredentials(BasicSSHUserPrivateKey.class, Jenkins.getInstanceOrNull(), null, Collections.emptyList());
assertThat(creds2.size(), is(1));
BasicSSHUserPrivateKey basicSSHUserPrivateKey = creds2.get(0);
assertEquals("agentuser", basicSSHUserPrivateKey.getUsername());
assertEquals("password", basicSSHUserPrivateKey.getPassphrase().getPlainText());
assertEquals("ssh private key used to connect ssh slaves", basicSSHUserPrivateKey.getDescription());
assertThat(basicSSHUserPrivateKey.getPrivateKeySource().getPrivateKeys().size(), is(1));
String directKey = basicSSHUserPrivateKey.getPrivateKeySource().getPrivateKeys().get(0);
assertThat(directKey, is("sp0ds9d+skkfjf"));
}
use of io.jenkins.plugins.casc.misc.ConfiguredWithCode 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"));
}
use of io.jenkins.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.
the class GithubOrganisationFolderTest method configure_github_organisation_folder_seed_job.
// @Test
// Fails as Items do override submit() with manual data-binding implementation
@ConfiguredWithCode("GithubOrganisationFolderTest.yml")
public void configure_github_organisation_folder_seed_job() {
final TopLevelItem job = Jenkins.get().getItem("ndeloof");
assertNotNull(job);
assertTrue(job instanceof OrganizationFolder);
OrganizationFolder folder = (OrganizationFolder) job;
assertEquals(1, folder.getNavigators().size());
final GitHubSCMNavigator github = folder.getNavigators().get(GitHubSCMNavigator.class);
assertNotNull(github);
assertEquals("ndeloof", github.getRepoOwner());
}
use of io.jenkins.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.
the class PropertiesSecretSourceTest method testSecretsFromPropertiesAreUpdatedAfterReload.
@Test
@ConfiguredWithCode("PropertiesSecretSourceTest.yaml")
public void testSecretsFromPropertiesAreUpdatedAfterReload() throws Exception {
File secretsFile = new File(getClass().getResource("secrets.properties").getFile());
Properties secrets = new Properties();
InputStream inputStream = new FileInputStream(secretsFile);
secrets.load(inputStream);
FileWriter fileWriter = new FileWriter(secretsFile);
String secretName = "testuser";
String updatedTestUserSecret = "charmander";
secrets.setProperty(secretName, updatedTestUserSecret);
try {
secrets.store(fileWriter, "store to properties file");
ConfigurationAsCode.get().configure(this.getClass().getResource("PropertiesSecretSourceTest.yaml").toString());
List<UsernamePasswordCredentials> credentialList = CredentialsProvider.lookupCredentials(UsernamePasswordCredentials.class, Jenkins.getInstanceOrNull(), null, Collections.emptyList());
assertEquals(1, credentialList.size());
UsernamePasswordCredentials credentials = credentialList.get(0);
assertEquals(updatedTestUserSecret, credentials.getUsername());
} finally {
secrets.setProperty(secretName, USERNAME_SECRET);
secrets.store(fileWriter, "store to properties file");
}
}
use of io.jenkins.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.
the class RoleStrategyTest method shouldExportRolesCorrect.
@Test
@ConfiguredWithCode("RoleStrategy1.yml")
public void shouldExportRolesCorrect() throws Exception {
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
CNode yourAttribute = getJenkinsRoot(context).get("authorizationStrategy");
String exported = toYamlString(yourAttribute);
String expected = toStringFromYamlFile(this, "RoleStrategy1Expected.yml");
assertThat(exported, is(expected));
}
Aggregations