Search in sources :

Example 1 with SamlRequestWithAuthnRequestInformationDto

use of uk.gov.ida.hub.samlengine.contracts.SamlRequestWithAuthnRequestInformationDto in project verify-hub by alphagov.

the class RpAuthnRequestTranslatorServiceTest method shouldTranslateSamlAuthnRequest.

@Test
public void shouldTranslateSamlAuthnRequest() throws Exception {
    RpAuthnRequestTranslatorService service = new RpAuthnRequestTranslatorService(stringToAuthnRequestTransformer, samlAuthnRequestToAuthnRequestFromRelyingPartyTransformer);
    boolean forceAuthentication = true;
    String id = UUID.randomUUID().toString();
    String issuer = UUID.randomUUID().toString();
    URI assertionConsumerServiceUrl = URI.create("http://someassertionuri");
    int assertionConsumerServiceIndex = 1;
    Signature signature = aSignature().withSignatureAlgorithm(SIGNATURE_ALGORITHM).build();
    ((SignatureImpl) signature).setXMLSignature(BuilderHelper.createXMLSignature(SIGNATURE_ALGORITHM, new DigestSHA256()));
    SamlRequestWithAuthnRequestInformationDto samlRequestWithAuthnRequestInformationDto = SamlAuthnRequestDtoBuilder.aSamlAuthnRequest().withId(id).withIssuer(issuer).withForceAuthentication(forceAuthentication).withAssertionConsumerIndex(assertionConsumerServiceIndex).withPublicCert(TEST_RP_PUBLIC_SIGNING_CERT).withPrivateKey(TEST_RP_PRIVATE_SIGNING_KEY).build();
    AuthnRequest authnRequest = AuthnRequestBuilder.anAuthnRequest().build();
    TranslatedAuthnRequestDto expected = TranslatedAuthnRequestDtoBuilder.aTranslatedAuthnRequest().withId(id).withIssuer(issuer).withForceAuthentication(forceAuthentication).withAssertionConsumerServiceUrl(assertionConsumerServiceUrl).withAssertionConsumerServiceIndex(assertionConsumerServiceIndex).build();
    AuthnRequestFromRelyingParty intermediateBlah = anAuthnRequestFromRelyingParty().withId(id).withIssuer(issuer).withForceAuthentication(forceAuthentication).withAssertionConsumerServiceUrl(assertionConsumerServiceUrl).withAssertionConsumerServiceIndex(assertionConsumerServiceIndex).withSignature(signature).build();
    stub(stringToAuthnRequestTransformer.apply(samlRequestWithAuthnRequestInformationDto.getSamlMessage())).toReturn(authnRequest);
    stub(samlAuthnRequestToAuthnRequestFromRelyingPartyTransformer.apply(authnRequest)).toReturn(intermediateBlah);
    TranslatedAuthnRequestDto actual = service.translate(samlRequestWithAuthnRequestInformationDto);
    assertThat(actual).isEqualToComparingFieldByField(expected);
}
Also used : SamlRequestWithAuthnRequestInformationDto(uk.gov.ida.hub.samlengine.contracts.SamlRequestWithAuthnRequestInformationDto) DigestSHA256(org.opensaml.xmlsec.algorithm.descriptors.DigestSHA256) AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) AuthnRequestFromRelyingParty(uk.gov.ida.saml.hub.domain.AuthnRequestFromRelyingParty) AuthnRequestFromRelyingPartyBuilder.anAuthnRequestFromRelyingParty(uk.gov.ida.hub.samlengine.builders.AuthnRequestFromRelyingPartyBuilder.anAuthnRequestFromRelyingParty) Signature(org.opensaml.xmlsec.signature.Signature) SignatureBuilder.aSignature(uk.gov.ida.saml.core.test.builders.SignatureBuilder.aSignature) TranslatedAuthnRequestDto(uk.gov.ida.hub.samlengine.contracts.TranslatedAuthnRequestDto) SignatureImpl(org.opensaml.xmlsec.signature.impl.SignatureImpl) URI(java.net.URI) Test(org.junit.Test)

Example 2 with SamlRequestWithAuthnRequestInformationDto

use of uk.gov.ida.hub.samlengine.contracts.SamlRequestWithAuthnRequestInformationDto in project verify-hub by alphagov.

the class RpAuthnRequestTranslatorResourceTest method shouldThrowInvalidSamlExceptionWhenTheAuthnRequestIsInvalid.

