Search in sources :

Example 1 with ResponseFromHubDto

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);
}
Also used : Response(javax.ws.rs.core.Response) ResponseFromHubDtoBuilder.aResponseFromHubDto(uk.gov.ida.integrationtest.hub.samlengine.builders.ResponseFromHubDtoBuilder.aResponseFromHubDto) ResponseFromHubDto(uk.gov.ida.hub.samlengine.contracts.ResponseFromHubDto) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) URI(java.net.URI) Test(org.junit.Test)

Example 2 with ResponseFromHubDto

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);
}
Also used : Response(javax.ws.rs.core.Response) AuthnResponseFromHubContainerDto(uk.gov.ida.hub.samlengine.contracts.AuthnResponseFromHubContainerDto) ResponseFromHubDtoBuilder.aResponseFromHubDto(uk.gov.ida.integrationtest.hub.samlengine.builders.ResponseFromHubDtoBuilder.aResponseFromHubDto) ResponseFromHubDto(uk.gov.ida.hub.samlengine.contracts.ResponseFromHubDto) URI(java.net.URI) Test(org.junit.Test)

Example 3 with ResponseFromHubDto

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();
}
Also used : Response(javax.ws.rs.core.Response) AuthnResponseFromHubContainerDto(uk.gov.ida.hub.samlengine.contracts.AuthnResponseFromHubContainerDto) ResponseFromHubDtoBuilder.aResponseFromHubDto(uk.gov.ida.integrationtest.hub.samlengine.builders.ResponseFromHubDtoBuilder.aResponseFromHubDto) ResponseFromHubDto(uk.gov.ida.hub.samlengine.contracts.ResponseFromHubDto) URI(java.net.URI) Test(org.junit.Test)

Example 4 with ResponseFromHubDto

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();
}
Also used : Response(javax.ws.rs.core.Response) AuthnResponseFromHubContainerDto(uk.gov.ida.hub.samlengine.contracts.AuthnResponseFromHubContainerDto) ResponseFromHubDtoBuilder.aResponseFromHubDto(uk.gov.ida.integrationtest.hub.samlengine.builders.ResponseFromHubDtoBuilder.aResponseFromHubDto) ResponseFromHubDto(uk.gov.ida.hub.samlengine.contracts.ResponseFromHubDto) URI(java.net.URI) Test(org.junit.Test)

Aggregations

URI (java.net.URI)4 Response (javax.ws.rs.core.Response)4 Test (org.junit.Test)4 ResponseFromHubDto (uk.gov.ida.hub.samlengine.contracts.ResponseFromHubDto)4 ResponseFromHubDtoBuilder.aResponseFromHubDto (uk.gov.ida.integrationtest.hub.samlengine.builders.ResponseFromHubDtoBuilder.aResponseFromHubDto)4 AuthnResponseFromHubContainerDto (uk.gov.ida.hub.samlengine.contracts.AuthnResponseFromHubContainerDto)3 ErrorStatusDto (uk.gov.ida.common.ErrorStatusDto)1