use of com.microsoft.jenkins.keyvault.SecretCertificateCredentials in project azure-credentials-plugin by jenkinsci.
the class ITSecretCertificateCredentials method getKeyStoreNotFound.
@Test
public void getKeyStoreNotFound() {
final String secretIdentifier = vaultUri + "/secrets/not-found/869660651aa3436994bd7290704c9394";
// Verify configuration
final SecretCertificateCredentials.DescriptorImpl descriptor = new SecretCertificateCredentials.DescriptorImpl();
final FormValidation result = descriptor.doVerifyConfiguration(jenkinsAzureCredentialsId, secretIdentifier, Secret.fromString(""));
Assert.assertEquals(FormValidation.Kind.ERROR, result.kind);
// Get key store
final SecretCertificateCredentials credentials = new SecretCertificateCredentials(CredentialsScope.SYSTEM, "", "", jenkinsAzureCredentialsId, secretIdentifier, Secret.fromString(""));
try {
final KeyStore keyStore = credentials.getKeyStore();
Assert.fail("Should throw exception but not");
} catch (Exception e) {
// Expect exception
}
}
use of com.microsoft.jenkins.keyvault.SecretCertificateCredentials in project azure-credentials-plugin by jenkinsci.
the class ITSecretCertificateCredentials method getKeyStore.
@Test
public void getKeyStore() throws IOException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException {
final String cert = IOUtils.toString(getClass().getResourceAsStream("../cert.pfx.b64"), StandardCharsets.UTF_8);
final KeyVaultSecret secretBundle = createSecret("secret-cert", cert);
final String secretIdentifier = secretBundle.getId();
final Secret password = Secret.fromString("123456");
// Verify configuration
final SecretCertificateCredentials.DescriptorImpl descriptor = new SecretCertificateCredentials.DescriptorImpl();
final FormValidation result = descriptor.doVerifyConfiguration(jenkinsAzureCredentialsId, secretIdentifier, password);
Assert.assertEquals(FormValidation.Kind.OK, result.kind);
// Get key store
final SecretCertificateCredentials credentials = new SecretCertificateCredentials(CredentialsScope.SYSTEM, "", "", jenkinsAzureCredentialsId, secretIdentifier, password);
final KeyStore keyStore = credentials.getKeyStore();
Assert.assertTrue(keyStore.containsAlias("msft"));
Assert.assertEquals(1, keyStore.size());
final Key key = keyStore.getKey("msft", password.getPlainText().toCharArray());
Assert.assertEquals("RSA", key.getAlgorithm());
}
Aggregations