Search in sources :

Example 1 with SignatureVerificationCertificate

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

the class CertificateServiceTest method findsOnlyValidSignatureVerificationCertificates_WhenTransactionSignatureCertificatesExists.

@Test
public void findsOnlyValidSignatureVerificationCertificates_WhenTransactionSignatureCertificatesExists() throws Exception {
    SignatureVerificationCertificate validCert = aSignatureVerificationCertificate().withX509(CERT_ONE_X509).build();
    SignatureVerificationCertificate invalidCert = aSignatureVerificationCertificate().withX509(CERT_TWO_X509).build();
    TransactionConfigEntityData transactionConfigEntityData = aTransactionConfigData().withEntityId(ENTITY_ID).addSignatureVerificationCertificate(validCert).addSignatureVerificationCertificate(invalidCert).build();
    CertificateDetails validCertificate = aCertifcateDetail(ENTITY_ID, validCert, FederationEntityType.RP);
    CertificateDetails invalidCertificate = aCertifcateDetail(ENTITY_ID, invalidCert, FederationEntityType.RP);
    when(matchingServiceDataSource.getData(ENTITY_ID)).thenReturn(Optional.empty());
    when(transactionDataSource.getData(ENTITY_ID)).thenReturn(Optional.of(transactionConfigEntityData));
    when(certificateValidityChecker.isValid(invalidCertificate)).thenReturn(false);
    when(certificateValidityChecker.isValid(validCertificate)).thenReturn(true);
    List<CertificateDetails> certificateDetailsFound = certificateService.signatureVerificatonCertificatesFor(ENTITY_ID);
    assertThat(certificateDetailsFound.size()).isEqualTo(1);
    assertThat(certificateDetailsFound.get(0)).isEqualTo(validCertificate);
}
Also used : CertificateDetails(uk.gov.ida.hub.config.domain.CertificateDetails) SignatureVerificationCertificateBuilder.aSignatureVerificationCertificate(uk.gov.ida.hub.config.domain.builders.SignatureVerificationCertificateBuilder.aSignatureVerificationCertificate) SignatureVerificationCertificate(uk.gov.ida.hub.config.domain.SignatureVerificationCertificate) TransactionConfigEntityData(uk.gov.ida.hub.config.domain.TransactionConfigEntityData) Test(org.junit.Test)

Example 2 with SignatureVerificationCertificate

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

the class CertificateServiceTest method findsOnlyValidSignatureVerificationCertificates_WhenMatchingSignatureCertificatesExists.

@Test
public void findsOnlyValidSignatureVerificationCertificates_WhenMatchingSignatureCertificatesExists() throws Exception {
    SignatureVerificationCertificate validSigCert = aSignatureVerificationCertificate().withX509(CERT_ONE_X509).build();
    SignatureVerificationCertificate invalidSigCert = aSignatureVerificationCertificate().withX509(CERT_TWO_X509).build();
    MatchingServiceConfigEntityData matchingServiceConfigEntityData = aMatchingServiceConfigEntityData().withEntityId(ENTITY_ID).addSignatureVerificationCertificate(validSigCert).addSignatureVerificationCertificate(invalidSigCert).build();
    CertificateDetails validCertificate = new CertificateDetails(ENTITY_ID, validSigCert, FederationEntityType.MS);
    CertificateDetails invalidCertificate = new CertificateDetails(ENTITY_ID, invalidSigCert, FederationEntityType.MS);
    when(transactionDataSource.getData(ENTITY_ID)).thenReturn(Optional.empty());
    when(matchingServiceDataSource.getData(ENTITY_ID)).thenReturn(Optional.of(matchingServiceConfigEntityData));
    when(certificateValidityChecker.isValid(invalidCertificate)).thenReturn(false);
    when(certificateValidityChecker.isValid(validCertificate)).thenReturn(true);
    List<CertificateDetails> certificateDetailsFound = certificateService.signatureVerificatonCertificatesFor(ENTITY_ID);
    assertThat(certificateDetailsFound.size()).isEqualTo(1);
    assertThat(certificateDetailsFound.get(0)).isEqualTo(validCertificate);
}
Also used : MatchingServiceConfigEntityDataBuilder.aMatchingServiceConfigEntityData(uk.gov.ida.hub.config.domain.builders.MatchingServiceConfigEntityDataBuilder.aMatchingServiceConfigEntityData) MatchingServiceConfigEntityData(uk.gov.ida.hub.config.domain.MatchingServiceConfigEntityData) CertificateDetails(uk.gov.ida.hub.config.domain.CertificateDetails) SignatureVerificationCertificateBuilder.aSignatureVerificationCertificate(uk.gov.ida.hub.config.domain.builders.SignatureVerificationCertificateBuilder.aSignatureVerificationCertificate) SignatureVerificationCertificate(uk.gov.ida.hub.config.domain.SignatureVerificationCertificate) Test(org.junit.Test)

