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));
}
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));
}
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);
}
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));
}
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);
}
Aggregations