Search in sources :

Example 6 with CredentialPrerequisitesResponse

use of com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse in project cloudbreak by hortonworks.

the class AuditCredentialV1ControllerTest method testGetPrerequisitesForCloudPlatform.

@Test
void testGetPrerequisitesForCloudPlatform() {
    CredentialPrerequisitesResponse credentialPrerequisitesResponse = mock(CredentialPrerequisitesResponse.class);
    when(credentialService.getPrerequisites(PLATFORM, false, DEPLOYMENT_ADDRESS, USER_CRN, CredentialType.AUDIT)).thenReturn(credentialPrerequisitesResponse);
    CredentialPrerequisitesResponse response = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.getPrerequisitesForCloudPlatform(PLATFORM, false, DEPLOYMENT_ADDRESS));
    assertThat(response).isEqualTo(credentialPrerequisitesResponse);
}
Also used : CredentialPrerequisitesResponse(com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse) Test(org.junit.jupiter.api.Test)

Example 7 with CredentialPrerequisitesResponse

use of com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse in project cloudbreak by hortonworks.

the class CredentialV1ControllerTest method testGetPrerequisitesForCloudPlatform.

@Test
void testGetPrerequisitesForCloudPlatform() {
    CredentialPrerequisitesResponse credentialPrerequisitesResponse = mock(CredentialPrerequisitesResponse.class);
    when(credentialService.getPrerequisites(PLATFORM, false, DEPLOYMENT_ADDRESS, USER_CRN, CredentialType.ENVIRONMENT)).thenReturn(credentialPrerequisitesResponse);
    CredentialPrerequisitesResponse response = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.getPrerequisitesForCloudPlatform(PLATFORM, false, DEPLOYMENT_ADDRESS));
    assertThat(response).isEqualTo(credentialPrerequisitesResponse);
}
Also used : CredentialPrerequisitesResponse(com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse) Test(org.junit.jupiter.api.Test)

Example 8 with CredentialPrerequisitesResponse

use of com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse in project cloudbreak by hortonworks.

the class GcpCredentialConnectorTest method testPrerequisites.

@Test
public void testPrerequisites() {
    final AuthenticatedContext authContext = createAuthContext();
    when(gcpPlatformParameters.getPrerequisitesCreationCommand(CredentialType.ENVIRONMENT)).thenReturn("prerequisites");
    CredentialPrerequisitesResponse prerequisites = underTest.getPrerequisites(authContext.getCloudContext(), "externalId", "auditExternalId", "deploymentAddress", CredentialType.ENVIRONMENT);
    CredentialPrerequisitesResponse credentialPrerequisitesResponse = new CredentialPrerequisitesResponse("platform", new GcpCredentialPrerequisites(Base64.encodeBase64String("prerequisites".getBytes())));
    Assert.assertEquals(credentialPrerequisitesResponse, prerequisites);
}
Also used : GcpCredentialPrerequisites(com.sequenceiq.cloudbreak.cloud.response.GcpCredentialPrerequisites) CredentialPrerequisitesResponse(com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Test(org.junit.jupiter.api.Test)

Example 9 with CredentialPrerequisitesResponse

use of com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse in project cloudbreak by hortonworks.

the class CredentialExperienceTest method getCredentialPrerequisitesResponse.

private CredentialPrerequisitesResponse getCredentialPrerequisitesResponse(String cloudProvider, String policy) {
    CredentialPrerequisitesResponse response = new CredentialPrerequisitesResponse();
    switch(cloudProvider) {
        case "AWS":
            response.setAws(new AwsCredentialPrerequisites());
            response.getAws().setPolicyJson(policy);
            response.getAws().setPolicies(Map.of("Environment", MINIMAL_POLICY));
            break;
        case "AZURE":
            response.setAzure(new AzureCredentialPrerequisites());
            response.getAzure().setRoleDefitionJson(policy);
            break;
        case "GCP":
            response.setGcp(new GcpCredentialPrerequisites());
            break;
        default:
    }
    return response;
}
Also used : AzureCredentialPrerequisites(com.sequenceiq.cloudbreak.cloud.response.AzureCredentialPrerequisites) GcpCredentialPrerequisites(com.sequenceiq.cloudbreak.cloud.response.GcpCredentialPrerequisites) CredentialPrerequisitesResponse(com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse) AwsCredentialPrerequisites(com.sequenceiq.cloudbreak.cloud.response.AwsCredentialPrerequisites)

Example 10 with CredentialPrerequisitesResponse

use of com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse in project cloudbreak by hortonworks.

the class AzureCredentialConnectorTest method testGetPrerequisitesReturnsTheExpectedValue.

@Test
public void testGetPrerequisitesReturnsTheExpectedValue() {
    String expectedCommand = "someAppCreationCommandValue";
    String expectedRoleDef = "roleDefJson";
    when(appCreationCommand.generateEnvironmentCredentialCommand(anyString())).thenReturn(expectedCommand);
    when(azurePlatformParameters.getRoleDefJson()).thenReturn(expectedRoleDef);
    CredentialPrerequisitesResponse result = underTest.getPrerequisites(TEST_CLOUD_CONTEXT, "2", "3", DEPLOYMENT_ADDRESS, CredentialType.ENVIRONMENT);
    assertEquals(PLATFORM, result.getCloudPlatform());
    assertEquals(expectedCommand, new String(Base64.decodeBase64(result.getAzure().getAppCreationCommand())));
    assertEquals(expectedRoleDef, result.getAzure().getRoleDefitionJson());
}
Also used : CredentialPrerequisitesResponse(com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

CredentialPrerequisitesResponse (com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse)15 Test (org.junit.jupiter.api.Test)6 GcpCredentialPrerequisites (com.sequenceiq.cloudbreak.cloud.response.GcpCredentialPrerequisites)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 AwsCredentialPrerequisites (com.sequenceiq.cloudbreak.cloud.response.AwsCredentialPrerequisites)2 AzureCredentialPrerequisites (com.sequenceiq.cloudbreak.cloud.response.AzureCredentialPrerequisites)2 OperationException (com.sequenceiq.cloudbreak.service.OperationException)2 CredentialOperationException (com.sequenceiq.environment.credential.exception.CredentialOperationException)2 IOException (java.io.IOException)2 BadRequestException (javax.ws.rs.BadRequestException)2 Test (org.junit.Test)2 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CredentialPrerequisitesRequest (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialPrerequisitesRequest)1 CredentialPrerequisitesResult (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialPrerequisitesResult)1