use of com.cloudbees.plugins.credentials.SecretBytes in project support-core-plugin by jenkinsci.
the class OtherConfigFilesComponentTest method setup.
@Before
public void setup() {
Secret secret = Secret.fromString("this-is-a-secret");
SecretBytes secret2 = SecretBytes.fromBytes("this-is-another-type-of-secret".getBytes());
assertEquals("this-is-a-secret", secret.getPlainText());
assertEquals("this-is-another-type-of-secret", new String(secret2.getPlainData()));
String encrypted_secret = secret.getEncryptedValue();
String encrypted_secret2 = secret2.toString();
xml = "<com.cloudbees.plugins.credentials.SystemCredentialsProvider plugin=\"credentials@1.18\">\n" + " <domainCredentialsMap class=\"hudson.util.CopyOnWriteMap$Hash\">\n" + " <entry>\n" + " <com.cloudbees.plugins.credentials.domains.Domain>\n" + " <specifications/>\n" + " </com.cloudbees.plugins.credentials.domains.Domain>\n" + " <java.util.concurrent.CopyOnWriteArrayList>\n" + " <com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>\n" + " <scope>GLOBAL</scope>\n" + " <id>f9ebaa5c-a7fc-46e4-93ab-453699781181</id>\n" + " <description>Alice</description>\n" + " <username/>\n" + " <password>" + encrypted_secret + "</password>\n" + " </com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>\n" + " <com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>\n" + " <scope>GLOBAL</scope>\n" + " <id>f9ebaa5c-a7fc-46e4-93ab-453699781182</id>\n" + " <description>Bobby</description>\n" + " <username/>\n" + " <password>" + encrypted_secret2 + "</password>\n" + " </com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>\n" + " </java.util.concurrent.CopyOnWriteArrayList>\n" + " </entry>\n" + " </domainCredentialsMap>\n" + "</com.cloudbees.plugins.credentials.SystemCredentialsProvider>";
}
use of com.cloudbees.plugins.credentials.SecretBytes in project configuration-as-code-plugin by jenkinsci.
the class CredentialsReadmeTest method testGlobalScopedCredentials.
@Test
@ConfiguredWithReadme("credentials/README.md#1")
@Envs({ @Env(name = "SSH_KEY_PASSWORD", value = PASSPHRASE), @Env(name = "SSH_PRIVATE_KEY", value = PRIVATE_KEY), @Env(name = "SSH_PRIVATE_FILE_PATH", value = "private-key.pem"), @Env(name = "SOME_USER_PASSWORD", value = PASSWORD), @Env(name = "SECRET_TEXT", value = TEXT), @Env(name = "AWS_ACCESS_KEY", value = ACCESS_KEY), @Env(name = "AWS_SECRET_ACCESS_KEY", value = SECRET_ACCESS_KEY), @Env(name = "SECRET_FILE_PATH", value = MYSECRETFILE_TXT), @Env(name = "SECRET_PASSWORD_CERT", value = PASSWORD), @Env(name = "SECRET_CERT_FILE_PATH", value = TEST_CERT) })
public void testGlobalScopedCredentials() throws Exception {
List<Credentials> creds = CredentialsProvider.lookupCredentials(Credentials.class, Jenkins.get(), null, Collections.emptyList());
assertThat(creds, hasSize(8));
for (Credentials credentials : creds) {
if (credentials instanceof BasicSSHUserPrivateKey) {
BasicSSHUserPrivateKey key = (BasicSSHUserPrivateKey) credentials;
assertThat(key.getPassphrase(), hasPlainText(PASSPHRASE));
assertThat(key.getPrivateKey(), equalTo(PRIVATE_KEY));
assertThat(key.getId(), anyOf(is("ssh_with_passphrase_provided"), is("ssh_with_passphrase_provided_via_file")));
assertThat(key.getUsername(), is("ssh_root"));
assertThat(key.getScope(), is(CredentialsScope.SYSTEM));
} else if (credentials instanceof UsernamePasswordCredentials) {
UsernamePasswordCredentials user = (UsernamePasswordCredentials) credentials;
assertThat(user.getUsername(), is("some-user"));
assertThat(user.getPassword(), hasPlainText(PASSWORD));
assertThat(user.getScope(), is(CredentialsScope.GLOBAL));
} else if (credentials instanceof StringCredentials) {
StringCredentials string = (StringCredentials) credentials;
assertThat(string.getId(), is("secret-text"));
assertThat(string.getSecret(), hasPlainText(TEXT));
assertThat(string.getScope(), is(CredentialsScope.GLOBAL));
} else if (credentials instanceof AWSCredentialsImpl) {
AWSCredentialsImpl aws = (AWSCredentialsImpl) credentials;
assertThat(aws.getId(), is("AWS"));
assertThat(aws.getAccessKey(), equalTo(ACCESS_KEY));
assertThat(aws.getSecretKey(), hasPlainText(SECRET_ACCESS_KEY));
assertThat(aws.getScope(), is(CredentialsScope.GLOBAL));
} else if (credentials instanceof FileCredentials) {
FileCredentials file = (FileCredentials) credentials;
assertThat(file.getId(), anyOf(is("secret-file"), is("secret-file_via_binary_file")));
assertThat(file.getFileName(), is(MYSECRETFILE_TXT));
String fileContent = IOUtils.toString(file.getContent(), StandardCharsets.UTF_8);
assertThat(fileContent, containsString("SUPER SECRET"));
assertThat(file.getScope(), is(CredentialsScope.GLOBAL));
} else if (credentials instanceof CertificateCredentialsImpl) {
CertificateCredentialsImpl cert = (CertificateCredentialsImpl) credentials;
assertThat(cert.getId(), is("secret-certificate"));
assertThat(cert.getPassword(), hasPlainText(PASSWORD));
byte[] fileContent = Files.readAllBytes(Paths.get(getClass().getResource(TEST_CERT).toURI()));
SecretBytes secretBytes = SecretBytes.fromString(Base64.getEncoder().encodeToString(fileContent));
UploadedKeyStoreSource keyStoreSource = (UploadedKeyStoreSource) cert.getKeyStoreSource();
assertThat(keyStoreSource.getUploadedKeystore().getPlainData(), is(secretBytes.getPlainData()));
assertThat(cert.getKeyStore().containsAlias("1"), is(true));
assertThat(cert.getKeyStore().getCertificate("1").getType(), is("X.509"));
assertThat(CredentialsNameProvider.name(cert), is("EMAILADDRESS=me@myhost.mydomain, CN=pkcs12, O=Fort-Funston, L=SanFrancisco, ST=CA, C=US (my secret cert)"));
assertThat(cert.getScope(), is(CredentialsScope.GLOBAL));
}
}
}
use of com.cloudbees.plugins.credentials.SecretBytes in project support-core-plugin by jenkinsci.
the class SecretHandlerTest method setup.
@Before
public void setup() {
Secret secret1 = Secret.fromString("this-is-a-secret");
SecretBytes secret2 = SecretBytes.fromBytes("this-is-another-type-of-secret".getBytes());
assertEquals("this-is-a-secret", secret1.getPlainText());
assertEquals("this-is-another-type-of-secret", new String(secret2.getPlainData()));
String encryptedSecret1 = secret1.getEncryptedValue();
String encryptedSecret2 = secret2.toString();
xml = "<com.cloudbees.plugins.credentials.SystemCredentialsProvider plugin=\"credentials@1.18\">\n" + " <domainCredentialsMap class=\"hudson.util.CopyOnWriteMap$Hash\">\n" + " <entry>\n" + " <com.cloudbees.plugins.credentials.domains.Domain>\n" + " <specifications/>\n" + " </com.cloudbees.plugins.credentials.domains.Domain>\n" + " <java.util.concurrent.CopyOnWriteArrayList>\n" + " <com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>\n" + " <scope>GLOBAL</scope>\n" + " <id>f9ebaa5c-a7fc-46e4-93ab-453699781181</id>\n" + " <description>Alice</description>\n" + " <username/>\n" + " <password>" + encryptedSecret1 + "</password>\n" + " </com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>\n" + " <com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>\n" + " <scope>GLOBAL</scope>\n" + " <id>f9ebaa5c-a7fc-46e4-93ab-453699781182</id>\n" + " <description>Bobby�x;</description>\n" + " <username/>\n" + " <password>" + encryptedSecret2 + "</password>\n" + " </com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>\n" + " </java.util.concurrent.CopyOnWriteArrayList>\n" + " </entry>\n" + " </domainCredentialsMap>\n" + "</com.cloudbees.plugins.credentials.SystemCredentialsProvider>";
}
Aggregations