Search in sources :

Example 31 with Credential

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

the class AwsCredentialValidatorTest method testWithMissingAwsAttributes.

@Test
public void testWithMissingAwsAttributes() {
    Credential original = new Credential();
    ObjectNode rootOriginal = getAwsAttributes();
    putRoleBased(rootOriginal);
    original.setAttributes(rootOriginal.toString());
    Credential newCred = new Credential();
    newCred.setAttributes(objectMapper.createObjectNode().toString());
    ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
    ValidationResult result = awsCredentialValidator.validateUpdate(original, newCred, resultBuilder);
    assertEquals(1, result.getErrors().size());
    assertThat(result.getErrors().get(0), CoreMatchers.containsString("Missing attributes from the JSON!"));
}
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)

Example 32 with Credential

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

the class CredentialDeleteServiceTest method createCredentialWithName.

private Credential createCredentialWithName(String name) {
    Credential cred = new Credential();
    cred.setName(name);
    return cred;
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential)

Example 33 with Credential

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

the class CredentialDeleteServiceTest method testMultipleWhenEnvironmentStillUsesTheCredential2ThenBadRequestShouldComeOnSecondButTheFirstDeletionSuccess.

@Test
void testMultipleWhenEnvironmentStillUsesTheCredential2ThenBadRequestShouldComeOnSecondButTheFirstDeletionSuccess() {
    doNothing().when(ownerAssignmentService).notifyResourceDeleted(any(), any());
    String name1 = "something1";
    Credential cred1 = createCredentialWithName(name1);
    cred1.setId(1L);
    when(credentialService.findByNameAndAccountId(eq(name1), eq(ACCOUNT_ID), any(Set.class), any())).thenReturn(Optional.of(cred1));
    when(credentialService.save(any())).thenReturn(cred1);
    String name2 = "something2";
    Credential cred2 = createCredentialWithName(name2);
    cred2.setId(2L);
    when(credentialService.findByNameAndAccountId(eq(name2), eq(ACCOUNT_ID), any(Set.class), any())).thenThrow(new BadRequestException("anything can happen"));
    when(environmentViewService.findAllByCredentialId(cred1.getId())).thenReturn(Set.of());
    Set<Credential> result = underTest.deleteMultiple(Set.of(name1, name2), ACCOUNT_ID, ENVIRONMENT);
    verify(credentialService, times(2)).findByNameAndAccountId(anyString(), anyString(), anyCollection(), any());
    verify(environmentViewService, times(1)).findAllByCredentialId(anyLong());
    verify(environmentViewService, times(1)).findAllByCredentialId(cred1.getId());
    verify(credentialService, times(1)).save(any());
    verify(ownerAssignmentService, times(1)).notifyResourceDeleted(any(), any());
    assertTrue(result.size() == 1);
    assertTrue(result.iterator().next().getName().startsWith(name1));
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) Set(java.util.Set) BadRequestException(javax.ws.rs.BadRequestException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 34 with Credential

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

the class CredentialServiceTest method testUpdateByAccountIdModifyPlatformIsForbiddenAndAuditCredential.

@Test
void testUpdateByAccountIdModifyPlatformIsForbiddenAndAuditCredential() {
    Credential result = new Credential();
    result.setCloudPlatform("anotherplatform");
    when(repository.findByNameAndAccountId(eq(CREDENTIAL_NAME), eq(ACCOUNT_ID), anyCollection(), any())).thenReturn(Optional.of(result));
    when(credentialValidator.validateCredentialUpdate(any(), any(), any())).thenThrow(BadRequestException.class);
    assertThrows(BadRequestException.class, () -> credentialServiceUnderTest.updateByAccountId(CREDENTIAL, ACCOUNT_ID, AUDIT));
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 35 with Credential

use of com.sequenceiq.environment.credential.domain.Credential 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)

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