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;
}
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);
}
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());
}
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());
}
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."));
}
Aggregations