Search in sources :

Example 1 with SecretStringCredentials

use of com.microsoft.jenkins.keyvault.SecretStringCredentials in project azure-credentials-plugin by jenkinsci.

the class ITSecretStringCredentials method getSecretNotFound.

@Test
public void getSecretNotFound() {
    final String secretIdentifier = vaultUri + "/secrets/not-found/869660651aa3436994bd7290704c9394";
    // Verify configuration
    final SecretStringCredentials.DescriptorImpl descriptor = new SecretStringCredentials.DescriptorImpl();
    final FormValidation result = descriptor.doVerifyConfiguration(jenkinsAzureCredentialsId, secretIdentifier);
    Assert.assertEquals(FormValidation.Kind.ERROR, result.kind);
    // Get secret
    final SecretStringCredentials credentials = new SecretStringCredentials(CredentialsScope.SYSTEM, "", "", jenkinsAzureCredentialsId, secretIdentifier);
    try {
        final Secret secret = credentials.getSecret();
        Assert.fail("Should throw exception but not");
    } catch (Exception e) {
    // Expect exception
    }
}
Also used : Secret(hudson.util.Secret) KeyVaultSecret(com.azure.security.keyvault.secrets.models.KeyVaultSecret) FormValidation(hudson.util.FormValidation) SecretStringCredentials(com.microsoft.jenkins.keyvault.SecretStringCredentials) Test(org.junit.Test)

Example 2 with SecretStringCredentials

use of com.microsoft.jenkins.keyvault.SecretStringCredentials in project azure-credentials-plugin by jenkinsci.

the class ITSecretStringCredentials method getSecret.

@Test
public void getSecret() {
    final KeyVaultSecret secretBundle = createSecret("secret-string", "I'm secret");
    final String secretIdentifier = secretBundle.getId();
    // Verify configuration
    final SecretStringCredentials.DescriptorImpl descriptor = new SecretStringCredentials.DescriptorImpl();
    final FormValidation result = descriptor.doVerifyConfiguration(jenkinsAzureCredentialsId, secretIdentifier);
    Assert.assertEquals(FormValidation.Kind.OK, result.kind);
    // Get secret
    final SecretStringCredentials credentials = new SecretStringCredentials(CredentialsScope.SYSTEM, "", "", jenkinsAzureCredentialsId, secretIdentifier);
    final Secret secret = credentials.getSecret();
    Assert.assertEquals("I'm secret", secret.getPlainText());
}
Also used : KeyVaultSecret(com.azure.security.keyvault.secrets.models.KeyVaultSecret) Secret(hudson.util.Secret) KeyVaultSecret(com.azure.security.keyvault.secrets.models.KeyVaultSecret) FormValidation(hudson.util.FormValidation) SecretStringCredentials(com.microsoft.jenkins.keyvault.SecretStringCredentials) Test(org.junit.Test)

Aggregations

KeyVaultSecret (com.azure.security.keyvault.secrets.models.KeyVaultSecret)2 SecretStringCredentials (com.microsoft.jenkins.keyvault.SecretStringCredentials)2 FormValidation (hudson.util.FormValidation)2 Secret (hudson.util.Secret)2 Test (org.junit.Test)2