Search in sources :

Example 1 with ENVIRONMENT

use of com.sequenceiq.common.model.CredentialType.ENVIRONMENT in project cloudbreak by hortonworks.

the class CredentialDeleteServiceTest method testMultipleIfAllTheCredentialsAreExistsAndAbleToArchiveThenExpectedCredentialsAreComingBack.

@Test
void testMultipleIfAllTheCredentialsAreExistsAndAbleToArchiveThenExpectedCredentialsAreComingBack() {
    String firstCredentialName = "first";
    String secondCredentialName = "second";
    Credential firstCred = createCredentialWithName(firstCredentialName);
    Credential secondCred = createCredentialWithName(secondCredentialName);
    Set<String> names = Set.of(firstCredentialName, secondCredentialName);
    when(credentialService.findByNameAndAccountId(eq(firstCredentialName), eq(ACCOUNT_ID), any(Set.class), any())).thenReturn(Optional.of(firstCred));
    when(credentialService.findByNameAndAccountId(eq(secondCredentialName), eq(ACCOUNT_ID), any(Set.class), any())).thenReturn(Optional.of(secondCred));
    when(credentialService.save(firstCred)).thenReturn(firstCred);
    when(credentialService.save(secondCred)).thenReturn(secondCred);
    doNothing().when(ownerAssignmentService).notifyResourceDeleted(any(), any());
    Set<Credential> result = underTest.deleteMultiple(names, ACCOUNT_ID, ENVIRONMENT);
    assertNotNull(result);
    assertEquals(2L, result.size());
    assertTrue(result.stream().anyMatch(credential -> credential.getName().startsWith(firstCredentialName)));
    assertTrue(result.stream().anyMatch(credential -> credential.getName().startsWith(secondCredentialName)));
    assertTrue(result.stream().allMatch(Credential::isArchived));
    verify(credentialService, times(2)).findByNameAndAccountId(anyString(), anyString(), anyCollection(), any());
    verify(environmentViewService, times(2)).findAllByCredentialId(any());
    verify(credentialService, times(2)).save(any());
    verify(credentialService, times(1)).save(firstCred);
    verify(credentialService, times(1)).save(secondCred);
    verify(ownerAssignmentService, times(2)).notifyResourceDeleted(any(), any());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) NotificationSender(com.sequenceiq.notification.NotificationSender) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Credential(com.sequenceiq.environment.credential.domain.Credential) Client(javax.ws.rs.client.Client) OwnerAssignmentService(com.sequenceiq.authorization.service.OwnerAssignmentService) MockitoAnnotations(org.mockito.MockitoAnnotations) CloudbreakMessagesService(com.sequenceiq.cloudbreak.message.CloudbreakMessagesService) ENVIRONMENT(com.sequenceiq.common.model.CredentialType.ENVIRONMENT) BadRequestException(javax.ws.rs.BadRequestException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Notification(com.sequenceiq.notification.Notification) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) List(java.util.List) EnvironmentViewService(com.sequenceiq.environment.environment.service.EnvironmentViewService) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Credential(com.sequenceiq.environment.credential.domain.Credential) Set(java.util.Set) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 2 with ENVIRONMENT

use of com.sequenceiq.common.model.CredentialType.ENVIRONMENT in project cloudbreak by hortonworks.

the class EnvironmentServiceIntegrationTest method setup.

