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