use of uk.gov.ida.hub.samlengine.contracts.ResponseFromHubDto in project verify-hub by alphagov.
the class RpAuthnResponseGeneratorResourceTest method shouldReturnAnErrorResponseGivenBadInput.
@Test
public void shouldReturnAnErrorResponseGivenBadInput() throws JsonProcessingException {
ResponseFromHubDto responseFromHubDto = aResponseFromHubDto().withAssertionConsumerServiceUri(null).build();
configStub.signResponsesAndUseSamlStandard(responseFromHubDto.getAuthnRequestIssuerEntityId());
URI generateAuthnResponseEndpoint = samlEngineAppRule.getUri(Urls.SamlEngineUrls.GENERATE_RP_AUTHN_RESPONSE_RESOURCE);
Response rpAuthnResponse = client.target(generateAuthnResponseEndpoint).request().post(Entity.entity(responseFromHubDto, MediaType.APPLICATION_JSON_TYPE));
assertThat(rpAuthnResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
ErrorStatusDto errorStatusDto = rpAuthnResponse.readEntity(ErrorStatusDto.class);
assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_INPUT);
}
use of uk.gov.ida.hub.samlengine.contracts.ResponseFromHubDto in project verify-hub by alphagov.
the class RpAuthnResponseGeneratorResourceTest method shouldGenerateRpAuthnResponseWithMessageSignedByHubUsingLegacySamlStandard.
@Test
public void shouldGenerateRpAuthnResponseWithMessageSignedByHubUsingLegacySamlStandard() throws Exception {
// Given
ResponseFromHubDto responseFromHubDto = aResponseFromHubDto().withStatus(TransactionIdaStatus.NoMatchingServiceMatchFromHub).withAuthnRequestIssuerEntityId(TestEntityIds.TEST_RP).withAssertion(createAssertionString()).build();
configStub.setupCertificatesForEntity(responseFromHubDto.getAuthnRequestIssuerEntityId());
configStub.signResponsesAndUseLegacyStandard(responseFromHubDto.getAuthnRequestIssuerEntityId());
// When
URI generateAuthnResponseEndpoint = samlEngineAppRule.getUri(Urls.SamlEngineUrls.GENERATE_RP_AUTHN_RESPONSE_RESOURCE);
Response rpAuthnResponse = client.target(generateAuthnResponseEndpoint).request().post(Entity.entity(responseFromHubDto, MediaType.APPLICATION_JSON_TYPE));
// Then
assertThat(rpAuthnResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
AuthnResponseFromHubContainerDto result = rpAuthnResponse.readEntity(AuthnResponseFromHubContainerDto.class);
org.opensaml.saml.saml2.core.Response response = extractResponse(result);
assertThat(response.getStatus().getStatusCode().getValue()).isEqualTo(StatusCode.SUCCESS);
assertThat(response.getEncryptedAssertions()).isNotEmpty();
assertThat(response.getID()).isEqualTo(responseFromHubDto.getResponseId());
assertThat(response.getInResponseTo()).isEqualTo(responseFromHubDto.getInResponseTo());
assertThat(response.getIssuer().getValue()).isEqualTo(TestEntityIds.HUB_ENTITY_ID);
}
use of uk.gov.ida.hub.samlengine.contracts.ResponseFromHubDto in project verify-hub by alphagov.
the class RpAuthnResponseGeneratorResourceTest method shouldGenerateRpAuthnResponseWithUnsignedMessage.
@Test
public void shouldGenerateRpAuthnResponseWithUnsignedMessage() throws Exception {
// Given
String assertion = createAssertionString();
ResponseFromHubDto responseFromHubDto = aResponseFromHubDto().withAuthnRequestIssuerEntityId(TestEntityIds.TEST_RP).withAssertion(assertion).withStatus(TransactionIdaStatus.Success).build();
configStub.setupCertificatesForEntity(responseFromHubDto.getAuthnRequestIssuerEntityId());
configStub.doNotSignResponseMessages(responseFromHubDto.getAuthnRequestIssuerEntityId());
// When
URI generateAuthnResponseEndpoint = samlEngineAppRule.getUri(Urls.SamlEngineUrls.GENERATE_RP_AUTHN_RESPONSE_RESOURCE);
Response rpAuthnResponse = client.target(generateAuthnResponseEndpoint).request().post(Entity.entity(responseFromHubDto, MediaType.APPLICATION_JSON_TYPE));
// Then
assertThat(rpAuthnResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
AuthnResponseFromHubContainerDto result = rpAuthnResponse.readEntity(AuthnResponseFromHubContainerDto.class);
org.opensaml.saml.saml2.core.Response response = extractResponse(result);
assertThat(response.getStatus().getStatusCode().getValue()).isEqualTo(StatusCode.SUCCESS);
assertThat(response.getEncryptedAssertions()).isNotEmpty();
assertThat(response.getID()).isEqualTo(responseFromHubDto.getResponseId());
assertThat(response.getInResponseTo()).isEqualTo(responseFromHubDto.getInResponseTo());
assertThat(response.getSignature()).isNull();
assertThat(response.getIssuer()).isNull();
}
use of uk.gov.ida.hub.samlengine.contracts.ResponseFromHubDto in project verify-hub by alphagov.
the class RpAuthnResponseGeneratorResourceTest method shouldGenerateRpAuthnResponseWithMessageSignedByHubUsingSamlProfileStandard.
@Test
public void shouldGenerateRpAuthnResponseWithMessageSignedByHubUsingSamlProfileStandard() throws Exception {
// Given
String assertion = createAssertionString();
ResponseFromHubDto responseFromHubDto = aResponseFromHubDto().withAuthnRequestIssuerEntityId(TestEntityIds.TEST_RP).withAssertion(assertion).withStatus(TransactionIdaStatus.Success).build();
configStub.setupCertificatesForEntity(responseFromHubDto.getAuthnRequestIssuerEntityId());
configStub.signResponsesAndUseSamlStandard(responseFromHubDto.getAuthnRequestIssuerEntityId());
// When
URI generateAuthnResponseEndpoint = samlEngineAppRule.getUri(Urls.SamlEngineUrls.GENERATE_RP_AUTHN_RESPONSE_RESOURCE);
Response rpAuthnResponse = client.target(generateAuthnResponseEndpoint).request().post(Entity.entity(responseFromHubDto, MediaType.APPLICATION_JSON_TYPE));
// Then
assertThat(rpAuthnResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
AuthnResponseFromHubContainerDto actualResult = rpAuthnResponse.readEntity(AuthnResponseFromHubContainerDto.class);
org.opensaml.saml.saml2.core.Response response = extractResponse(actualResult);
assertThat(response.getStatus().getStatusCode().getValue()).isEqualTo(StatusCode.SUCCESS);
assertThat(response.getEncryptedAssertions()).isNotEmpty();
assertThat(response.getID()).isEqualTo(responseFromHubDto.getResponseId());
assertThat(response.getInResponseTo()).isEqualTo(responseFromHubDto.getInResponseTo());
assertThat(response.getIssuer().getValue()).isEqualTo(TestEntityIds.HUB_ENTITY_ID);
assertThat(response.getSignature()).isNotNull();
}
Aggregations