Skip to content

Commit

Permalink
do not return revocation batches marked for deletion (#167)
Browse files Browse the repository at this point in the history
Co-authored-by: Felix Dittrich <[email protected]>
  • Loading branch information
bergmann-dierk and f11h committed Mar 23, 2022
1 parent 45729ec commit eba7dac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ public RevocationBatchDownload getRevocationBatch(String batchId) throws Revocat
public List<CmsPackageDto> getCmsPackage(String country) {
List<RevocationBatchEntity> revocationBatchEntities = revocationBatchRepository.getAllByCountry(country);
return revocationBatchEntities.stream()
.filter(it -> !it.getDeleted())
.map(it -> new CmsPackageDto(it.getSignedBatch(), it.getId(),
CmsPackageDto.CmsPackageTypeDto.REVOCATION_LIST))
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void testAllCertTypes() throws Exception {
String cmsBase64 = Base64.getEncoder().encodeToString(certDscEu.getEncoded());

createSignerInfo(cmsBase64, certDscEu, "signature1");
createRevocation(cmsBase64);
createRevocation("id1", cmsBase64, false);
createValidationEntry(cmsBase64);

String authCertHash = trustedPartyTestHelper.getHash(TrustedPartyEntity.CertificateType.AUTHENTICATION, countryCode);
Expand All @@ -140,6 +140,25 @@ void testAllCertTypes() throws Exception {
.andExpect(jsonPath("$[2].cms", is(cmsBase64)));
}

@Test
void testRevocationDeleted() throws Exception {
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("ec");
X509Certificate certDscEu = CertificateTestUtils.generateCertificate(keyPairGenerator.generateKeyPair(), countryCode, "Test");
String cmsBase64 = Base64.getEncoder().encodeToString(certDscEu.getEncoded());

createRevocation("id1", null, true);
RevocationBatchEntity entity = createRevocation("id2", cmsBase64, false);

String authCertHash = trustedPartyTestHelper.getHash(TrustedPartyEntity.CertificateType.AUTHENTICATION, countryCode);

mockMvc.perform(get("/cms-migration")
.header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash)
.header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject))
.andExpect(jsonPath("$", hasSize(1)))
.andExpect(jsonPath("$[0].entityId", is(entity.getId()), Long.class))
.andExpect(jsonPath("$[0].cms", is(cmsBase64)));
}

@Test
void testNoneForCountry() throws Exception {
String authCertHash = trustedPartyTestHelper.getHash(TrustedPartyEntity.CertificateType.AUTHENTICATION, countryCode);
Expand Down Expand Up @@ -607,10 +626,10 @@ private void createSignerInfo(final String cmsBase64, final X509Certificate cert
));
}

private RevocationBatchEntity createRevocation(final String cmsBase64) {
private RevocationBatchEntity createRevocation(final String batchId, final String cmsBase64, boolean deleted) {
RevocationBatchEntity revocationBatchEntity = new RevocationBatchEntity(
null, "batchId", countryCode, ZonedDateTime.now(), ZonedDateTime.now().plusDays(2),
false, RevocationBatchEntity.RevocationHashType.SIGNATURE, "UNKNOWN_KID", cmsBase64);
null, batchId, countryCode, ZonedDateTime.now(), ZonedDateTime.now().plusDays(2),
deleted, RevocationBatchEntity.RevocationHashType.SIGNATURE, "UNKNOWN_KID", cmsBase64);
return revocationBatchRepository.save(revocationBatchEntity);
}

Expand Down

0 comments on commit eba7dac

Please sign in to comment.