Example 3 with SignatureVerificationCertificate

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

the class SignatureVerificationCertificateBuilder method build.

public SignatureVerificationCertificate build() {
    String fullCert = format("-----BEGIN CERTIFICATE-----\n{0}\n-----END CERTIFICATE-----", x509Value.trim());
    DeserializablePublicKeyConfiguration configuration = mock(DeserializablePublicKeyConfiguration.class);
    when(configuration.getCert()).thenReturn(fullCert);
    return new SignatureVerificationCertificate(configuration);
}
Also used : DeserializablePublicKeyConfiguration(uk.gov.ida.common.shared.configuration.DeserializablePublicKeyConfiguration) SignatureVerificationCertificate(uk.gov.ida.hub.config.domain.SignatureVerificationCertificate)

Example 4 with SignatureVerificationCertificate

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

the class CertificateServiceTest method throwsNoCertificateFoundException_WhenMatchingSignatureCertificatesExistButAreInvalid.

@Test(expected = NoCertificateFoundException.class)
public void throwsNoCertificateFoundException_WhenMatchingSignatureCertificatesExistButAreInvalid() throws Exception {
    SignatureVerificationCertificate invalidSigCert = aSignatureVerificationCertificate().withX509(CERT_TWO_X509).build();
    MatchingServiceConfigEntityData matchingServiceConfigEntityData = aMatchingServiceConfigEntityData().withEntityId(ENTITY_ID).addSignatureVerificationCertificate(invalidSigCert).build();
    CertificateDetails invalidCertificate = new CertificateDetails(ENTITY_ID, invalidSigCert, FederationEntityType.MS);
    when(transactionDataSource.getData(ENTITY_ID)).thenReturn(Optional.empty());
    when(matchingServiceDataSource.getData(ENTITY_ID)).thenReturn(Optional.of(matchingServiceConfigEntityData));
    when(certificateValidityChecker.isValid(invalidCertificate)).thenReturn(false);
    certificateService.signatureVerificatonCertificatesFor(ENTITY_ID);
}
Also used : MatchingServiceConfigEntityDataBuilder.aMatchingServiceConfigEntityData(uk.gov.ida.hub.config.domain.builders.MatchingServiceConfigEntityDataBuilder.aMatchingServiceConfigEntityData) MatchingServiceConfigEntityData(uk.gov.ida.hub.config.domain.MatchingServiceConfigEntityData) CertificateDetails(uk.gov.ida.hub.config.domain.CertificateDetails) SignatureVerificationCertificateBuilder.aSignatureVerificationCertificate(uk.gov.ida.hub.config.domain.builders.SignatureVerificationCertificateBuilder.aSignatureVerificationCertificate) SignatureVerificationCertificate(uk.gov.ida.hub.config.domain.SignatureVerificationCertificate) Test(org.junit.Test)

Example 5 with SignatureVerificationCertificate

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

