Search in sources :

Example 11 with Certificate

use of uk.gov.ida.hub.config.domain.Certificate in project verify-hub by alphagov.

the class CertificateServiceTest method encryptionCertificateForEntityIdReturnsCertificateWhenEnabledTransactionCertificateExists.

@Test
public void encryptionCertificateForEntityIdReturnsCertificateWhenEnabledTransactionCertificateExists() {
    TransactionConfig transactionConfig = aTransactionConfigData().withEntityId(RP_ONE_ENTITY_ID).withEncryptionCertificate(CERT_ONE_X509).withEnabled(true).build();
    when(connectedServiceConfigRepository.has(RP_ONE_ENTITY_ID)).thenReturn(true);
    when(connectedServiceConfigRepository.get(RP_ONE_ENTITY_ID)).thenReturn(Optional.of(transactionConfig));
    when(certificateValidityChecker.isValid(any(Certificate.class))).thenReturn(true);
    Certificate certificate = certificateService.encryptionCertificateFor(RP_ONE_ENTITY_ID);
    assertThat(certificate).isEqualTo(new Certificate(RP_ONE_ENTITY_ID, FederationEntityType.RP, CERT_ONE_X509, CertificateUse.ENCRYPTION, CertificateOrigin.FEDERATION, true));
}
Also used : TransactionConfig(uk.gov.ida.hub.config.domain.TransactionConfig) Certificate(uk.gov.ida.hub.config.domain.Certificate) Test(org.junit.jupiter.api.Test)

Example 12 with Certificate

use of uk.gov.ida.hub.config.domain.Certificate in project verify-hub by alphagov.

the class CertificateServiceTest method signatureVerificationCertificatesForEntityIdReturnsSignatureVerificationCertificatesWhenTransactionSignatureCertificatesExists.

@Test
public void signatureVerificationCertificatesForEntityIdReturnsSignatureVerificationCertificatesWhenTransactionSignatureCertificatesExists() {
    TransactionConfig transactionConfig = aTransactionConfigData().withEntityId(RP_ONE_ENTITY_ID).addSignatureVerificationCertificate(CERT_ONE_X509).addSignatureVerificationCertificate(CERT_TWO_X509).build();
    when(connectedServiceConfigRepository.has(RP_ONE_ENTITY_ID)).thenReturn(true);
    when(connectedServiceConfigRepository.get(RP_ONE_ENTITY_ID)).thenReturn(Optional.of(transactionConfig));
    when(certificateValidityChecker.isValid(any(Certificate.class))).thenReturn(true);
    List<Certificate> CertificateFound = certificateService.signatureVerificationCertificatesFor(RP_ONE_ENTITY_ID);
    assertThat(CertificateFound.size()).isEqualTo(2);
    assertThat(CertificateFound).contains(new Certificate(RP_ONE_ENTITY_ID, FederationEntityType.RP, CERT_ONE_X509, CertificateUse.SIGNING, CertificateOrigin.FEDERATION, true), new Certificate(RP_ONE_ENTITY_ID, FederationEntityType.RP, CERT_TWO_X509, CertificateUse.SIGNING, CertificateOrigin.FEDERATION, true));
}
Also used : TransactionConfig(uk.gov.ida.hub.config.domain.TransactionConfig) Certificate(uk.gov.ida.hub.config.domain.Certificate) Test(org.junit.jupiter.api.Test)

Example 13 with Certificate

use of uk.gov.ida.hub.config.domain.Certificate in project verify-hub by alphagov.

the class CertificateServiceTest method getAllCertificatesReturnsAllTransactionAndMatchingServiceCertificate.

@Test
public void getAllCertificatesReturnsAllTransactionAndMatchingServiceCertificate() {
    final TransactionConfig transactionOneConfig = aTransactionConfigData().withEntityId(RP_ONE_ENTITY_ID).withEnabled(true).build();
    final TransactionConfig transactionTwoConfig = aTransactionConfigData().withEntityId(RP_TWO_ENTITY_ID).withEnabled(true).build();
    final MatchingServiceConfig matchingServiceOneConfig = aMatchingServiceConfig().withEntityId(RP_MSA_ONE_ENTITY_ID).build();
    Set<Certificate> expectedCertificateSet = new HashSet<>();
    expectedCertificateSet.addAll(transactionOneConfig.getAllCertificates());
    expectedCertificateSet.addAll(transactionTwoConfig.getAllCertificates());
    expectedCertificateSet.addAll(matchingServiceOneConfig.getAllCertificates());
    List<TransactionConfig> transactionConfigs = new ArrayList<>();
    transactionConfigs.add(transactionOneConfig);
    transactionConfigs.add(transactionTwoConfig);
    List<MatchingServiceConfig> matchingServiceConfigs = new ArrayList<>();
    matchingServiceConfigs.add(matchingServiceOneConfig);
    when(connectedServiceConfigRepository.stream()).thenReturn(transactionConfigs.stream());
    when(matchingServiceConfigRepository.stream()).thenReturn(matchingServiceConfigs.stream());
    final Set<Certificate> actualCertificateSet = certificateService.getAllCertificates();
    assertThat(actualCertificateSet.size()).isEqualTo(6);
    assertThat(actualCertificateSet).containsAll(expectedCertificateSet);
}
Also used : MatchingServiceConfig(uk.gov.ida.hub.config.domain.MatchingServiceConfig) MatchingServiceConfigBuilder.aMatchingServiceConfig(uk.gov.ida.hub.config.domain.builders.MatchingServiceConfigBuilder.aMatchingServiceConfig) ArrayList(java.util.ArrayList) TransactionConfig(uk.gov.ida.hub.config.domain.TransactionConfig) Certificate(uk.gov.ida.hub.config.domain.Certificate) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 14 with Certificate

