Search in sources :

Example 11 with TransactionConfig

use of uk.gov.ida.hub.config.domain.TransactionConfig 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 12 with TransactionConfig

use of uk.gov.ida.hub.config.domain.TransactionConfig 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 13 with TransactionConfig

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

the class CertificateServiceTest method encryptionCertificateForEntityIdThrowsWhenEncryptionCertificateExistsButIsNotEnabled.

@Test
public void encryptionCertificateForEntityIdThrowsWhenEncryptionCertificateExistsButIsNotEnabled() {
    Assertions.assertThrows(CertificateDisabledException.class, () -> {
        TransactionConfig transactionConfig = aTransactionConfigData().withEntityId(RP_ONE_ENTITY_ID).withEnabled(false).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);
        certificateService.encryptionCertificateFor(RP_ONE_ENTITY_ID);
    });
}
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 14 with TransactionConfig

use of uk.gov.ida.hub.config.domain.TransactionConfig 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)

Example 15 with TransactionConfig

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

the class CertificateServiceTest method encryptionCertificateForEntityIdWarnsAndThrowsWhenTransactionCertificateExistsButIsInvalid.

@Test
public void encryptionCertificateForEntityIdWarnsAndThrowsWhenTransactionCertificateExistsButIsInvalid() {
    Assertions.assertThrows(NoCertificateFoundException.class, () -> {
        TransactionConfig transactionConfig = aTransactionConfigData().withEntityId(RP_ONE_ENTITY_ID).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(false);
        try {
            certificateService.encryptionCertificateFor(RP_ONE_ENTITY_ID);
        } finally {
            String expectedLogMessage = "Encryption certificate for entityId '" + RP_ONE_ENTITY_ID + "' was requested but is invalid";
            checkForExpectedLogWarnings(List.of(expectedLogMessage));
        }
    });
}
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

TransactionConfig (uk.gov.ida.hub.config.domain.TransactionConfig)21 Test (org.junit.jupiter.api.Test)15 IdentityProviderConfig (uk.gov.ida.hub.config.domain.IdentityProviderConfig)8 MatchingServiceConfig (uk.gov.ida.hub.config.domain.MatchingServiceConfig)7 ConfigValidationException (uk.gov.ida.hub.config.exceptions.ConfigValidationException)7 Certificate (uk.gov.ida.hub.config.domain.Certificate)6 TranslationData (uk.gov.ida.hub.config.domain.TranslationData)6 MatchingServiceConfigBuilder.aMatchingServiceConfig (uk.gov.ida.hub.config.domain.builders.MatchingServiceConfigBuilder.aMatchingServiceConfig)5 TranslationDataBuilder.aTranslationData (uk.gov.ida.hub.config.domain.builders.TranslationDataBuilder.aTranslationData)4 TypeLiteral (com.google.inject.TypeLiteral)2 ConfigDataBootstrap (uk.gov.ida.hub.config.data.ConfigDataBootstrap)2 LevelsOfAssuranceConfigValidator (uk.gov.ida.hub.config.data.LevelsOfAssuranceConfigValidator)2 CertificateChainConfigValidator (uk.gov.ida.hub.config.domain.CertificateChainConfigValidator)2 NoCertificateFoundException (uk.gov.ida.hub.config.exceptions.NoCertificateFoundException)2 Timed (com.codahale.metrics.annotation.Timed)1 AbstractModule (com.google.inject.AbstractModule)1 Injector (com.google.inject.Injector)1 ConfigurationFactoryFactory (io.dropwizard.configuration.ConfigurationFactoryFactory)1 DefaultConfigurationFactoryFactory (io.dropwizard.configuration.DefaultConfigurationFactoryFactory)1 URI (java.net.URI)1