Search in sources :

Example 11 with SamlRequestDto

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

the class SamlMessageReceiverApiResourceTest method shouldErrorWhenRelayStateIsMoreThanEightyCharacters.

@Test
public void shouldErrorWhenRelayStateIsMoreThanEightyCharacters() throws Exception {
    String longRelayState = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
    SamlRequestDto authnRequestWrapper = createAuthnRequest(TEST_RP, longRelayState, 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 12 with SamlRequestDto

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

the class CountryMetadataConsumerTest method shouldServeCountryMetadata.

@Test
public void shouldServeCountryMetadata() throws Exception {
    // Given
    SessionId sessionId = SessionId.createNewSessionId();
    policyStubRule.receiveAuthnResponseFromCountry(sessionId.toString(), LEVEL_2);
    String response = authnResponseFactory.aSamlResponseFromIdp("a-request", countryMetadata.getCountryMetadataUri(), idpSigningCert, idpSigningKey, "", SIGNATURE_ALGORITHM, DIGEST_ALGORITHM);
    // When
    ResponseActionDto post = postSAML(new SamlRequestDto(response, sessionId.getSessionId(), "127.0.0.1")).readEntity(ResponseActionDto.class);
    // Then
    assertThat(post.getSessionId()).isEqualTo(sessionId);
    assertThat(post.getLoaAchieved()).isEqualTo(LEVEL_2);
}
Also used : ResponseActionDto(uk.gov.ida.hub.samlproxy.domain.ResponseActionDto) SamlRequestDto(uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto) SessionId(uk.gov.ida.common.SessionId) Test(org.junit.Test)

Example 13 with SamlRequestDto

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

the class MetadataConsumerTests method shouldAllowRequestsWhenMetadataIsAvailableAndValid.

@Test
public void shouldAllowRequestsWhenMetadataIsAvailableAndValid() throws Exception {
    SessionId sessionId = SessionId.createNewSessionId();
    policyStubRule.register(UriBuilder.fromPath(Urls.PolicyUrls.IDP_AUTHN_RESPONSE_RESOURCE).build(sessionId).getPath(), 200, ResponseActionDto.success(sessionId, true, LEVEL_2));
    String response = authnResponseFactory.aSamlResponseFromIdp(TestEntityIds.STUB_IDP_ONE, STUB_IDP_PUBLIC_PRIMARY_CERT, STUB_IDP_PUBLIC_PRIMARY_PRIVATE_KEY, "", SIGNATURE_ALGORITHM, DIGEST_ALGORITHM);
    ResponseActionDto post = postSAML(new SamlRequestDto(response, sessionId.getSessionId(), "127.0.0.1")).readEntity(ResponseActionDto.class);
    assertThat(post.getSessionId()).isEqualTo(sessionId);
    assertThat(post.getLoaAchieved()).isEqualTo(LEVEL_2);
}
Also used : ResponseActionDto(uk.gov.ida.hub.samlproxy.domain.ResponseActionDto) SamlRequestDto(uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto) SessionId(uk.gov.ida.common.SessionId) Test(org.junit.Test)

Example 14 with SamlRequestDto

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

the class SamlMessageReceiverApiResourceEidasDisabledTest method responsePost_shouldRespondWith404_whenEidasIsDisabled.

@Test
public void responsePost_shouldRespondWith404_whenEidasIsDisabled() throws Exception {
    String sessionId = UUID.randomUUID().toString();
    policyStubRule.receiveAuthnResponseFromIdp(sessionId, LevelOfAssurance.LEVEL_2);
    final String samlResponse = authnResponseFactory.aSamlResponseFromIdp(STUB_IDP_ONE, STUB_IDP_PUBLIC_PRIMARY_CERT, STUB_IDP_PUBLIC_PRIMARY_PRIVATE_KEY, Endpoints.SSO_RESPONSE_ENDPOINT, SIGNATURE_ALGORITHM, DIGEST_ALGORITHM);
    SamlRequestDto authnResponse = new SamlRequestDto(samlResponse, sessionId, "127.0.0.1");
    final Response response = postSAML(authnResponse, Urls.SamlProxyUrls.EIDAS_SAML2_SSO_RECEIVER_API_RESOURCE);
    assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
}
Also used : Response(javax.ws.rs.core.Response) SamlRequestDto(uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto) Test(org.junit.Test)

Example 15 with SamlRequestDto

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

the class SamlMessageReceiverApiResourceTest method shouldReturnBadRequestAndShouldAuditWhenSendingAnAuthnRequestFromAnIncorectIssuer.

@Test
public void shouldReturnBadRequestAndShouldAuditWhenSendingAnAuthnRequestFromAnIncorectIssuer() throws Exception {
    SamlRequestDto authnRequest = createAuthnRequest(STUB_IDP_ONE, "relayState", TEST_PUBLIC_CERT, TEST_PRIVATE_KEY);
    configStubRule.setupStubForNonExistentSigningCertificates(STUB_IDP_ONE);
    eventSinkStubRule.register(Urls.HubSupportUrls.HUB_SUPPORT_EVENT_SINK_RESOURCE, Response.Status.OK.getStatusCode());
    assertThat(eventSinkStubRule.getCountOfRequestsTo(Urls.HubSupportUrls.HUB_SUPPORT_EVENT_SINK_RESOURCE)).isEqualTo(0);
    Response clientResponse = postSAML(authnRequest, Urls.SamlProxyUrls.SAML2_SSO_RECEIVER_API_ROOT);
    assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    assertThat(eventSinkStubRule.getCountOfRequestsTo(Urls.HubSupportUrls.HUB_SUPPORT_EVENT_SINK_RESOURCE)).isEqualTo(1);
}
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