Search in sources :

Example 16 with SamlRequestDto

use of uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto in project verify-hub by alphagov.

the class SamlMessageReceiverApiResourceTest method shouldErrorWhenRelayStateIsInvalid.

@Test
public void shouldErrorWhenRelayStateIsInvalid() throws Exception {
    SamlRequestDto authnRequestWrapper = createAuthnRequest(TEST_RP, INVALID_RELAY_STATE, TEST_PUBLIC_CERT, TEST_PRIVATE_KEY);
    Response clientResponse = postSAML(authnRequestWrapper, Urls.SamlProxyUrls.SAML2_SSO_RECEIVER_API_ROOT);
    assertError(clientResponse, ExceptionType.INVALID_SAML);
}
Also used : Response(javax.ws.rs.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) SamlRequestDto(uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto) Test(org.junit.Test)

Example 17 with SamlRequestDto

use of uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto in project verify-hub by alphagov.

the class SamlMessageReceiverApiResourceTest method shouldErrorWhenAuthnRequestIsInvalid.

@Test
public void shouldErrorWhenAuthnRequestIsInvalid() throws Exception {
    String id = AuthnRequestIdGenerator.generateRequestId();
    Optional<Boolean> forceAuthentication = Optional.of(false);
    Optional<Integer> assertionConsumerServiceIndex = Optional.of(1);
    String issuer = TEST_RP;
    Optional<URI> assertionConsumerServiceUrl = Optional.empty();
    String anAuthnRequest = authnRequestFactory.anInvalidAuthnRequest(id, issuer, forceAuthentication, assertionConsumerServiceUrl, assertionConsumerServiceIndex, TEST_PUBLIC_CERT, TEST_PRIVATE_KEY, Endpoints.SSO_REQUEST_ENDPOINT, Optional.empty());
    SamlRequestDto authnRequestWrapper = new SamlRequestDto(anAuthnRequest, "relayState", "ipAddress");
    configStubRule.setupStubForCertificates(issuer);
    Response clientResponse = postSAML(authnRequestWrapper, Urls.SamlProxyUrls.SAML2_SSO_RECEIVER_API_ROOT);
    assertError(clientResponse, ExceptionType.INVALID_SAML);
}
Also used : Response(javax.ws.rs.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) SamlRequestDto(uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto) URI(java.net.URI) Test(org.junit.Test)

Example 18 with SamlRequestDto

use of uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto in project verify-hub by alphagov.

the class SamlMessageReceiverApiResourceTest method shouldErrorWhenAProblemOccursWithinSessionProxy.

@Test
public void shouldErrorWhenAProblemOccursWithinSessionProxy() throws Exception {
    SamlRequestDto authnRequestWrapper = createAuthnRequest(TEST_RP, RELAY_STATE, TEST_RP_PUBLIC_SIGNING_CERT, TEST_RP_PRIVATE_SIGNING_KEY);
    configStubRule.setupStubForCertificates(TEST_RP);
    policyStubRule.returnErrorForCreateSession();
    Response clientResponse = postSAML(authnRequestWrapper, Urls.SamlProxyUrls.SAML2_SSO_RECEIVER_API_ROOT);
    assertError(clientResponse, ExceptionType.NETWORK_ERROR);
}
Also used : Response(javax.ws.rs.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) SamlRequestDto(uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto) Test(org.junit.Test)

Example 19 with SamlRequestDto

use of uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto in project verify-hub by alphagov.

the class SamlMessageReceiverApiResourceTest method shouldReturnErrorWhenInvalidResponseFromIdp.

@Test
public void shouldReturnErrorWhenInvalidResponseFromIdp() throws Exception {
    org.opensaml.saml.saml2.core.Response idpAuthnResponse = aResponse().withIssuer(anIssuer().withIssuerId(STUB_IDP_ONE).build()).withoutSignatureElement().build();
    SamlRequestDto authnRequestWrapper = new SamlRequestDto(authnRequestToStringTransformer.apply(idpAuthnResponse), "relayState", "ipAddress");
    Response clientResponse = postSAML(authnRequestWrapper, Urls.SamlProxyUrls.SAML2_SSO_RECEIVER_API_RESOURCE);
    assertError(clientResponse, ExceptionType.INVALID_SAML);
}
Also used : Response(javax.ws.rs.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) SamlRequestDto(uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto) Test(org.junit.Test)

Example 20 with SamlRequestDto

use of uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto in project verify-hub by alphagov.

the class SamlMessageReceiverApiResourceTest method shouldErrorWhenNonBase64SamlRequest.

@Test
public void shouldErrorWhenNonBase64SamlRequest() throws Exception {
    SamlRequestDto authnRequestWrapper = new SamlRequestDto(TestSamlRequestFactory.createNonBase64Request(), "relayState", "ipAddress");
    Response clientResponse = postSAML(authnRequestWrapper, Urls.SamlProxyUrls.SAML2_SSO_RECEIVER_API_ROOT);
    assertError(clientResponse, ExceptionType.INVALID_SAML);
}
Also used : Response(javax.ws.rs.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) SamlRequestDto(uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto) Test(org.junit.Test)

Aggregations

SamlRequestDto (uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto)22 Test (org.junit.Test)21 Response (javax.ws.rs.core.Response)18 ResponseBuilder.aResponse (uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse)14 SessionId (uk.gov.ida.common.SessionId)5 URI (java.net.URI)3 ResponseActionDto (uk.gov.ida.hub.samlproxy.domain.ResponseActionDto)2 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)1 AuthnRequestBuilder.anAuthnRequest (uk.gov.ida.saml.core.test.builders.AuthnRequestBuilder.anAuthnRequest)1