Search in sources :

Example 76 with Json

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);
}
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 77 with Json

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());
}
Also used : Json(com.sequenceiq.cloudbreak.common.json.Json) Test(org.junit.jupiter.api.Test)

Example 78 with Json

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());
}
Also used : AzureCredentialAttributes(com.sequenceiq.environment.credential.attributes.azure.AzureCredentialAttributes) CredentialAttributes(com.sequenceiq.environment.credential.attributes.CredentialAttributes) Credential(com.sequenceiq.environment.credential.domain.Credential) CredentialVerification(com.sequenceiq.environment.credential.verification.CredentialVerification) Json(com.sequenceiq.cloudbreak.common.json.Json) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 79 with Json

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);
}
Also used : Network(com.sequenceiq.redbeams.domain.stack.Network) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) DatabaseServer(com.sequenceiq.redbeams.domain.stack.DatabaseServer) Json(com.sequenceiq.cloudbreak.common.json.Json) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 80 with Json

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);
}
Also used : Network(com.sequenceiq.redbeams.domain.stack.Network) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) DatabaseServer(com.sequenceiq.redbeams.domain.stack.DatabaseServer) Json(com.sequenceiq.cloudbreak.common.json.Json) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

Json (com.sequenceiq.cloudbreak.common.json.Json)266 Test (org.junit.jupiter.api.Test)95 HashMap (java.util.HashMap)49 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)31 Template (com.sequenceiq.freeipa.entity.Template)26 AwsInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate)25 List (java.util.List)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)24 AzureInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate)23 Map (java.util.Map)22 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)21 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)21 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)21 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)20 IOException (java.io.IOException)20 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)18 RestRequestDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails)16 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)16 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)14