Search in sources :

Example 6 with AzureCredentials

use of com.microsoft.azure.util.AzureCredentials in project azure-keyvault-plugin by jenkinsci.

the class AzureKeyVaultGlobalConfigurationSystemPropertySPTest method testValuesSet.

@Test
public void testValuesSet() {
    AzureKeyVaultGlobalConfiguration configuration = AzureKeyVaultGlobalConfiguration.get();
    assertThat(configuration.getCredentialID(), is(AzureKeyVaultGlobalConfiguration.GENERATED_ID));
    assertThat(configuration.getKeyVaultURL(), is("https://mine.vault.azure.net"));
    Credentials credentials = SystemCredentialsProvider.getInstance().getCredentials().get(0);
    assertThat(credentials, instanceOf(AzureCredentials.class));
    AzureCredentials azureCredentials = (AzureCredentials) credentials;
    assertThat(azureCredentials.getClientId(), is("1234"));
    assertThat(azureCredentials.getPlainClientSecret(), is("1255534"));
    assertThat(azureCredentials.getSubscriptionId(), is("5678"));
    assertThat(azureCredentials.getTenant(), is("tenant_id"));
    // Test updating value
    System.setProperty("jenkins.azure-keyvault.url", "https://mine2.vault.azure.net");
    System.setProperty("jenkins.azure-keyvault.sp.client_id", "5678");
    System.setProperty("jenkins.azure-keyvault.sp.client_secret", "99999");
    System.setProperty("jenkins.azure-keyvault.sp.subscription_id", "9999");
    System.setProperty("jenkins.azure-keyvault.sp.tenant_id", "11111");
    configuration = AzureKeyVaultGlobalConfiguration.get();
    assertThat(configuration.getCredentialID(), is(AzureKeyVaultGlobalConfiguration.GENERATED_ID));
    assertThat(configuration.getKeyVaultURL(), is("https://mine2.vault.azure.net"));
    List<Credentials> credentialsList = SystemCredentialsProvider.getInstance().getCredentials();
    assertThat(credentialsList.size(), is(1));
    AzureCredentials azureCredentialsUpdated = (AzureCredentials) credentialsList.get(0);
    assertThat(azureCredentialsUpdated.getClientId(), is("5678"));
    assertThat(azureCredentialsUpdated.getPlainClientSecret(), is("99999"));
    assertThat(azureCredentialsUpdated.getSubscriptionId(), is("9999"));
    assertThat(azureCredentialsUpdated.getTenant(), is("11111"));
}
Also used : AzureCredentials(com.microsoft.azure.util.AzureCredentials) Credentials(com.cloudbees.plugins.credentials.Credentials) AzureCredentials(com.microsoft.azure.util.AzureCredentials) AzureImdsCredentials(com.microsoft.azure.util.AzureImdsCredentials) Test(org.junit.Test)

Example 7 with AzureCredentials

use of com.microsoft.azure.util.AzureCredentials in project azure-keyvault-plugin by jenkinsci.

the class AzureKeyVaultGlobalConfigurationEnvVarSPTest method testValuesSet.

@Test
public void testValuesSet() {
    AzureKeyVaultGlobalConfiguration configuration = AzureKeyVaultGlobalConfiguration.get();
    assertThat(configuration.getCredentialID(), is(AzureKeyVaultGlobalConfiguration.GENERATED_ID));
    assertThat(configuration.getCredentialID(), is(AzureKeyVaultGlobalConfiguration.GENERATED_ID));
    assertThat(configuration.getKeyVaultURL(), is("https://mine.vault.azure.net"));
    Credentials credentials = SystemCredentialsProvider.getInstance().getCredentials().get(0);
    assertThat(credentials, instanceOf(AzureCredentials.class));
    AzureCredentials azureCredentials = (AzureCredentials) credentials;
    assertThat(azureCredentials.getClientId(), is("1234"));
    assertThat(azureCredentials.getPlainClientSecret(), is("1255534"));
    assertThat(azureCredentials.getSubscriptionId(), is("5678"));
    assertThat(azureCredentials.getTenant(), is("tenant_id"));
}
Also used : AzureCredentials(com.microsoft.azure.util.AzureCredentials) AzureCredentials(com.microsoft.azure.util.AzureCredentials) Credentials(com.cloudbees.plugins.credentials.Credentials) Test(org.junit.Test)

Aggregations

AzureCredentials (com.microsoft.azure.util.AzureCredentials)7 Credentials (com.cloudbees.plugins.credentials.Credentials)5 AzureImdsCredentials (com.microsoft.azure.util.AzureImdsCredentials)4 Test (org.junit.Test)3 AzureBaseCredentials (com.microsoft.azure.util.AzureBaseCredentials)2 IOException (java.io.IOException)2 TokenCredential (com.azure.core.credential.TokenCredential)1 ClientSecretCredentialBuilder (com.azure.identity.ClientSecretCredentialBuilder)1 ManagedIdentityCredentialBuilder (com.azure.identity.ManagedIdentityCredentialBuilder)1 AzureResourceManager (com.azure.resourcemanager.AzureResourceManager)1 Vault (com.azure.resourcemanager.keyvault.models.Vault)1 SecretClient (com.azure.security.keyvault.secrets.SecretClient)1 CredentialsScope (com.cloudbees.plugins.credentials.CredentialsScope)1 CredentialsStore (com.cloudbees.plugins.credentials.CredentialsStore)1 SystemCredentialsProvider (com.cloudbees.plugins.credentials.SystemCredentialsProvider)1 IdCredentials (com.cloudbees.plugins.credentials.common.IdCredentials)1 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)1 Domain (com.cloudbees.plugins.credentials.domains.Domain)1 SecretClientCache (com.microsoft.jenkins.keyvault.SecretClientCache)1 Extension (hudson.Extension)1