use of uk.gov.ida.hub.config.domain.Certificate in project verify-hub by alphagov.

the class CertificateServiceTest method signatureVerificationCertificatesForEntityIdReturnsSignatureVerificationCertificatesWhenMatchingSignatureCertificatesExists.

@Test
public void signatureVerificationCertificatesForEntityIdReturnsSignatureVerificationCertificatesWhenMatchingSignatureCertificatesExists() {
    MatchingServiceConfig matchingServiceConfig = aMatchingServiceConfig().withEntityId(RP_ONE_ENTITY_ID).addSignatureVerificationCertificate(CERT_ONE_X509).addSignatureVerificationCertificate(CERT_TWO_X509).build();
    when(matchingServiceConfigRepository.has(RP_ONE_ENTITY_ID)).thenReturn(true);
    when(matchingServiceConfigRepository.get(RP_ONE_ENTITY_ID)).thenReturn(Optional.of(matchingServiceConfig));
    when(certificateValidityChecker.isValid(any(Certificate.class))).thenReturn(true);
    List<Certificate> CertificateFound = certificateService.signatureVerificationCertificatesFor(RP_ONE_ENTITY_ID);
    assertThat(CertificateFound.size()).isEqualTo(2);
    assertThat(CertificateFound).contains(new Certificate(RP_ONE_ENTITY_ID, FederationEntityType.RP, CERT_ONE_X509, CertificateUse.SIGNING, CertificateOrigin.FEDERATION, true), new Certificate(RP_ONE_ENTITY_ID, FederationEntityType.RP, CERT_TWO_X509, CertificateUse.SIGNING, CertificateOrigin.FEDERATION, true));
}
Also used : MatchingServiceConfig(uk.gov.ida.hub.config.domain.MatchingServiceConfig) MatchingServiceConfigBuilder.aMatchingServiceConfig(uk.gov.ida.hub.config.domain.builders.MatchingServiceConfigBuilder.aMatchingServiceConfig) Certificate(uk.gov.ida.hub.config.domain.Certificate) Test(org.junit.jupiter.api.Test)

Example 15 with Certificate

use of uk.gov.ida.hub.config.domain.Certificate in project verify-hub by alphagov.

the class CertificateServiceTest method signatureVerificationCertificatesForEntityIdReturnsValidSignatureVerificationCertificatesWhenTransactionSignatureCertificatesExist.

@Test
public void signatureVerificationCertificatesForEntityIdReturnsValidSignatureVerificationCertificatesWhenTransactionSignatureCertificatesExist() {
    TransactionConfig transactionConfig = aTransactionConfigData().withEntityId(RP_ONE_ENTITY_ID).addSignatureVerificationCertificate(CERT_ONE_X509).addSignatureVerificationCertificate(CERT_TWO_X509).build();
    Certificate validCertificate = new Certificate(RP_ONE_ENTITY_ID, FederationEntityType.RP, CERT_ONE_X509, CertificateUse.SIGNING, CertificateOrigin.FEDERATION, true);
    Certificate invalidCertificate = new Certificate(RP_ONE_ENTITY_ID, FederationEntityType.RP, CERT_TWO_X509, CertificateUse.SIGNING, CertificateOrigin.FEDERATION, true);
    when(connectedServiceConfigRepository.has(RP_ONE_ENTITY_ID)).thenReturn(true);
    when(connectedServiceConfigRepository.get(RP_ONE_ENTITY_ID)).thenReturn(Optional.of(transactionConfig));
    when(certificateValidityChecker.isValid(invalidCertificate)).thenReturn(false);
    when(certificateValidityChecker.isValid(validCertificate)).thenReturn(true);
    List<Certificate> CertificateFound = certificateService.signatureVerificationCertificatesFor(RP_ONE_ENTITY_ID);
    assertThat(CertificateFound.size()).isEqualTo(1);
    assertThat(CertificateFound.get(0)).isEqualTo(validCertificate);
}
Also used : TransactionConfig(uk.gov.ida.hub.config.domain.TransactionConfig) Certificate(uk.gov.ida.hub.config.domain.Certificate) Test(org.junit.jupiter.api.Test)

Aggregations

Certificate (uk.gov.ida.hub.config.domain.Certificate)17 Test (org.junit.jupiter.api.Test)13 MatchingServiceConfig (uk.gov.ida.hub.config.domain.MatchingServiceConfig)6 MatchingServiceConfigBuilder.aMatchingServiceConfig (uk.gov.ida.hub.config.domain.builders.MatchingServiceConfigBuilder.aMatchingServiceConfig)6 TransactionConfig (uk.gov.ida.hub.config.domain.TransactionConfig)5 DateTime (org.joda.time.DateTime)3 CertificateException (java.security.cert.CertificateException)2 CertificateDisabledException (uk.gov.ida.hub.config.exceptions.CertificateDisabledException)2 NoCertificateFoundException (uk.gov.ida.hub.config.exceptions.NoCertificateFoundException)2 Timed (com.codahale.metrics.annotation.Timed)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors.toList (java.util.stream.Collectors.toList)1 Inject (javax.inject.Inject)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1