the class CertificateServiceTest method findsSignatureVerificationCertificates_WhenMatchingSignatureCertificatesExists.

@Test
public void findsSignatureVerificationCertificates_WhenMatchingSignatureCertificatesExists() throws Exception {
    SignatureVerificationCertificate sigCert1 = aSignatureVerificationCertificate().withX509(CERT_ONE_X509).build();
    SignatureVerificationCertificate sigCert2 = aSignatureVerificationCertificate().withX509(CERT_TWO_X509).build();
    MatchingServiceConfigEntityData matchingServiceConfigEntityData = aMatchingServiceConfigEntityData().withEntityId(ENTITY_ID).addSignatureVerificationCertificate(sigCert1).addSignatureVerificationCertificate(sigCert2).build();
    when(transactionDataSource.getData(ENTITY_ID)).thenReturn(Optional.empty());
    when(matchingServiceDataSource.getData(ENTITY_ID)).thenReturn(Optional.of(matchingServiceConfigEntityData));
    when(certificateValidityChecker.isValid(any(CertificateDetails.class))).thenReturn(true);
    List<CertificateDetails> certificateDetailsFound = certificateService.signatureVerificatonCertificatesFor(ENTITY_ID);
    assertThat(certificateDetailsFound.size()).isEqualTo(2);
    assertThat(certificateDetailsFound).contains(aCertifcateDetail(ENTITY_ID, sigCert1, FederationEntityType.MS), aCertifcateDetail(ENTITY_ID, sigCert2, FederationEntityType.MS));
}
Also used : MatchingServiceConfigEntityDataBuilder.aMatchingServiceConfigEntityData(uk.gov.ida.hub.config.domain.builders.MatchingServiceConfigEntityDataBuilder.aMatchingServiceConfigEntityData) MatchingServiceConfigEntityData(uk.gov.ida.hub.config.domain.MatchingServiceConfigEntityData) CertificateDetails(uk.gov.ida.hub.config.domain.CertificateDetails) SignatureVerificationCertificateBuilder.aSignatureVerificationCertificate(uk.gov.ida.hub.config.domain.builders.SignatureVerificationCertificateBuilder.aSignatureVerificationCertificate) SignatureVerificationCertificate(uk.gov.ida.hub.config.domain.SignatureVerificationCertificate) Test(org.junit.Test)

Aggregations

SignatureVerificationCertificate (uk.gov.ida.hub.config.domain.SignatureVerificationCertificate)7 Test (org.junit.Test)5 CertificateDetails (uk.gov.ida.hub.config.domain.CertificateDetails)5 SignatureVerificationCertificateBuilder.aSignatureVerificationCertificate (uk.gov.ida.hub.config.domain.builders.SignatureVerificationCertificateBuilder.aSignatureVerificationCertificate)5 MatchingServiceConfigEntityData (uk.gov.ida.hub.config.domain.MatchingServiceConfigEntityData)4 MatchingServiceConfigEntityDataBuilder.aMatchingServiceConfigEntityData (uk.gov.ida.hub.config.domain.builders.MatchingServiceConfigEntityDataBuilder.aMatchingServiceConfigEntityData)4 TransactionConfigEntityData (uk.gov.ida.hub.config.domain.TransactionConfigEntityData)3 Ignore (org.junit.Ignore)1 DeserializablePublicKeyConfiguration (uk.gov.ida.common.shared.configuration.DeserializablePublicKeyConfiguration)1 CountriesConfigEntityData (uk.gov.ida.hub.config.domain.CountriesConfigEntityData)1 IdentityProviderConfigEntityData (uk.gov.ida.hub.config.domain.IdentityProviderConfigEntityData)1 SignatureVerificationCertificateBuilder (uk.gov.ida.hub.config.domain.builders.SignatureVerificationCertificateBuilder)1 InvalidCertificateDto (uk.gov.ida.hub.config.dto.InvalidCertificateDto)1