use of com.microsoft.azure.management.compute.implementation.DiskEncryptionSetInner in project cloudbreak by hortonworks.
the class AzureEncryptionResourcesTest method testCreateDiskEncryptionSetShouldReturnExistingDiskEncryptionSetWithPolling.
@Test
public void testCreateDiskEncryptionSetShouldReturnExistingDiskEncryptionSetWithPolling() {
DiskEncryptionSetCreationRequest requestedSet = new DiskEncryptionSetCreationRequest.Builder().withId("uniqueId").withCloudContext(cloudContext).withCloudCredential(cloudCredential).withDiskEncryptionSetResourceGroupName("dummyResourceGroup").withEncryptionKeyResourceGroupName("dummyResourceGroup").withTags(new HashMap<>()).withEncryptionKeyUrl("https://dummyVaultName.vault.azure.net/keys/dummyKeyName/dummyKeyVersion").build();
DiskEncryptionSetInner desInitial = (DiskEncryptionSetInner) new DiskEncryptionSetInner().withEncryptionType(DiskEncryptionSetType.ENCRYPTION_AT_REST_WITH_CUSTOMER_KEY).withActiveKey(new KeyForDiskEncryptionSet().withKeyUrl("https://dummyVaultName.vault.azure.net/keys/dummyKeyName/dummyKeyVersion").withSourceVault(new SourceVault().withId("/subscriptions/dummySubs/resourceGroups/dummyResourceGroup/providers/Microsoft.KeyVault/vaults/dummyVaultName"))).withIdentity(new EncryptionSetIdentity().withType(DiskEncryptionSetIdentityType.SYSTEM_ASSIGNED)).withLocation("dummyRegion").withTags(new HashMap<>());
ReflectionTestUtils.setField(desInitial, "id", DES_RESOURCE_ID);
EncryptionSetIdentity identity = new EncryptionSetIdentity().withType(DiskEncryptionSetIdentityType.SYSTEM_ASSIGNED);
ReflectionTestUtils.setField(identity, "principalId", DES_PRINCIPAL_ID);
DiskEncryptionSetInner desAfterPolling = (DiskEncryptionSetInner) new DiskEncryptionSetInner().withEncryptionType(DiskEncryptionSetType.ENCRYPTION_AT_REST_WITH_CUSTOMER_KEY).withActiveKey(new KeyForDiskEncryptionSet().withKeyUrl("https://dummyVaultName.vault.azure.net/keys/dummyKeyName/dummyKeyVersion").withSourceVault(new SourceVault().withId("/subscriptions/dummySubs/resourceGroups/dummyResourceGroup/providers/Microsoft.KeyVault/vaults/dummyVaultName"))).withIdentity(identity).withLocation("dummyRegion").withTags(new HashMap<>());
ReflectionTestUtils.setField(desAfterPolling, "id", DES_RESOURCE_ID);
Subscription subscription = mock(Subscription.class);
when(persistenceNotifier.notifyAllocation(any(CloudResource.class), eq(cloudContext))).thenReturn(new ResourcePersisted());
when(subscription.subscriptionId()).thenReturn("dummySubscriptionId");
when(azureUtils.generateDesNameByNameAndId(any(String.class), any(String.class))).thenReturn("dummyEnvName-DES-uniqueId");
when(azureClientService.createAuthenticatedContext(cloudContext, cloudCredential)).thenReturn(authenticatedContext);
when(authenticatedContext.getParameter(AzureClient.class)).thenReturn(azureClient);
when(azureClient.getCurrentSubscription()).thenReturn(subscription);
when(azureClient.getDiskEncryptionSetByName(any(String.class), any(String.class))).thenReturn(desInitial);
when(azureClient.checkKeyVaultAccessPolicyForServicePrincipal(any(String.class), any(String.class), any(String.class))).thenReturn(true);
initRetry();
// Return a different DES instance to simulate that the poller checker task initially indicated incomplete, hence the final DES was obtained by the
// scheduled execution of the poller
when(diskEncryptionSetCreationPoller.startPolling(eq(authenticatedContext), any(DiskEncryptionSetCreationCheckerContext.class), eq(desInitial))).thenReturn(desAfterPolling);
when(azureClient.keyVaultExists("dummyResourceGroup", "dummyVaultName")).thenReturn(Boolean.TRUE);
CreatedDiskEncryptionSet createdDes = underTest.createDiskEncryptionSet(requestedSet);
assertEquals(createdDes.getDiskEncryptionSetLocation(), "dummyRegion");
assertEquals(createdDes.getDiskEncryptionSetResourceGroupName(), "dummyResourceGroup");
assertThat(createdDes.getDiskEncryptionSetId()).isEqualTo(DES_RESOURCE_ID);
verify(azureClient, never()).createDiskEncryptionSet(any(String.class), any(String.class), any(String.class), any(String.class), any(String.class), any(Map.class));
verify(azureClient).grantKeyVaultAccessPolicyToServicePrincipal("dummyResourceGroup", "dummyVaultName", DES_PRINCIPAL_ID);
verify(azureClient).checkKeyVaultAccessPolicyForServicePrincipal("dummyResourceGroup", "dummyVaultName", DES_PRINCIPAL_ID);
verifyPersistedCloudResource();
}
use of com.microsoft.azure.management.compute.implementation.DiskEncryptionSetInner in project cloudbreak by hortonworks.
the class AzurePollTaskFactoryIntegrationTest method diskEncryptionSetCreationCheckerTaskTest.
@Test
void diskEncryptionSetCreationCheckerTaskTest() {
when(authenticatedContext.getParameter(AzureClient.class)).thenReturn(azureClient);
DiskEncryptionSetCreationCheckerContext checkerContext = new DiskEncryptionSetCreationCheckerContext(RESOURCE_GROUP_NAME, DISK_ENCRYPTION_SET_NAME);
PollTask<DiskEncryptionSetInner> result = underTest.diskEncryptionSetCreationCheckerTask(authenticatedContext, checkerContext);
assertThat(result).isInstanceOf(DiskEncryptionSetCreationCheckerTask.class);
DiskEncryptionSetCreationCheckerTask checkerTask = (DiskEncryptionSetCreationCheckerTask) result;
assertThat(checkerTask.getAuthenticatedContext()).isSameAs(authenticatedContext);
}
use of com.microsoft.azure.management.compute.implementation.DiskEncryptionSetInner in project cloudbreak by hortonworks.
the class AzurePollTaskFactoryTest method diskEncryptionSetCreationCheckerTaskTest.
@Test
void diskEncryptionSetCreationCheckerTaskTest() {
DiskEncryptionSetCreationCheckerContext checkerContext = new DiskEncryptionSetCreationCheckerContext(RESOURCE_GROUP_NAME, DISK_ENCRYPTION_SET_NAME);
PollTask<DiskEncryptionSetInner> checkerTask = mock(PollTask.class);
when(applicationContext.getBean(DiskEncryptionSetCreationCheckerTask.NAME, authenticatedContext, checkerContext)).thenReturn(checkerTask);
PollTask<DiskEncryptionSetInner> result = underTest.diskEncryptionSetCreationCheckerTask(authenticatedContext, checkerContext);
assertThat(result).isSameAs(checkerTask);
}
use of com.microsoft.azure.management.compute.implementation.DiskEncryptionSetInner in project cloudbreak by hortonworks.
the class DiskEncryptionSetCreationCheckerTaskTest method doCallTestWhenSuccess.
@Test
void doCallTestWhenSuccess() {
DiskEncryptionSetInner des = mock(DiskEncryptionSetInner.class);
when(azureClient.getDiskEncryptionSetByName(RESOURCE_GROUP_NAME, DISK_ENCRYPTION_SET_NAME)).thenReturn(des);
DiskEncryptionSetInner result = underTest.doCall();
assertThat(result).isSameAs(des);
}
use of com.microsoft.azure.management.compute.implementation.DiskEncryptionSetInner in project cloudbreak by hortonworks.
the class AzureClient method createDiskEncryptionSetInner.
private DiskEncryptionSetInner createDiskEncryptionSetInner(String sourceVaultId, String encryptionKeyUrl, String location, Map<String, String> tags) {
SourceVault sourceVault = new SourceVault().withId(sourceVaultId);
KeyForDiskEncryptionSet keyForDiskEncryptionSet = new KeyForDiskEncryptionSet().withKeyUrl(encryptionKeyUrl).withSourceVault(sourceVault);
EncryptionSetIdentity eSetId = new EncryptionSetIdentity().withType(DiskEncryptionSetIdentityType.SYSTEM_ASSIGNED);
return (DiskEncryptionSetInner) new DiskEncryptionSetInner().withEncryptionType(DiskEncryptionSetType.ENCRYPTION_AT_REST_WITH_CUSTOMER_KEY).withActiveKey(keyForDiskEncryptionSet).withIdentity(eSetId).withLocation(location).withTags(tags);
}
Aggregations