use of com.sequenceiq.cloudbreak.common.json.Json 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.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class CredentialDefinitionServiceTest method testSensitiveRemoved.
@Test
public void testSensitiveRemoved() throws JsonProcessingException {
when(resourceDefinitionService.getResourceDefinition(anyString(), anyString())).thenReturn(JsonUtil.writeValueAsString(DEFINITION_SENSITIVE2));
Json json = new Json("{\"alma\":\"barack\",\"szilva\":\"sensitivevalue\"}");
assertDoesNotThrow(executeCheckProperties(json));
assertEquals(1, json.getMap().size());
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class CredentialServiceTest method testAuthorizeCodeGrantFlowFoundStateMatches.
@Test
void testAuthorizeCodeGrantFlowFoundStateMatches() throws IOException {
when(repository.save(any())).thenReturn(CREDENTIAL);
when(repository.findAllByAccountId(eq(ACCOUNT_ID), anyCollection(), any())).thenReturn(Set.of(CREDENTIAL));
when(credentialAdapter.verify(any(), anyString())).thenAnswer(i -> new CredentialVerification(i.getArgument(0), true));
Credential result = credentialServiceUnderTest.authorizeCodeGrantFlow(DIFFERENT_CODE, STATE, ACCOUNT_ID, "platform");
CredentialAttributes resultAttributes = new Json(result.getAttributes()).get(CredentialAttributes.class);
assertEquals(DIFFERENT_CODE, resultAttributes.getAzure().getCodeGrantFlowBased().getAuthorizationCode());
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class DBStackToDatabaseStackConverterTest method testConversionAzureWithMultipleResourceGroups.
@Test
public void testConversionAzureWithMultipleResourceGroups() {
Network network = new Network();
network.setAttributes(new Json(NETWORK_ATTRIBUTES));
dbStack.setNetwork(network);
dbStack.setCloudPlatform(CLOUD_PLATFORM);
dbStack.setParameters(new HashMap<>());
DatabaseServer server = new DatabaseServer();
server.setDatabaseVendor(DatabaseVendor.POSTGRES);
server.setAttributes(new Json(DATABASE_SERVER_ATTRIBUTES));
dbStack.setDatabaseServer(server);
dbStack.setTags(new Json(STACK_TAGS));
dbStack.setTemplate("template");
DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
environmentResponse.setCloudPlatform(CLOUD_PLATFORM);
environmentResponse.setAzure(AzureEnvironmentParameters.builder().withAzureResourceGroup(AzureResourceGroup.builder().withResourceGroupUsage(ResourceGroupUsage.MULTIPLE).build()).build());
when(environmentService.getByCrn(anyString())).thenReturn(environmentResponse);
DatabaseStack convertedStack = underTest.convert(dbStack);
Map<String, Object> parameters = convertedStack.getDatabaseServer().getParameters();
assertThat(parameters.containsKey(RESOURCE_GROUP_NAME_PARAMETER)).isFalse();
assertThat(parameters.containsKey(RESOURCE_GROUP_USAGE_PARAMETER)).isFalse();
assertThat(parameters.size()).isEqualTo(2);
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class DBStackToDatabaseStackConverterTest method testConversionAzureWithAzureEncryptionResourcesPresentAndSingleResourceGroup.
@Test
public void testConversionAzureWithAzureEncryptionResourcesPresentAndSingleResourceGroup() {
Network network = new Network();
network.setAttributes(new Json(NETWORK_ATTRIBUTES));
dbStack.setNetwork(network);
dbStack.setCloudPlatform(CLOUD_PLATFORM);
dbStack.setParameters(new HashMap<>());
DatabaseServer server = new DatabaseServer();
server.setDatabaseVendor(DatabaseVendor.POSTGRES);
server.setAttributes(new Json(DATABASE_SERVER_ATTRIBUTES));
dbStack.setDatabaseServer(server);
dbStack.setTags(new Json(STACK_TAGS));
dbStack.setTemplate("template");
DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
environmentResponse.setCloudPlatform(CLOUD_PLATFORM);
environmentResponse.setAzure(AzureEnvironmentParameters.builder().withAzureResourceGroup(AzureResourceGroup.builder().withResourceGroupUsage(ResourceGroupUsage.SINGLE).withName(RESOURCE_GROUP).build()).withResourceEncryptionParameters(AzureResourceEncryptionParameters.builder().withEncryptionKeyUrl(KEY_URL).withEncryptionKeyResourceGroupName(RESOURCE_GROUP).build()).build());
when(environmentService.getByCrn(anyString())).thenReturn(environmentResponse);
DatabaseStack convertedStack = underTest.convert(dbStack);
Map<String, Object> parameters = convertedStack.getDatabaseServer().getParameters();
assertThat(parameters.get(RESOURCE_GROUP_NAME_PARAMETER).toString()).isEqualTo(RESOURCE_GROUP);
assertThat(parameters.get(RESOURCE_GROUP_USAGE_PARAMETER).toString()).isEqualTo(ResourceGroupUsage.SINGLE.name());
assertThat(parameters.get(ENCRYPTION_KEY_URL).toString()).isEqualTo(KEY_URL);
assertThat(parameters.get(ENCRYPTION_KEY_RESOURCE_GROUP_NAME).toString()).isEqualTo(RESOURCE_GROUP);
assertThat(parameters.size()).isEqualTo(6);
}
Aggregations