@BeforeEach
public void setup() {
    client = new EnvironmentServiceClientBuilder(String.format(SERVICE_ADDRESS, port)).withCertificateValidation(false).withDebug(true).withIgnorePreValidation(true).build().withCrn(TEST_USER_CRN);
    credential = new Credential();
    credential.setName("credential_test");
    credential.setResourceCrn(TEST_RESOURCE_CRN);
    credential.setAccountId(TEST_ACCOUNT_ID);
    credential.setCloudPlatform("AWS");
    credential.setCreator(TEST_USER_CRN);
    credential.setDescription("description");
    credential.setGovCloud(false);
    credential.setArchived(false);
    credential.setType(ENVIRONMENT);
    credentialRequest = new CredentialRequest();
    when(entitlementService.azureEnabled(any())).thenReturn(true);
    doNothing().when(grpcUmsClient).assignResourceRole(anyString(), anyString(), anyString(), any(), any());
    lenient().when(grpcUmsClient.hasRights(anyString(), anyList(), any(), any())).then(i -> {
        List<RightCheck> rightChecks = i.getArgument(1);
        return rightChecks.stream().map(r -> Boolean.TRUE).collect(toList());
    });
    lenient().when(grpcUmsClient.checkAccountRight(anyString(), anyString(), any(), any())).thenReturn(true);
    Map<String, Boolean> rightCheckMap = Maps.newHashMap();
    rightCheckMap.put(credential.getResourceCrn(), true);
    when(umsResourceAuthorizationService.getRightOfUserOnResources(anyString(), any(), anyList())).thenReturn(rightCheckMap);
    when(grpcUmsClient.getResourceRoles(any(), any())).thenReturn(Set.of("crn:altus:iam:us-west-1:altus:resourceRole:Owner", "crn:altus:iam:us-west-1:altus:resourceRole:EnvironmentAdmin"));
}
Also used : RightCheck(com.cloudera.thunderhead.service.authorization.AuthorizationProto.RightCheck) BeforeEach(org.junit.jupiter.api.BeforeEach) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) CredentialVerificationRequest(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationRequest) ResourceDefinitionResult(com.sequenceiq.cloudbreak.cloud.event.platform.ResourceDefinitionResult) SecretService(com.sequenceiq.cloudbreak.service.secret.service.SecretService) ActiveProfiles(org.springframework.test.context.ActiveProfiles) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) NetworkService(com.sequenceiq.environment.network.NetworkService) Map(java.util.Map) ENVIRONMENT(com.sequenceiq.common.model.CredentialType.ENVIRONMENT) AzureCredentialRequestParameters(com.sequenceiq.environment.api.v1.credential.model.parameters.azure.AzureCredentialRequestParameters) BadRequestException(javax.ws.rs.BadRequestException) RoleBasedRequest(com.sequenceiq.environment.api.v1.credential.model.parameters.azure.RoleBasedRequest) AwsDefaultRegionSelectionFailed(com.sequenceiq.cloudbreak.cloud.aws.common.exception.AwsDefaultRegionSelectionFailed) InteractiveLoginRequest(com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveLoginRequest) MockBean(org.springframework.boot.test.mock.mockito.MockBean) UmsResourceAuthorizationService(com.sequenceiq.authorization.service.UmsResourceAuthorizationService) AwsCredentialParameters(com.sequenceiq.environment.api.v1.credential.model.parameters.aws.AwsCredentialParameters) Set(java.util.Set) Mockito.doNothing(org.mockito.Mockito.doNothing) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) CredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CredentialStatus) NotFoundException(javax.ws.rs.NotFoundException) Test(org.junit.jupiter.api.Test) ProxyResponses(com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponses) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ProxyTestSource.getProxyConfig(com.sequenceiq.environment.proxy.v1.ProxyTestSource.getProxyConfig) ProxyConfigRepository(com.sequenceiq.environment.proxy.repository.ProxyConfigRepository) InitCodeGrantFlowRequest(com.sequenceiq.cloudbreak.cloud.event.credential.InitCodeGrantFlowRequest) UmsAccountAuthorizationService(com.sequenceiq.authorization.service.UmsAccountAuthorizationService) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Mock(org.mockito.Mock) Credential(com.sequenceiq.environment.credential.domain.Credential) ProxyRequest(com.sequenceiq.environment.api.v1.proxy.model.request.ProxyRequest) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Mockito.lenient(org.mockito.Mockito.lenient) CredentialRepository(com.sequenceiq.environment.credential.repository.CredentialRepository) TestConfigurationForServiceIntegration(com.sequenceiq.environment.service.integration.testconfiguration.TestConfigurationForServiceIntegration) Inject(javax.inject.Inject) ProxyResponse(com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse) CredentialRequest(com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest) FileReaderUtils(com.sequenceiq.cloudbreak.util.FileReaderUtils) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) RightCheck(com.cloudera.thunderhead.service.authorization.AuthorizationProto.RightCheck) EnvironmentServiceClientBuilder(com.sequenceiq.environment.client.EnvironmentServiceClientBuilder) ForbiddenException(javax.ws.rs.ForbiddenException) QuartzJobInitializer(com.sequenceiq.cloudbreak.quartz.configuration.QuartzJobInitializer) CredentialVerificationResult(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationResult) ResourceDefinitionRequest(com.sequenceiq.cloudbreak.cloud.event.platform.ResourceDefinitionRequest) Mockito.when(org.mockito.Mockito.when) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Maps(com.google.common.collect.Maps) GrpcUmsClient(com.sequenceiq.cloudbreak.auth.altus.GrpcUmsClient) KeyBasedParameters(com.sequenceiq.environment.api.v1.credential.model.parameters.aws.KeyBasedParameters) LocalServerPort(org.springframework.boot.web.server.LocalServerPort) EnvironmentServiceCrnEndpoints(com.sequenceiq.environment.client.EnvironmentServiceCrnEndpoints) Collectors.toList(java.util.stream.Collectors.toList) AfterEach(org.junit.jupiter.api.AfterEach) ProxyTestSource.getProxyRequest(com.sequenceiq.environment.proxy.v1.ProxyTestSource.getProxyRequest) Assertions(org.junit.jupiter.api.Assertions) InteractiveCredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.InteractiveCredentialResponse) RequestProvider(com.sequenceiq.environment.credential.service.RequestProvider) InteractiveLoginResult(com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveLoginResult) ProxyConfig(com.sequenceiq.environment.proxy.domain.ProxyConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CredentialResponses(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponses) CredentialRequest(com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest) Credential(com.sequenceiq.environment.credential.domain.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) EnvironmentServiceClientBuilder(com.sequenceiq.environment.client.EnvironmentServiceClientBuilder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ENVIRONMENT (com.sequenceiq.common.model.CredentialType.ENVIRONMENT)2 Credential (com.sequenceiq.environment.credential.domain.Credential)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 BadRequestException (javax.ws.rs.BadRequestException)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Test (org.junit.jupiter.api.Test)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Mock (org.mockito.Mock)2 Mockito.doNothing (org.mockito.Mockito.doNothing)2 Mockito.when (org.mockito.Mockito.when)2 RightCheck (com.cloudera.thunderhead.service.authorization.AuthorizationProto.RightCheck)1 Maps (com.google.common.collect.Maps)1 OwnerAssignmentService (com.sequenceiq.authorization.service.OwnerAssignmentService)1 UmsAccountAuthorizationService (com.sequenceiq.authorization.service.UmsAccountAuthorizationService)1 UmsResourceAuthorizationService (com.sequenceiq.authorization.service.UmsResourceAuthorizationService)1