use of uk.gov.ida.hub.samlengine.contracts.SamlAuthnResponseTranslatorDto in project verify-hub by alphagov.
the class IdpAuthnResponseTranslatorResourceTest method handleResponseFromIdp_shouldThrowExceptionForSecondIdpIfTwoIdpsSubmitAnAuthnStatementAssertionWithTheSameId.
@Test
public void handleResponseFromIdp_shouldThrowExceptionForSecondIdpIfTwoIdpsSubmitAnAuthnStatementAssertionWithTheSameId() throws Exception {
String authnStatementAssertionId = "authnStatementAssertionId" + UUID.randomUUID().toString();
String mdsStatementAssertionId = "mdsStatementAssertionId" + UUID.randomUUID().toString();
SamlAuthnResponseTranslatorDto samlResponseDto_1 = getSuccessSamlAuthnResponseTranslatorDto(STUB_IDP_TWO, authnStatementAssertionId, mdsStatementAssertionId + "-1");
SamlAuthnResponseTranslatorDto samlResponseDto_2 = getSuccessSamlAuthnResponseTranslatorDto(STUB_IDP_THREE, authnStatementAssertionId, mdsStatementAssertionId + "-2");
Response clientResponse = postToSamlEngine(samlResponseDto_1);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
clientResponse = postToSamlEngine(samlResponseDto_2);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
ErrorStatusDto errorStatusDto = clientResponse.readEntity(ErrorStatusDto.class);
assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
use of uk.gov.ida.hub.samlengine.contracts.SamlAuthnResponseTranslatorDto in project verify-hub by alphagov.
the class IdpAuthnResponseTranslatorResourceTest method handleResponseFromIdp_shouldThrowExceptionIfmdsAssertionIsReplayedInResponseFromIdp.
@Test
public void handleResponseFromIdp_shouldThrowExceptionIfmdsAssertionIsReplayedInResponseFromIdp() throws Exception {
String authnStatementAssertionId = "authnStatementAssertionId" + UUID.randomUUID().toString();
String mdsStatementAssertionId = "mdsStatementAssertionId" + UUID.randomUUID().toString();
SamlAuthnResponseTranslatorDto samlResponseDto_1 = getSuccessSamlAuthnResponseTranslatorDto(STUB_IDP_ONE, authnStatementAssertionId + "-1", mdsStatementAssertionId);
SamlAuthnResponseTranslatorDto samlResponseDto_2 = getSuccessSamlAuthnResponseTranslatorDto(STUB_IDP_ONE, authnStatementAssertionId + "-2", mdsStatementAssertionId);
Response clientResponse = postToSamlEngine(samlResponseDto_1);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
clientResponse = postToSamlEngine(samlResponseDto_2);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
ErrorStatusDto errorStatusDto = clientResponse.readEntity(ErrorStatusDto.class);
assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
use of uk.gov.ida.hub.samlengine.contracts.SamlAuthnResponseTranslatorDto in project verify-hub by alphagov.
the class IdpAuthnResponseTranslatorResourceTest method handleResponseFromIdp_shouldDecryptAssertionEncryptedWithPrimaryEncryptionCertificates.
@Test
public void handleResponseFromIdp_shouldDecryptAssertionEncryptedWithPrimaryEncryptionCertificates() throws Exception {
BasicCredential primaryEncryptionKey = new BasicCredential(new HardCodedKeyStore(HUB_ENTITY_ID).getPrimaryEncryptionKeyForEntity(HUB_ENTITY_ID));
SamlAuthnResponseTranslatorDto samlResponseDto = getSuccessSamlAuthnResponseTranslatorDto(primaryEncryptionKey);
Response clientResponse = postToSamlEngine(samlResponseDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
}
use of uk.gov.ida.hub.samlengine.contracts.SamlAuthnResponseTranslatorDto in project verify-hub by alphagov.
the class IdpAuthnResponseTranslatorResourceTest method shouldFailWhenASuccessIdpAuthnResponseDoesNotContainAnIpAddressAsSeenByIdp.
@Test
public void shouldFailWhenASuccessIdpAuthnResponseDoesNotContainAnIpAddressAsSeenByIdp() throws Exception {
final String ipAddressAsSeenByIdp = null;
final org.opensaml.saml.saml2.core.Response samlAuthnResponse = authnResponseFactory.aResponseFromIdpBuilder(STUB_IDP_ONE, ipAddressAsSeenByIdp).withDestination(IDP_RESPONSE_ENDPOINT).build();
String saml = authnResponseFactory.transformResponseToSaml(samlAuthnResponse);
SamlAuthnResponseTranslatorDto samlResponseDto = aSamlAuthnResponseTranslatorDto().withMatchingServiceEntityId(TEST_RP_MS).withSamlResponse(saml).build();
Response clientResponse = postToSamlEngine(samlResponseDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
ErrorStatusDto errorStatusDto = clientResponse.readEntity(ErrorStatusDto.class);
assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
use of uk.gov.ida.hub.samlengine.contracts.SamlAuthnResponseTranslatorDto in project verify-hub by alphagov.
the class IdpAuthnResponseTranslatorResourceTest method shouldThrowExceptionIfResponseContainsMdsAssertionInResponseToValuesNotMatchingRequestId.
@Test
public void shouldThrowExceptionIfResponseContainsMdsAssertionInResponseToValuesNotMatchingRequestId() throws Exception {
final org.opensaml.saml.saml2.core.Response samlAuthnResponse = authnResponseFactory.aResponseFromIdpBuilderWithInResponseToValues(STUB_IDP_ONE, "default-request-id", "default-request-id", "other-request-id").withDestination("http://localhost" + Urls.FrontendUrls.SAML2_SSO_RESPONSE_ENDPOINT).build();
String saml = authnResponseFactory.transformResponseToSaml(samlAuthnResponse);
SamlAuthnResponseTranslatorDto samlResponseDto = aSamlAuthnResponseTranslatorDto().withSamlResponse(saml).withMatchingServiceEntityId(TEST_RP_MS).build();
Response clientResponse = postToSamlEngine(samlResponseDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
ErrorStatusDto errorStatusDto = clientResponse.readEntity(ErrorStatusDto.class);
assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
Aggregations