use of uk.gov.ida.saml.core.test.HardCodedKeyStore in project verify-hub by alphagov.
the class IdpAuthnResponseTranslatorResourceTest method handleResponseFromIdp_shouldDecryptAssertionEncryptedWithPrimaryEncryptionCertificates.
@Test
public void handleResponseFromIdp_shouldDecryptAssertionEncryptedWithPrimaryEncryptionCertificates() throws Exception {
BasicCredential primaryEncryptionKey = new BasicCredential(new HardCodedKeyStore(HUB_ENTITY_ID).getPrimaryEncryptionKeyForEntity(HUB_ENTITY_ID));
SamlAuthnResponseTranslatorDto samlResponseDto = getSuccessSamlAuthnResponseTranslatorDto(primaryEncryptionKey);
Response clientResponse = postToSamlEngine(samlResponseDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
}
use of uk.gov.ida.saml.core.test.HardCodedKeyStore in project verify-hub by alphagov.
the class SamlMessageSenderApiResourceTest method sendUnsignedJsonAuthnResponseFromHub_shouldRespondWithNextLocation.
@Test
public void sendUnsignedJsonAuthnResponseFromHub_shouldRespondWithNextLocation() throws Exception {
SessionId sessionId = SessionId.createNewSessionId();
URI nextLocationUri = URI.create("http://blah");
String requestId = UUID.randomUUID().toString();
Function<OutboundResponseFromHub, String> outboundResponseFromHubToStringTransformer = new HubTransformersFactory().getOutboundResponseFromHubToStringTransformer(new HardCodedKeyStore(HUB_ENTITY_ID), getKeyStore(), new IdpHardCodedEntityToEncryptForLocator(), SIGNATURE_ALGORITHM, DIGEST_ALGORITHM);
OutboundResponseFromHub authnResponseFromHub = anAuthnResponse().withInResponseTo(requestId).withIssuerId(HUB_ENTITY_ID).withTransactionIdaStatus(TransactionIdaStatus.Success).buildOutboundResponseFromHub();
String samlString = outboundResponseFromHubToStringTransformer.apply(authnResponseFromHub);
AuthnResponseFromHubContainerDto authnResponseFromHubContainerDto = new AuthnResponseFromHubContainerDto(samlString, nextLocationUri, java.util.Optional.empty(), authnResponseFromHub.getId());
policyStub.anAuthnResponseFromHubToRp(sessionId, authnResponseFromHubContainerDto);
javax.ws.rs.core.Response response = getResponseFromSamlProxy(Urls.SamlProxyUrls.SEND_RESPONSE_FROM_HUB_API_RESOURCE, sessionId);
assertThat(response.readEntity(SamlMessageSenderHandler.SamlMessage.class).getPostEndpoint()).isEqualTo(nextLocationUri.toASCIIString());
}
use of uk.gov.ida.saml.core.test.HardCodedKeyStore in project verify-hub by alphagov.
the class SamlMessageSenderApiResourceTest method sendJsonErrorResponseFromHub_shouldRespondWithNextLocation.
@Test
public void sendJsonErrorResponseFromHub_shouldRespondWithNextLocation() throws Exception {
URI uri = URI.create("http://blah");
String requestId = UUID.randomUUID().toString();
final SessionId sessionId = SessionId.createNewSessionId();
OutboundResponseFromHub authnResponseFromHub = anAuthnResponse().withInResponseTo(requestId).withIssuerId(HUB_ENTITY_ID).withTransactionIdaStatus(TransactionIdaStatus.RequesterError).buildOutboundResponseFromHub();
Function<OutboundResponseFromHub, String> outboundResponseFromHubToStringTransformer = new HubTransformersFactory().getOutboundResponseFromHubToStringTransformer(new HardCodedKeyStore(HUB_ENTITY_ID), getKeyStore(), new IdpHardCodedEntityToEncryptForLocator(), SIGNATURE_ALGORITHM, DIGEST_ALGORITHM);
String samlString = outboundResponseFromHubToStringTransformer.apply(authnResponseFromHub);
AuthnResponseFromHubContainerDto authnResponseFromHubContainerDto = new AuthnResponseFromHubContainerDto(samlString, uri, java.util.Optional.empty(), authnResponseFromHub.getId());
policyStub.anErrorResponseFromHubToRp(sessionId, authnResponseFromHubContainerDto);
javax.ws.rs.core.Response response = getResponseFromSamlProxy(Urls.SamlProxyUrls.SEND_ERROR_RESPONSE_FROM_HUB_API_RESOURCE, sessionId);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.readEntity(SamlMessageSenderHandler.SamlMessage.class).getPostEndpoint()).isEqualTo(uri.toASCIIString());
}
use of uk.gov.ida.saml.core.test.HardCodedKeyStore in project verify-hub by alphagov.
the class SamlMessageSenderApiResourceTest method sendSignedJsonAuthnResponseFromHub_shouldRespondWithNextLocation.
@Test
public void sendSignedJsonAuthnResponseFromHub_shouldRespondWithNextLocation() throws Exception {
SessionId sessionId = SessionId.createNewSessionId();
URI nextLocationUri = URI.create("http://blah");
String requestId = UUID.randomUUID().toString();
ResponseAssertionSigner responseAssertionSigner = new ResponseAssertionSigner(new SignatureFactory(new IdaKeyStoreCredentialRetriever(getKeyStore()), SIGNATURE_ALGORITHM, DIGEST_ALGORITHM));
Function<OutboundResponseFromHub, String> outboundResponseFromHubToStringTransformer = new HubTransformersFactory().getOutboundResponseFromHubToStringTransformer(new HardCodedKeyStore(HUB_ENTITY_ID), getKeyStore(), new IdpHardCodedEntityToEncryptForLocator(), responseAssertionSigner, SIGNATURE_ALGORITHM, DIGEST_ALGORITHM);
OutboundResponseFromHub authnResponseFromHub = anAuthnResponse().withInResponseTo(requestId).withIssuerId(HUB_ENTITY_ID).withTransactionIdaStatus(TransactionIdaStatus.Success).buildOutboundResponseFromHub();
String samlString = outboundResponseFromHubToStringTransformer.apply(authnResponseFromHub);
AuthnResponseFromHubContainerDto authnResponseFromHubContainerDto = new AuthnResponseFromHubContainerDto(samlString, nextLocationUri, java.util.Optional.empty(), authnResponseFromHub.getId());
policyStub.anAuthnResponseFromHubToRp(sessionId, authnResponseFromHubContainerDto);
javax.ws.rs.core.Response response = getResponseFromSamlProxy(Urls.SamlProxyUrls.SEND_RESPONSE_FROM_HUB_API_RESOURCE, sessionId);
assertThat(response.readEntity(SamlMessageSenderHandler.SamlMessage.class).getPostEndpoint()).isEqualTo(nextLocationUri.toASCIIString());
}
use of uk.gov.ida.saml.core.test.HardCodedKeyStore in project verify-hub by alphagov.
the class IdpAuthnResponseTranslatorResourceTest method shouldEncryptTheMatchingDatasetAssertionWhenGivenMatchingServiceEntityId.
@Test
public void shouldEncryptTheMatchingDatasetAssertionWhenGivenMatchingServiceEntityId() throws Exception {
BasicCredential primaryEncryptionKey = new BasicCredential(new HardCodedKeyStore(HUB_ENTITY_ID).getPrimaryEncryptionKeyForEntity(HUB_ENTITY_ID));
SamlAuthnResponseTranslatorDto samlResponseDto = getSuccessSamlAuthnResponseTranslatorDto(primaryEncryptionKey);
Response clientResponse = postToSamlEngine(samlResponseDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
InboundResponseFromIdpDto inboundResponseFromIdpDto = clientResponse.readEntity(InboundResponseFromIdpDto.class);
assertThat(inboundResponseFromIdpDto.getEncryptedMatchingDatasetAssertion().isPresent()).isTrue();
}
Aggregations