Search in sources :

Example 26 with Credential

use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.

the class EnvironmentValidationHandlerTest method createEnvironmentValidationDto.

private EnvironmentValidationDto createEnvironmentValidationDto() {
    EnvironmentValidationDto environmentValidationDto = new EnvironmentValidationDto();
    environmentValidationDto.setValidationType(ValidationType.ENVIRONMENT_CREATION);
    EnvironmentDto environmentDto = new EnvironmentDto();
    environmentDto.setId(1L);
    Credential credential = new Credential();
    credential.setResourceCrn("credential");
    environmentDto.setCredential(credential);
    environmentValidationDto.setEnvironmentDto(environmentDto);
    return environmentValidationDto;
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto)

Example 27 with Credential

use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.

the class ServiceProviderCredentialAdapterTest method testInitCodeGrantFlowShouldAddAdditionalAttributesToAzureCodeGrantFlowAttributes.

@Test
void testInitCodeGrantFlowShouldAddAdditionalAttributesToAzureCodeGrantFlowAttributes() {
    String expectedAdditionalAttributeKey = "someCloudCredentialKey";
    String expectedAdditionalAttributeValue = "someCloudCredentialValue";
    String initialAttributeKey = "aKey";
    String initialAttributeValue = "aValue";
    Map<String, Object> initialAttributes = new HashMap<>();
    Map<String, Object> initialAzureAttributes = new HashMap<>();
    Map<String, String> initialAzureCodeGrantFlowParams = new HashMap<>();
    initialAzureCodeGrantFlowParams.put(initialAttributeKey, initialAttributeValue);
    initialAzureAttributes.put("codeGrantFlowBased", initialAzureCodeGrantFlowParams);
    initialAttributes.put("azure", initialAzureAttributes);
    Credential credential = new Credential();
    String initialCredentialAttriute = new Json(initialAttributes).getValue();
    credential.setAttributes(initialCredentialAttriute);
    credential.setId(CREDENTIAL_ID);
    credential.setCloudPlatform(CLOUD_PLATFORM);
    credential.setName(CREDENTIAL_NAME);
    when(credentialConverter.convert(credential)).thenReturn(convertedCredential);
    when(initCodeGrantFlowResponse.getCodeGrantFlowInitParams()).thenReturn(Map.of(expectedAdditionalAttributeKey, expectedAdditionalAttributeValue));
    Credential result = underTest.initCodeGrantFlow(credential, ACCOUNT_ID);
    assertNotEquals(initialCredentialAttriute, result.getAttributes());
    var attributeMap = new Json(result.getAttributes()).getMap();
    Map<String, Object> azureAttributes = (Map<String, Object>) attributeMap.get("azure");
    Map<String, String> codeGrattFlowAttributes = (Map<String, String>) azureAttributes.get("codeGrantFlowBased");
    assertTrue(codeGrattFlowAttributes.containsKey(initialAttributeKey));
    assertTrue(codeGrattFlowAttributes.containsKey(expectedAdditionalAttributeKey));
    assertEquals(expectedAdditionalAttributeValue, codeGrattFlowAttributes.get(expectedAdditionalAttributeKey));
    assertEquals(initialAttributeValue, codeGrattFlowAttributes.get(initialAttributeKey));
    assertEquals(credential, result);
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) HashMap(java.util.HashMap) Json(com.sequenceiq.cloudbreak.common.json.Json) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 28 with Credential

use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.

the class CredentialViewConverterTest method testConvertCredential.

@Test
void testConvertCredential() {
    Credential credential = new Credential();
    credential.setName(CRED_NAME);
    credential.setCloudPlatform(CLOUD_PLATFORM);
    credential.setCreator(CREATOR);
    credential.setResourceCrn(CRN);
    credential.setDescription(DESCRIPTION);
    credential.setVerificationStatusText(VERIFICATION_STATUS_TEXT);
    credential.setType(CredentialType.ENVIRONMENT);
    credential.setGovCloud(true);
    CredentialView result = underTest.convert(credential);
    assertEquals(CRED_NAME, result.getName());
    assertEquals(CLOUD_PLATFORM, result.getCloudPlatform());
    assertEquals(CREATOR, result.getCreator());
    assertEquals(CRN, result.getResourceCrn());
    assertEquals(DESCRIPTION, result.getDescription());
    assertEquals(VERIFICATION_STATUS_TEXT, result.getVerificationStatusText());
    assertEquals(CredentialType.ENVIRONMENT, result.getType());
    assertTrue(result.getGovCloud());
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) CredentialView(com.sequenceiq.environment.credential.domain.CredentialView) Test(org.junit.jupiter.api.Test)

Example 29 with Credential

use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.

the class CredentialViewConverterTest method testConvertToCredentialViewResponse.

@Test
void testConvertToCredentialViewResponse() {
    Credential credential = new Credential();
    credential.setName(CRED_NAME);
    credential.setCloudPlatform(CLOUD_PLATFORM);
    credential.setCreator(CREATOR);
    credential.setResourceCrn(CRN);
    credential.setDescription(DESCRIPTION);
    credential.setVerificationStatusText(VERIFICATION_STATUS_TEXT);
    credential.setType(CredentialType.ENVIRONMENT);
    credential.setGovCloud(true);
    CredentialViewResponse result = underTest.convertResponse(credential);
    assertEquals(CRED_NAME, result.getName());
    assertEquals(CLOUD_PLATFORM, result.getCloudPlatform());
    assertEquals(CREATOR, result.getCreator());
    assertEquals(CRN, result.getCrn());
    assertEquals(DESCRIPTION, result.getDescription());
    assertEquals(VERIFICATION_STATUS_TEXT, result.getVerificationStatusText());
    assertEquals(CredentialType.ENVIRONMENT, result.getType());
    assertTrue(result.getGovCloud());
}
Also used : CredentialViewResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialViewResponse) Credential(com.sequenceiq.environment.credential.domain.Credential) Test(org.junit.jupiter.api.Test)

Example 30 with Credential

use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.

the class AwsCredentialValidatorTest method testKeyBasedToRoleBased.

@Test
public void testKeyBasedToRoleBased() {
    Credential original = new Credential();
    ObjectNode rootOriginal = getAwsAttributes();
    putKeyBased(rootOriginal);
    original.setAttributes(rootOriginal.toString());
    Credential newCred = new Credential();
    ObjectNode rootNew = getAwsAttributes();
    putRoleBased(rootNew);
    newCred.setAttributes(rootNew.toString());
    ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
    ValidationResult result = awsCredentialValidator.validateUpdate(original, newCred, resultBuilder);
    assertEquals(1, result.getErrors().size());
    assertThat(result.getErrors().get(0), CoreMatchers.containsString("Cannot change AWS credential from key based to role based."));
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Aggregations

Credential (com.sequenceiq.environment.credential.domain.Credential)102 Test (org.junit.jupiter.api.Test)49 Environment (com.sequenceiq.environment.environment.domain.Environment)27 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)13 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)10 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)9 EnvironmentAuthentication (com.sequenceiq.environment.environment.domain.EnvironmentAuthentication)9 EnvironmentCreationDto (com.sequenceiq.environment.environment.dto.EnvironmentCreationDto)9 BadRequestException (javax.ws.rs.BadRequestException)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 CheckPermissionByAccount (com.sequenceiq.authorization.annotation.CheckPermissionByAccount)8 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)8 Set (java.util.Set)8 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)7 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)7 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)7 Map (java.util.Map)7 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)6 BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)6