@Test
public void shouldThrowInvalidSamlExceptionWhenTheAuthnRequestIsInvalid() throws Exception {
    SamlRequestWithAuthnRequestInformationDto requestDto = aSamlAuthnRequest().withPublicCert(TEST_RP_PUBLIC_SIGNING_CERT).withPrivateKey(TEST_RP_PRIVATE_SIGNING_KEY).buildInvalid();
    Response response = post(requestDto, samlEngineAppRule.getUri(Urls.SamlEngineUrls.TRANSLATE_RP_AUTHN_REQUEST_RESOURCE));
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto entity = response.readEntity(ErrorStatusDto.class);
    assertThat(entity.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
Also used : SamlRequestWithAuthnRequestInformationDto(uk.gov.ida.hub.samlengine.contracts.SamlRequestWithAuthnRequestInformationDto) Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) Test(org.junit.Test)

Example 3 with SamlRequestWithAuthnRequestInformationDto

use of uk.gov.ida.hub.samlengine.contracts.SamlRequestWithAuthnRequestInformationDto in project verify-hub by alphagov.

the class RpAuthnRequestTranslatorResourceTest method shouldTranslateSamlAuthnRequestMessage.

@Test
public void shouldTranslateSamlAuthnRequestMessage() throws Exception {
    String id = AuthnRequestIdGenerator.generateRequestId();
    int assertionConsumerServiceIndex = 1;
    SamlRequestWithAuthnRequestInformationDto requestDto = aSamlAuthnRequest().withId(id).withIssuer(TEST_RP).withForceAuthentication(false).withAssertionConsumerIndex(assertionConsumerServiceIndex).withPublicCert(TEST_RP_PUBLIC_SIGNING_CERT).withPrivateKey(TEST_RP_PRIVATE_SIGNING_KEY).build();
    TranslatedAuthnRequestDto expectedResult = aTranslatedAuthnRequest().withId(id).withIssuer(TEST_RP).withForceAuthentication(false).withAssertionConsumerServiceIndex(assertionConsumerServiceIndex).build();
    Response response = post(requestDto, samlEngineAppRule.getUri(Urls.SamlEngineUrls.TRANSLATE_RP_AUTHN_REQUEST_RESOURCE));
    assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    assertThat(response.readEntity(TranslatedAuthnRequestDto.class)).isEqualToComparingFieldByField(expectedResult);
}
Also used : SamlRequestWithAuthnRequestInformationDto(uk.gov.ida.hub.samlengine.contracts.SamlRequestWithAuthnRequestInformationDto) Response(javax.ws.rs.core.Response) TranslatedAuthnRequestDto(uk.gov.ida.hub.samlengine.contracts.TranslatedAuthnRequestDto) Test(org.junit.Test)

Example 4 with SamlRequestWithAuthnRequestInformationDto

use of uk.gov.ida.hub.samlengine.contracts.SamlRequestWithAuthnRequestInformationDto in project verify-hub by alphagov.

the class RpAuthnRequestTranslatorResourceTest method shouldThrowExceptionWhenAuthnRequestIsSignedByNonExistentRP.

@Test
public void shouldThrowExceptionWhenAuthnRequestIsSignedByNonExistentRP() throws Exception {
    final SamlRequestWithAuthnRequestInformationDto requestDto = aSamlAuthnRequest().withPublicCert(STUB_IDP_PUBLIC_PRIMARY_CERT).withPrivateKey(STUB_IDP_PUBLIC_PRIMARY_PRIVATE_KEY).build();
    configStub.setupStubForNonExistentSigningCertificates("nonexistent-rp");
    Response response = post(requestDto, samlEngineAppRule.getUri(Urls.SamlEngineUrls.TRANSLATE_RP_AUTHN_REQUEST_RESOURCE));
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
}
Also used : SamlRequestWithAuthnRequestInformationDto(uk.gov.ida.hub.samlengine.contracts.SamlRequestWithAuthnRequestInformationDto) Response(javax.ws.rs.core.Response) Test(org.junit.Test)

Example 5 with SamlRequestWithAuthnRequestInformationDto

use of uk.gov.ida.hub.samlengine.contracts.SamlRequestWithAuthnRequestInformationDto in project verify-hub by alphagov.

the class RpAuthnRequestTranslatorResourceTest method authenticationRequestPost_shouldThrowExceptionWhenIssueInstantTooOld.

@Test
public void authenticationRequestPost_shouldThrowExceptionWhenIssueInstantTooOld() throws Exception {
    DateTimeFreezer.freezeTime();
    DateTime issueInstant = DateTime.now().minusMinutes(5).minusSeconds(1);
    SamlRequestWithAuthnRequestInformationDto requestDto = aSamlAuthnRequest().withIssueInstant(issueInstant).withIssuer(TEST_RP).withPublicCert(TEST_RP_PUBLIC_SIGNING_CERT).withPrivateKey(TEST_RP_PRIVATE_SIGNING_KEY).build();
    Response response = post(requestDto, samlEngineAppRule.getUri(Urls.SamlEngineUrls.TRANSLATE_RP_AUTHN_REQUEST_RESOURCE));
    assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto entity = response.readEntity(ErrorStatusDto.class);
    assertThat(entity.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML_REQUEST_TOO_OLD);
}
Also used : SamlRequestWithAuthnRequestInformationDto(uk.gov.ida.hub.samlengine.contracts.SamlRequestWithAuthnRequestInformationDto) Response(javax.ws.rs.core.Response) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 SamlRequestWithAuthnRequestInformationDto (uk.gov.ida.hub.samlengine.contracts.SamlRequestWithAuthnRequestInformationDto)6 Response (javax.ws.rs.core.Response)5 ErrorStatusDto (uk.gov.ida.common.ErrorStatusDto)3 TranslatedAuthnRequestDto (uk.gov.ida.hub.samlengine.contracts.TranslatedAuthnRequestDto)2 URI (java.net.URI)1 DateTime (org.joda.time.DateTime)1 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)1 DigestSHA256 (org.opensaml.xmlsec.algorithm.descriptors.DigestSHA256)1 Signature (org.opensaml.xmlsec.signature.Signature)1 SignatureImpl (org.opensaml.xmlsec.signature.impl.SignatureImpl)1 AuthnRequestFromRelyingPartyBuilder.anAuthnRequestFromRelyingParty (uk.gov.ida.hub.samlengine.builders.AuthnRequestFromRelyingPartyBuilder.anAuthnRequestFromRelyingParty)1 SignatureBuilder.aSignature (uk.gov.ida.saml.core.test.builders.SignatureBuilder.aSignature)1 AuthnRequestFromRelyingParty (uk.gov.ida.saml.hub.domain.AuthnRequestFromRelyingParty)1