use of uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto in project verify-hub by alphagov.
the class AttributeQueryServiceTest method shouldPropagateExceptionThrownBySamlEngineAndNotSendAttributeQuery.
@Test(expected = ApplicationException.class)
public void shouldPropagateExceptionThrownBySamlEngineAndNotSendAttributeQuery() throws Exception {
// Given
boolean isRegistration = true;
stub(idpSelectedStateController.isRegistrationContext()).toReturn(isRegistration);
AttributeQueryRequestDto attributeQueryRequestDto = AttributeQueryRequestBuilder.anAttributeQueryRequest().build();
stub(samlEngineProxy.generateAttributeQuery(attributeQueryRequestDto)).toThrow(ApplicationException.createAuditedException(INVALID_SAML, UUID.randomUUID()));
// When
service.sendAttributeQueryRequest(sessionId, attributeQueryRequestDto);
// Then
verify(samlEngineProxy, times(1)).generateAttributeQuery(attributeQueryRequestDto);
verify(samlSoapProxyProxy, times(0)).sendHubMatchingServiceRequest(eq(sessionId), Matchers.<AttributeQueryRequest>any());
}
use of uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto in project verify-hub by alphagov.
the class AuthnResponseFromIdpServiceTest method shouldSendRequestToMatchingServiceViaAttributeQueryServiceAndUpdateSessionStateWhenSuccessfulResponseIsReceived.
@Test
public void shouldSendRequestToMatchingServiceViaAttributeQueryServiceAndUpdateSessionStateWhenSuccessfulResponseIsReceived() {
// Given
final String msaEntityId = "a-msa-entity-id";
LevelOfAssurance loaAchieved = LevelOfAssurance.LEVEL_2;
stub(idpSelectedStateController.isRegistrationContext()).toReturn(REGISTERING);
when(idpSelectedStateController.getMatchingServiceEntityId()).thenReturn(msaEntityId);
InboundResponseFromIdpDto successResponseFromIdp = InboundResponseFromIdpDtoBuilder.successResponse(UUID.randomUUID().toString(), loaAchieved);
SamlAuthnResponseTranslatorDto samlAuthnResponseTranslatorDto = SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto().build();
when(samlAuthnResponseTranslatorDtoFactory.fromSamlAuthnResponseContainerDto(samlAuthnResponseContainerDto, msaEntityId)).thenReturn(samlAuthnResponseTranslatorDto);
stub(samlEngineProxy.translateAuthnResponseFromIdp(any(SamlAuthnResponseTranslatorDto.class))).toReturn(successResponseFromIdp);
AttributeQueryRequestDto attributeQueryRequestDto = AttributeQueryRequestBuilder.anAttributeQueryRequest().build();
stub(idpSelectedStateController.createAttributeQuery(any(SuccessFromIdp.class))).toReturn(attributeQueryRequestDto);
AttributeQueryContainerDto msaRequest = AttributeQueryContainerDtoBuilder.anAttributeQueryContainerDto().build();
stub(samlEngineProxy.generateAttributeQuery(attributeQueryRequestDto)).toReturn(msaRequest);
// When
ResponseAction responseAction = service.receiveAuthnResponseFromIdp(sessionId, samlAuthnResponseContainerDto);
// Then
verify(samlAuthnResponseTranslatorDtoFactory).fromSamlAuthnResponseContainerDto(samlAuthnResponseContainerDto, msaEntityId);
verify(attributeQueryService).sendAttributeQueryRequest(sessionId, attributeQueryRequestDto);
verifyIdpStateControllerIsCalledWithRightDataOnSuccess(successResponseFromIdp);
ResponseAction expectedResponseAction = ResponseAction.success(sessionId, REGISTERING, loaAchieved);
assertThat(responseAction).isEqualToComparingFieldByField(expectedResponseAction);
}
use of uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto in project verify-hub by alphagov.
the class Cycle0And1MatchRequestSentStateControllerTest method getNextState_shouldReturnUserAccountCreationRequestSentStateWhenTransactionDoesNotSupportCycle3AndSupportsUserAccountCreation.
@Test
public void getNextState_shouldReturnUserAccountCreationRequestSentStateWhenTransactionDoesNotSupportCycle3AndSupportsUserAccountCreation() {
// Given
URI userAccountCreationUri = URI.create("a-test-user-account-creation-uri");
List<UserAccountCreationAttribute> userAccountCreationAttributes = singletonList(UserAccountCreationAttribute.DATE_OF_BIRTH);
when(transactionsConfigProxy.getMatchingProcess(TRANSACTION_ENTITY_ID)).thenReturn(new MatchingProcess(Optional.absent()));
when(transactionsConfigProxy.getUserAccountCreationAttributes(TRANSACTION_ENTITY_ID)).thenReturn(userAccountCreationAttributes);
when(matchingServiceConfigProxy.getMatchingService(anyString())).thenReturn(aMatchingServiceConfigEntityDataDto().withUserAccountCreationUri(userAccountCreationUri).build());
// When
final State nextState = controller.getNextStateForNoMatch();
// Then
verify(hubEventLogger).logMatchingServiceUserAccountCreationRequestSentEvent(state.getSessionId(), TRANSACTION_ENTITY_ID, state.getSessionExpiryTimestamp(), state.getRequestId());
verify(attributeQueryService).sendAttributeQueryRequest(eq(nextState.getSessionId()), attributeQueryRequestCaptor.capture());
AttributeQueryRequestDto actualAttributeQueryRequestDto = attributeQueryRequestCaptor.getValue();
assertThat(actualAttributeQueryRequestDto.getAttributeQueryUri()).isEqualTo(userAccountCreationUri);
assertThat(actualAttributeQueryRequestDto.getUserAccountCreationAttributes()).isEqualTo(Optional.fromNullable(userAccountCreationAttributes));
assertThat(nextState).isInstanceOf(UserAccountCreationRequestSentState.class);
}
use of uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto in project verify-hub by alphagov.
the class Cycle3MatchRequestSentStateControllerTest method getNextStateForNoMatch_shouldReturnUserAccountCreationRequestSentStateWhenAttributesArePresent.
@Test
public void getNextStateForNoMatch_shouldReturnUserAccountCreationRequestSentStateWhenAttributesArePresent() {
// Given
URI userAccountCreationUri = URI.create("a-test-user-account-creation-uri");
Cycle3MatchRequestSentState state = aCycle3MatchRequestSentState().build();
ImmutableList<UserAccountCreationAttribute> userAccountCreationAttributes = ImmutableList.of(UserAccountCreationAttribute.DATE_OF_BIRTH);
String transactionEntityId = "request issuer id";
when(transactionsConfigProxy.getUserAccountCreationAttributes(transactionEntityId)).thenReturn(userAccountCreationAttributes);
when(matchingServiceConfigProxy.getMatchingService(anyString())).thenReturn(aMatchingServiceConfigEntityDataDto().withUserAccountCreationUri(userAccountCreationUri).build());
Cycle3MatchRequestSentStateController controller = new Cycle3MatchRequestSentStateController(state, hubEventLogger, null, policyConfiguration, null, null, transactionsConfigProxy, matchingServiceConfigProxy, assertionRestrictionFactory, attributeQueryService);
// When
State nextState = controller.getNextStateForNoMatch();
// Then
ArgumentCaptor<EventSinkHubEvent> eventSinkArgumentCaptor = ArgumentCaptor.forClass(EventSinkHubEvent.class);
verify(eventSinkProxy, times(1)).logHubEvent(eventSinkArgumentCaptor.capture());
assertThat(eventSinkArgumentCaptor.getValue().getEventType()).isEqualTo(EventSinkHubEventConstants.EventTypes.SESSION_EVENT);
assertThat(eventSinkArgumentCaptor.getValue().getDetails().get(EventDetailsKey.session_event_type)).isEqualTo(USER_ACCOUNT_CREATION_REQUEST_SENT);
assertThat(eventSinkArgumentCaptor.getValue().getSessionId()).isEqualTo(state.getSessionId().toString());
assertThat(eventSinkArgumentCaptor.getValue().getDetails().get(EventDetailsKey.request_id)).isEqualTo(state.getRequestId());
assertThat(eventSinkArgumentCaptor.getValue().getOriginatingService()).isEqualTo(serviceInfo.getName());
verify(attributeQueryService).sendAttributeQueryRequest(eq(nextState.getSessionId()), attributeQueryRequestCaptor.capture());
AttributeQueryRequestDto actualAttributeQueryRequestDto = attributeQueryRequestCaptor.getValue();
assertThat(actualAttributeQueryRequestDto.getAttributeQueryUri()).isEqualTo(userAccountCreationUri);
assertThat(actualAttributeQueryRequestDto.getUserAccountCreationAttributes()).isEqualTo(Optional.fromNullable(userAccountCreationAttributes));
assertThat(actualAttributeQueryRequestDto.getEncryptedMatchingDatasetAssertion()).isEqualTo(state.getEncryptedMatchingDatasetAssertion());
assertThat(nextState).isInstanceOf(UserAccountCreationRequestSentState.class);
}
Aggregations