Search in sources :

Example 6 with LevelOfAssurance

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);
}
Also used : LevelOfAssurance(uk.gov.ida.hub.policy.domain.LevelOfAssurance) SuccessFromIdp(uk.gov.ida.hub.policy.domain.SuccessFromIdp) AttributeQueryContainerDto(uk.gov.ida.hub.policy.contracts.AttributeQueryContainerDto) InboundResponseFromIdpDto(uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.policy.contracts.SamlAuthnResponseTranslatorDto) AttributeQueryRequestDto(uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto) ResponseAction(uk.gov.ida.hub.policy.domain.ResponseAction) Test(org.junit.Test)

Example 7 with LevelOfAssurance

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);
}
Also used : LevelOfAssurance(uk.gov.ida.hub.policy.domain.LevelOfAssurance) Test(org.junit.Test)

Example 8 with 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());
    }
}
Also used : LevelOfAssurance(uk.gov.ida.hub.policy.domain.LevelOfAssurance) StateProcessingValidationException(uk.gov.ida.hub.policy.domain.exception.StateProcessingValidationException) Test(org.junit.Test)

Example 9 with LevelOfAssurance

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());
}
Also used : Response(javax.ws.rs.core.Response) LevelOfAssurance(uk.gov.ida.hub.policy.domain.LevelOfAssurance) Cycle0And1MatchRequestSentState(uk.gov.ida.hub.policy.domain.state.Cycle0And1MatchRequestSentState) SessionId(uk.gov.ida.hub.policy.domain.SessionId) URI(java.net.URI) ResponseAction(uk.gov.ida.hub.policy.domain.ResponseAction) Test(org.junit.Test)

Aggregations

LevelOfAssurance (uk.gov.ida.hub.policy.domain.LevelOfAssurance)9 Test (org.junit.Test)6 ResponseAction (uk.gov.ida.hub.policy.domain.ResponseAction)3 SessionId (uk.gov.ida.hub.policy.domain.SessionId)3 Response (javax.ws.rs.core.Response)2 AttributeQueryRequestDto (uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto)2 SamlAuthnResponseTranslatorDto (uk.gov.ida.hub.policy.contracts.SamlAuthnResponseTranslatorDto)2 SuccessFromIdp (uk.gov.ida.hub.policy.domain.SuccessFromIdp)2 URI (java.net.URI)1 DateTime (org.joda.time.DateTime)1 Duration (org.joda.time.Duration)1 AttributeQueryContainerDto (uk.gov.ida.hub.policy.contracts.AttributeQueryContainerDto)1 IdpConfigDto (uk.gov.ida.hub.policy.domain.IdpConfigDto)1 InboundResponseFromIdpDto (uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto)1 PersistentId (uk.gov.ida.hub.policy.domain.PersistentId)1 SessionId.createNewSessionId (uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId)1 StateProcessingValidationException (uk.gov.ida.hub.policy.domain.exception.StateProcessingValidationException)1 Cycle0And1MatchRequestSentState (uk.gov.ida.hub.policy.domain.state.Cycle0And1MatchRequestSentState)1 IdpSelectedState (uk.gov.ida.hub.policy.domain.state.IdpSelectedState)1 SessionStartedState (uk.gov.ida.hub.policy.domain.state.SessionStartedState)1