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