use of uk.gov.ida.hub.policy.domain.SessionId in project verify-hub by alphagov.
the class RpErrorResponseFromHubIntegrationTest method shouldReturnErrorStatusCodeWhenCallToSamlEngineGoesAwry.
@Test
public void shouldReturnErrorStatusCodeWhenCallToSamlEngineGoesAwry() throws Exception {
final SessionId sessionId = aSessionIsCreated();
samlEngineStub.setUpStubForErrorResponseGenerateErrorOccurring();
URI uri = UriBuilder.fromPath(Urls.PolicyUrls.RP_ERROR_RESPONSE_RESOURCE).build(sessionId.getSessionId());
Response response = get(uri);
assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
ErrorStatusDto errorStatusDto = response.readEntity(ErrorStatusDto.class);
assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_INPUT);
}
use of uk.gov.ida.hub.policy.domain.SessionId in project verify-hub by alphagov.
the class SessionResourceIntegrationTest method shouldReturnOkWhenGeneratingIdpAuthnRequestFromHubIsSuccessfulOnSignIn.
@Test
public void shouldReturnOkWhenGeneratingIdpAuthnRequestFromHubIsSuccessfulOnSignIn() throws Exception {
// Given
final SamlRequestDto samlRequestDto = new SamlRequestDto("coffee-pasta", idpSsoUri);
samlEngineStub.setupStubForIdpAuthnRequestGenerate(samlRequestDto);
configStub.setupStubForEnabledIdps(rpEntityId, false, REQUESTED_LOA, singletonList(idpEntityId));
SessionId sessionId = aSessionIsCreated();
anIdpIsSelectedForSignIn(sessionId, idpEntityId);
final AuthnRequestFromHubContainerDto expectedResult = anAuthnRequestFromHubContainerDtoWithRegistering(samlRequestDto, false);
// When
AuthnRequestFromHubContainerDto result = getEntity(UriBuilder.fromPath(Urls.PolicyUrls.IDP_AUTHN_REQUEST_RESOURCE).build(sessionId), AuthnRequestFromHubContainerDto.class);
// Then
assertThat(result).isEqualToComparingFieldByField(expectedResult);
IdpSelectedState sessionState = policy.getSessionState(sessionId, IdpSelectedState.class);
assertThat(sessionState.getMatchingServiceEntityId()).isEqualTo(msEntityId);
}
use of uk.gov.ida.hub.policy.domain.SessionId in project verify-hub by alphagov.
the class SessionResourceIntegrationTest method shouldGetRpResponseGivenASessionInEidasSuccessfulMatchStateExists.
@Test
public void shouldGetRpResponseGivenASessionInEidasSuccessfulMatchStateExists() throws JsonProcessingException {
SessionId sessionId = SessionId.createNewSessionId();
Response sessionCreatedResponse = TestSessionResourceHelper.createSessionInEidasSuccessfulMatchState(sessionId, rpEntityId, countryEntityId, client, policy.uri(UriBuilder.fromPath(TEST_SESSION_RESOURCE_PATH + EIDAS_SUCCESSFUL_MATCH_STATE).build().toASCIIString()));
assertThat(sessionCreatedResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
AuthnResponseFromHubContainerDto expectedAuthnResponseFromHub = anAuthnResponseFromHubContainerDto().build();
samlEngineStub.setUpStubForAuthnResponseGenerate(expectedAuthnResponseFromHub);
URI rpAuthResponseUri = UriBuilder.fromPath(Urls.PolicyUrls.RP_AUTHN_RESPONSE_RESOURCE).build(sessionId);
Response responseForRp = client.target(policy.uri(rpAuthResponseUri.toASCIIString())).request().get();
assertThat(responseForRp.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
AuthnResponseFromHubContainerDto authnResponseFromHub = responseForRp.readEntity(AuthnResponseFromHubContainerDto.class);
assertThat(authnResponseFromHub).isEqualToComparingFieldByField(expectedAuthnResponseFromHub);
}
use of uk.gov.ida.hub.policy.domain.SessionId in project verify-hub by alphagov.
the class SessionResourceIntegrationTest method shouldCreateSession.
@Test
public void shouldCreateSession() throws Exception {
configStub.setUpStubForAssertionConsumerServiceUri(rpEntityId);
samlEngineStub.setupStubForAuthnRequestTranslate(translatedAuthnRequest);
Response responseFromPost = createASession(rpSamlRequest);
assertThat(responseFromPost.getStatus()).isEqualTo(Response.Status.CREATED.getStatusCode());
final SessionId postSessionId = responseFromPost.readEntity(SessionId.class);
URI getUri = UriBuilder.fromUri(Urls.PolicyUrls.SESSION_RESOURCE_ROOT).path(Urls.SharedUrls.SESSION_ID_PARAM_PATH).build(postSessionId);
final SessionId getSessionId = getEntity(getUri, SessionId.class);
assertThat(postSessionId).isEqualTo(getSessionId);
assertThat(eventSinkStub.getRecordedRequest()).hasSize(1);
String eventSinkEntity = eventSinkStub.getRecordedRequest().get(0).getEntity();
assertThat(eventSinkEntity).contains(postSessionId.getSessionId());
assertThat(eventSinkEntity).contains(EventSinkHubEventConstants.SessionEvents.SESSION_STARTED);
assertThat(eventSinkEntity).contains(rpSamlRequest.getPrincipalIPAddressAsSeenByHub());
}
use of uk.gov.ida.hub.policy.domain.SessionId in project verify-hub by alphagov.
the class SessionResourceIntegrationTest method shouldReturnNotFoundWhenSessionDoesNotExistInPolicy.
@Test
public void shouldReturnNotFoundWhenSessionDoesNotExistInPolicy() throws Exception {
// Given
SessionId sessionId = aSessionIsCreated();
anIdpIsSelectedForSignIn(sessionId, idpEntityId);
// When
Response response = get(UriBuilder.fromPath(Urls.PolicyUrls.IDP_AUTHN_REQUEST_RESOURCE).build("this-session-totally-does-not-exist"));
// Then
checkException(response, ExceptionType.SESSION_NOT_FOUND);
}
Aggregations