Search in sources :

Example 1 with IdpSelected

use of uk.gov.ida.hub.policy.domain.IdpSelected in project verify-hub by alphagov.

the class AuthnRequestFromTransactionHandlerTest method stateControllerInvokedFromSessionRepositoryForselectedIdp.

@Test
public void stateControllerInvokedFromSessionRepositoryForselectedIdp() {
    SessionId sessionId = new SessionId("aSessionId");
    IdpSelected idpSelected = new IdpSelected(IDP_ENTITY_ID, PRINCIPAL_IP_ADDRESS, REGISTERING, REQUESTED_LOA);
    IdpSelectingStateControllerSpy idpSelectingStateController = new IdpSelectingStateControllerSpy();
    when(sessionRepository.getStateController(sessionId, IdpSelectingState.class)).thenReturn((idpSelectingStateController));
    authnRequestFromTransactionHandler.selectIdpForGivenSessionId(sessionId, idpSelected);
    assertThat(idpSelectingStateController.idpEntityId()).isEqualTo(IDP_ENTITY_ID);
    assertThat(idpSelectingStateController.principalIpAddress()).isEqualTo(PRINCIPAL_IP_ADDRESS);
    assertThat(idpSelectingStateController.registering()).isEqualTo(REGISTERING);
    assertThat(idpSelectingStateController.getRequestedLoa()).isEqualTo(REQUESTED_LOA);
}
Also used : IdpSelected(uk.gov.ida.hub.policy.domain.IdpSelected) SessionId(uk.gov.ida.hub.policy.domain.SessionId) Test(org.junit.Test)

Example 2 with IdpSelected

use of uk.gov.ida.hub.policy.domain.IdpSelected in project verify-hub by alphagov.

the class AuthnRequestFromTransactionResourceIntegrationTest method badEntityResponseThrown_WhenMandatoryFieldsAreMissing.

@Test
public void badEntityResponseThrown_WhenMandatoryFieldsAreMissing() throws Exception {
    sessionId = aSessionIsCreated();
    Response response = postIdpSelected(new IdpSelected(null, null, null, null));
    assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_UNPROCESSABLE_ENTITY);
    ValidationErrorMessage msg = response.readEntity(ValidationErrorMessage.class);
    assertThat(msg.getErrors()).contains("selectedIdpEntityId may not be empty");
    assertThat(msg.getErrors()).contains("principalIpAddress may not be empty");
    assertThat(msg.getErrors()).contains("registration may not be null");
    assertThat(msg.getErrors()).contains("requestedLoa may not be null");
}
Also used : Response(javax.ws.rs.core.Response) IdpSelected(uk.gov.ida.hub.policy.domain.IdpSelected) ValidationErrorMessage(io.dropwizard.jersey.validation.ValidationErrorMessage) Test(org.junit.Test)

Example 3 with IdpSelected

use of uk.gov.ida.hub.policy.domain.IdpSelected in project verify-hub by alphagov.

the class AuthnRequestFromTransactionResourceIntegrationTest method idpSelected_shouldThrowIfIdpIsNotAvailable.

@Test
public void idpSelected_shouldThrowIfIdpIsNotAvailable() throws JsonProcessingException {
    sessionId = aSessionIsCreated();
    IdpSelected idpSelected = new IdpSelected("does-not-exist", principalIpAddress, REGISTERING, LEVEL_2);
    Response response = postIdpSelected(idpSelected);
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto error = response.readEntity(ErrorStatusDto.class);
    assertThat(error.getExceptionType()).isEqualTo(ExceptionType.STATE_PROCESSING_VALIDATION);
}
Also used : Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) IdpSelected(uk.gov.ida.hub.policy.domain.IdpSelected) Test(org.junit.Test)

Example 4 with IdpSelected

use of uk.gov.ida.hub.policy.domain.IdpSelected in project verify-hub by alphagov.

the class AuthnRequestFromTransactionResourceIntegrationTest method selectIdp_shouldReturnSuccessResponseAndAudit.

@Test
public void selectIdp_shouldReturnSuccessResponseAndAudit() throws JsonProcessingException {
    sessionId = aSessionIsCreated();
    Response response = postIdpSelected(new IdpSelected(idpEntityId, principalIpAddress, REGISTERING, LEVEL_2));
    assertThat(response.getStatus()).isEqualTo(Response.Status.CREATED.getStatusCode());
    // one session started event, one idp selected event
    assertThat(eventSinkStub.getRecordedRequest()).hasSize(2);
    String recordedEvent = eventSinkStub.getLastRequest().getEntity();
    assertThat(recordedEvent).contains(sessionId.getSessionId());
    assertThat(recordedEvent).contains(principalIpAddress);
    assertThat(recordedEvent).contains(EventSinkHubEventConstants.SessionEvents.IDP_SELECTED);
    assertThat(recordedEvent).contains(samlResponse.getId());
}
Also used : Response(javax.ws.rs.core.Response) IdpSelected(uk.gov.ida.hub.policy.domain.IdpSelected) Test(org.junit.Test)

Example 5 with IdpSelected

use of uk.gov.ida.hub.policy.domain.IdpSelected in project verify-hub by alphagov.

the class SessionResourceIntegrationTest method anIdpIsSelectedForSignIn.

private void anIdpIsSelectedForSignIn(SessionId sessionId, String idpEntityId) {
    final URI policyUri = policy.uri(UriBuilder.fromPath(Urls.PolicyUrls.AUTHN_REQUEST_SELECT_IDP_RESOURCE).build(sessionId).getPath());
    client.target(policyUri).request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(new IdpSelected(idpEntityId, "this-is-an-ip-address", SIGNING_IN, REQUESTED_LOA)));
}
Also used : IdpSelected(uk.gov.ida.hub.policy.domain.IdpSelected) URI(java.net.URI)

Aggregations

IdpSelected (uk.gov.ida.hub.policy.domain.IdpSelected)11 Test (org.junit.Test)7 URI (java.net.URI)6 Response (javax.ws.rs.core.Response)4 SessionId (uk.gov.ida.hub.policy.domain.SessionId)3 ErrorStatusDto (uk.gov.ida.common.ErrorStatusDto)2 ValidationErrorMessage (io.dropwizard.jersey.validation.ValidationErrorMessage)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1