use of uk.gov.ida.hub.policy.domain.LevelOfAssurance 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.domain.LevelOfAssurance in project verify-hub by alphagov.
the class LevelOfAssuranceValidatorTest method validate_shouldNotThrowExceptionIfLevelOfAssuranceFromMatchingServiceMatchesOneFromIdp.
@Test
public void validate_shouldNotThrowExceptionIfLevelOfAssuranceFromMatchingServiceMatchesOneFromIdp() throws Exception {
LevelOfAssurance levelOfAssurance = LevelOfAssurance.LEVEL_2;
levelOfAssuranceValidator.validate(Optional.fromNullable(levelOfAssurance), levelOfAssurance);
}
use of uk.gov.ida.hub.policy.domain.LevelOfAssurance in project verify-hub by alphagov.
the class LevelOfAssuranceValidatorTest method validate_shouldThrowExceptionIfLevelOfAssuranceFromMatchingServiceDoesNotExist.
@Test
public void validate_shouldThrowExceptionIfLevelOfAssuranceFromMatchingServiceDoesNotExist() throws Exception {
LevelOfAssurance levelOfAssurance = LevelOfAssurance.LEVEL_2;
try {
levelOfAssuranceValidator.validate(Optional.<LevelOfAssurance>absent(), levelOfAssurance);
fail("fail");
} catch (StateProcessingValidationException e) {
assertThat(e.getMessage()).isEqualTo(StateProcessingValidationException.noLevelOfAssurance().getMessage());
}
}
use of uk.gov.ida.hub.policy.domain.LevelOfAssurance in project verify-hub by alphagov.
the class SessionResourceIntegrationTest method shouldUpdateSessionStateAndSendAnAttributeQueryRequestWhenASuccessResponseIsReceivedFromIdp.
@Test
public void shouldUpdateSessionStateAndSendAnAttributeQueryRequestWhenASuccessResponseIsReceivedFromIdp() throws JsonProcessingException {
// Given
SessionId sessionId = SessionId.createNewSessionId();
Response sessionCreatedResponse = TestSessionResourceHelper.createSessionInIdpSelectedState(sessionId, rpEntityId, idpEntityId, client, policy.uri(UriBuilder.fromPath(TEST_SESSION_RESOURCE_PATH + IDP_SELECTED_STATE).build().toASCIIString()));
assertThat(sessionCreatedResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
LevelOfAssurance loaAchieved = LevelOfAssurance.LEVEL_2;
samlEngineStub.setupStubForIdpAuthnResponseTranslate(InboundResponseFromIdpDtoBuilder.successResponse(idpEntityId, loaAchieved));
samlEngineStub.setupStubForAttributeQueryRequest(anAttributeQueryContainerDto().build());
configStub.setUpStubForMatchingServiceRequest(idpEntityId, IdpSelectedStateBuilder.anIdpSelectedState().build().getMatchingServiceEntityId());
samlSoapProxyProxyStub.setUpStubForSendHubMatchingServiceRequest(sessionId);
// When
URI idpResponseUri = UriBuilder.fromPath(Urls.PolicyUrls.IDP_AUTHN_RESPONSE_RESOURCE).build(sessionId);
Response response = client.target(policy.uri(idpResponseUri.toASCIIString())).request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(aSamlAuthnResponseContainerDto().withSessionId(sessionId).build()));
// Then
ResponseAction expectedResult = ResponseAction.success(sessionId, true, loaAchieved);
assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
ResponseAction actualResult = response.readEntity(ResponseAction.class);
assertThat(actualResult).isEqualToComparingFieldByField(expectedResult);
assertThat(getSessionStateName(sessionId)).isEqualTo(Cycle0And1MatchRequestSentState.class.getName());
}
Aggregations