From 617e48e39f926964ae37a93c80a0aebc8a28d35f Mon Sep 17 00:00:00 2001 From: Felix Dittrich <31076102+f11h@users.noreply.github.com> Date: Thu, 21 Jul 2022 18:36:25 +0200 Subject: [PATCH] Fix: Fallback Values for Pagination (#194) * Add Fallback Values for Pagination * Renove obsolete testcase * More robust --- .../controller/TrustListController.java | 17 +- .../controller/TrustListIntegrationTest.java | 787 +++++++++--------- 2 files changed, 427 insertions(+), 377 deletions(-) diff --git a/src/main/java/eu/europa/ec/dgc/gateway/restapi/controller/TrustListController.java b/src/main/java/eu/europa/ec/dgc/gateway/restapi/controller/TrustListController.java index 9e4c594e..d0c284d3 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/restapi/controller/TrustListController.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/restapi/controller/TrustListController.java @@ -149,8 +149,11 @@ public ResponseEntity> downloadTrustList( ) { List trustList; if (isPaginationRequired(page,size)) { + page = (page != null && page >= 0) ? page : 0; + size = (size != null && size >= 0) ? size : 100; + trustList = trustListMapper.trustListToTrustListDto( - trustListService.getTrustList(ifModifiedSince, page, size)); + trustListService.getTrustList(ifModifiedSince, page, size)); } else { trustList = trustListMapper.trustListToTrustListDto( trustListService.getTrustList(ifModifiedSince, null, null)); @@ -240,8 +243,11 @@ public ResponseEntity> downloadTrustListFilteredByType( TrustListType mappedType = trustListMapper.certificateTypeDtoToTrustListType(type); List trustList; if (isPaginationRequired(page,size)) { + page = (page != null && page >= 0) ? page : 0; + size = (size != null && size >= 0) ? size : 100; + trustList = trustListMapper.trustListToTrustListDto( - trustListService.getTrustList(mappedType, ifModifiedSince, page, size)); + trustListService.getTrustList(mappedType, ifModifiedSince, page, size)); } else { trustList = trustListMapper.trustListToTrustListDto( trustListService.getTrustList(mappedType, ifModifiedSince, null, null)); @@ -342,8 +348,11 @@ public ResponseEntity> downloadTrustListFilteredByCountryAndT List trustList; if (isPaginationRequired(page,size)) { + page = (page != null && page >= 0) ? page : 0; + size = (size != null && size >= 0) ? size : 100; + trustList = trustListMapper.trustListToTrustListDto( - trustListService.getTrustList(mappedType, countryCode, ifModifiedSince, page, size)); + trustListService.getTrustList(mappedType, countryCode, ifModifiedSince, page, size)); } else { trustList = trustListMapper.trustListToTrustListDto( trustListService.getTrustList(mappedType, countryCode, ifModifiedSince, null, null)); @@ -409,6 +418,6 @@ public ResponseEntity> getTrustedIssuersByCountry( } private boolean isPaginationRequired(Integer page, Integer size) { - return page != null && size != null && page >= 0 && size > 0; + return (page != null && page >= 0) || (size != null && size >= 0); } } diff --git a/src/test/java/eu/europa/ec/dgc/gateway/restapi/controller/TrustListIntegrationTest.java b/src/test/java/eu/europa/ec/dgc/gateway/restapi/controller/TrustListIntegrationTest.java index fd00c608..2371b2c2 100644 --- a/src/test/java/eu/europa/ec/dgc/gateway/restapi/controller/TrustListIntegrationTest.java +++ b/src/test/java/eu/europa/ec/dgc/gateway/restapi/controller/TrustListIntegrationTest.java @@ -20,6 +20,12 @@ package eu.europa.ec.dgc.gateway.restapi.controller; +import static org.hamcrest.Matchers.hasSize; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; @@ -46,7 +52,6 @@ import java.util.Base64; import java.util.List; import java.util.Optional; -import static org.hamcrest.Matchers.hasSize; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -58,10 +63,6 @@ import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @SpringBootTest @AutoConfigureMockMvc @@ -106,7 +107,7 @@ class TrustListIntegrationTest { private static final ZonedDateTime nowMinusOneHour = ZonedDateTime.now(gmt).minusHours(1); X509Certificate certUploadDe, certUploadEu, certCscaDe, certCscaEu, certAuthDe, certAuthEu, certDscDe, certDscEu, - certUploadDe2, certUploadEu2, certCscaDe2, certCscaEu2, certAuthDe2, certAuthEu2, certDscDe2, certDscEu2, certDscEuDeleted; + certUploadDe2, certUploadEu2, certCscaDe2, certCscaEu2, certAuthDe2, certAuthEu2, certDscDe2, certDscEu2, certDscEuDeleted; @BeforeEach void testData() throws Exception { @@ -129,9 +130,9 @@ void testData() throws Exception { signerInformationTestHelper.createSignerInformationInDB("EU", "sig2", certDscEu, now); trustedIssuerRepository.saveAll(List.of( - trustedIssuerTestHelper.createTrustedIssuer("EU"), - trustedIssuerTestHelper.createTrustedIssuer("DE"), - trustedIssuerTestHelper.createTrustedIssuer("AT") + trustedIssuerTestHelper.createTrustedIssuer("EU"), + trustedIssuerTestHelper.createTrustedIssuer("DE"), + trustedIssuerTestHelper.createTrustedIssuer("AT") )); } @@ -141,71 +142,72 @@ void testTrustListDownloadNoFilterIsSince() throws Exception { String authCertHash = trustedPartyTestHelper.getHash(TrustedPartyEntity.CertificateType.AUTHENTICATION, countryCode); mockMvc.perform(get("/trustList") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(IF_MODIFIED_SINCE_HEADER, nowMinusOneHour) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certDscDe, "DE", CertificateTypeDto.DSC, "sig1")) - .andExpect(c -> assertTrustListItem(c, certDscEu, "EU", CertificateTypeDto.DSC, "sig2")) - .andExpect(c -> assertTrustListItem(c, certDscDe2, "DE", CertificateTypeDto.DSC, "sig3")) - .andExpect(c -> assertTrustListItem(c, certDscEu2, "EU", CertificateTypeDto.DSC, "sig4")) - .andExpect(c -> assertTrustListItem(c, certDscEuDeleted, "EU", CertificateTypeDto.DSC, null, true)) - .andExpect(c -> assertTrustListItem(c, certCscaDe, "DE", CertificateTypeDto.CSCA, null)) - .andExpect(c -> assertTrustListItem(c, certCscaEu, "EU", CertificateTypeDto.CSCA, null)) - .andExpect(c -> assertTrustListItem(c, certUploadDe, "DE", CertificateTypeDto.UPLOAD, null)) - .andExpect(c -> assertTrustListItem(c, certUploadEu, "EU", CertificateTypeDto.UPLOAD, null)) - .andExpect(c -> assertTrustListItem(c, certAuthDe, "DE", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListItem(c, certAuthEu, "EU", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListItem(c, certCscaDe2, "DE", CertificateTypeDto.CSCA, null)) - .andExpect(c -> assertTrustListItem(c, certCscaEu2, "EU", CertificateTypeDto.CSCA, null)) - .andExpect(c -> assertTrustListItem(c, certUploadDe2, "DE", CertificateTypeDto.UPLOAD, null)) - .andExpect(c -> assertTrustListItem(c, certUploadEu2, "EU", CertificateTypeDto.UPLOAD, null)) - .andExpect(c -> assertTrustListItem(c, certAuthDe2, "DE", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListItem(c, certAuthEu2, "EU", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListLength(c, 17)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(IF_MODIFIED_SINCE_HEADER, nowMinusOneHour) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certDscDe, "DE", CertificateTypeDto.DSC, "sig1")) + .andExpect(c -> assertTrustListItem(c, certDscEu, "EU", CertificateTypeDto.DSC, "sig2")) + .andExpect(c -> assertTrustListItem(c, certDscDe2, "DE", CertificateTypeDto.DSC, "sig3")) + .andExpect(c -> assertTrustListItem(c, certDscEu2, "EU", CertificateTypeDto.DSC, "sig4")) + .andExpect(c -> assertTrustListItem(c, certDscEuDeleted, "EU", CertificateTypeDto.DSC, null, true)) + .andExpect(c -> assertTrustListItem(c, certCscaDe, "DE", CertificateTypeDto.CSCA, null)) + .andExpect(c -> assertTrustListItem(c, certCscaEu, "EU", CertificateTypeDto.CSCA, null)) + .andExpect(c -> assertTrustListItem(c, certUploadDe, "DE", CertificateTypeDto.UPLOAD, null)) + .andExpect(c -> assertTrustListItem(c, certUploadEu, "EU", CertificateTypeDto.UPLOAD, null)) + .andExpect(c -> assertTrustListItem(c, certAuthDe, "DE", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListItem(c, certAuthEu, "EU", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListItem(c, certCscaDe2, "DE", CertificateTypeDto.CSCA, null)) + .andExpect(c -> assertTrustListItem(c, certCscaEu2, "EU", CertificateTypeDto.CSCA, null)) + .andExpect(c -> assertTrustListItem(c, certUploadDe2, "DE", CertificateTypeDto.UPLOAD, null)) + .andExpect(c -> assertTrustListItem(c, certUploadEu2, "EU", CertificateTypeDto.UPLOAD, null)) + .andExpect(c -> assertTrustListItem(c, certAuthDe2, "DE", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListItem(c, certAuthEu2, "EU", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListLength(c, 17)); mockMvc.perform(get("/trustList") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(IF_MODIFIED_SINCE_HEADER, nowMinusOneMinute) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListLength(c, 8)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(IF_MODIFIED_SINCE_HEADER, nowMinusOneMinute) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListLength(c, 8)); } + @Test void testTrustListDownloadNoFilterPageable() throws Exception { prepareTestCertsCreatedAtNowMinusOneHour(); String authCertHash = trustedPartyTestHelper.getHash(TrustedPartyEntity.CertificateType.AUTHENTICATION, countryCode); mockMvc.perform(get("/trustList?page=0&pagesize=100") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certDscDe, "DE", CertificateTypeDto.DSC, "sig1")) - .andExpect(c -> assertTrustListItem(c, certDscEu, "EU", CertificateTypeDto.DSC, "sig2")) - .andExpect(c -> assertTrustListItem(c, certDscDe2, "DE", CertificateTypeDto.DSC, "sig3")) - .andExpect(c -> assertTrustListItem(c, certDscEu2, "EU", CertificateTypeDto.DSC, "sig4")) - .andExpect(c -> assertTrustListItem(c, certCscaDe, "DE", CertificateTypeDto.CSCA, null)) - .andExpect(c -> assertTrustListItem(c, certCscaEu, "EU", CertificateTypeDto.CSCA, null)) - .andExpect(c -> assertTrustListItem(c, certUploadDe, "DE", CertificateTypeDto.UPLOAD, null)) - .andExpect(c -> assertTrustListItem(c, certUploadEu, "EU", CertificateTypeDto.UPLOAD, null)) - .andExpect(c -> assertTrustListItem(c, certAuthDe, "DE", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListItem(c, certAuthEu, "EU", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListItem(c, certCscaDe2, "DE", CertificateTypeDto.CSCA, null)) - .andExpect(c -> assertTrustListItem(c, certCscaEu2, "EU", CertificateTypeDto.CSCA, null)) - .andExpect(c -> assertTrustListItem(c, certUploadDe2, "DE", CertificateTypeDto.UPLOAD, null)) - .andExpect(c -> assertTrustListItem(c, certUploadEu2, "EU", CertificateTypeDto.UPLOAD, null)) - .andExpect(c -> assertTrustListItem(c, certAuthDe2, "DE", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListItem(c, certAuthEu2, "EU", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListLength(c, 16)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certDscDe, "DE", CertificateTypeDto.DSC, "sig1")) + .andExpect(c -> assertTrustListItem(c, certDscEu, "EU", CertificateTypeDto.DSC, "sig2")) + .andExpect(c -> assertTrustListItem(c, certDscDe2, "DE", CertificateTypeDto.DSC, "sig3")) + .andExpect(c -> assertTrustListItem(c, certDscEu2, "EU", CertificateTypeDto.DSC, "sig4")) + .andExpect(c -> assertTrustListItem(c, certCscaDe, "DE", CertificateTypeDto.CSCA, null)) + .andExpect(c -> assertTrustListItem(c, certCscaEu, "EU", CertificateTypeDto.CSCA, null)) + .andExpect(c -> assertTrustListItem(c, certUploadDe, "DE", CertificateTypeDto.UPLOAD, null)) + .andExpect(c -> assertTrustListItem(c, certUploadEu, "EU", CertificateTypeDto.UPLOAD, null)) + .andExpect(c -> assertTrustListItem(c, certAuthDe, "DE", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListItem(c, certAuthEu, "EU", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListItem(c, certCscaDe2, "DE", CertificateTypeDto.CSCA, null)) + .andExpect(c -> assertTrustListItem(c, certCscaEu2, "EU", CertificateTypeDto.CSCA, null)) + .andExpect(c -> assertTrustListItem(c, certUploadDe2, "DE", CertificateTypeDto.UPLOAD, null)) + .andExpect(c -> assertTrustListItem(c, certUploadEu2, "EU", CertificateTypeDto.UPLOAD, null)) + .andExpect(c -> assertTrustListItem(c, certAuthDe2, "DE", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListItem(c, certAuthEu2, "EU", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListLength(c, 16)); } @Test @@ -213,55 +215,45 @@ void testTrustListDownloadNoFilterIsSincePageable() throws Exception { prepareTestCertsCreatedAtNowMinusOneHour(); String authCertHash = trustedPartyTestHelper.getHash(TrustedPartyEntity.CertificateType.AUTHENTICATION, countryCode); - mockMvc.perform(get("/trustList?page=-1&pagesize=10") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(IF_MODIFIED_SINCE_HEADER, nowMinusOneHour) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListLength(c, 17)); - mockMvc.perform(get("/trustList?page=0&pagesize=10") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(IF_MODIFIED_SINCE_HEADER, nowMinusOneHour) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListLength(c, 10)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(IF_MODIFIED_SINCE_HEADER, nowMinusOneHour) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListLength(c, 10)); mockMvc.perform(get("/trustList?page=0&pagesize=100") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(IF_MODIFIED_SINCE_HEADER, nowMinusOneMinute) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListLength(c, 8)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(IF_MODIFIED_SINCE_HEADER, nowMinusOneMinute) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListLength(c, 8)); mockMvc.perform(get("/trustList?page=1&pagesize=5") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(IF_MODIFIED_SINCE_HEADER, nowMinusOneMinute) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListLength(c, 3)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(IF_MODIFIED_SINCE_HEADER, nowMinusOneMinute) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListLength(c, 3)); mockMvc.perform(get("/trustList?page=2&pagesize=10") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(IF_MODIFIED_SINCE_HEADER, nowMinusOneMinute) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListLength(c, 0)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(IF_MODIFIED_SINCE_HEADER, nowMinusOneMinute) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListLength(c, 0)); } @Test @@ -270,49 +262,49 @@ void testTrustListDownloadNoFilterByTypeAndCountryIsSincePageable() throws Excep String authCertHash = trustedPartyTestHelper.getHash(TrustedPartyEntity.CertificateType.AUTHENTICATION, countryCode); mockMvc.perform(get("/trustList/AUTHENTICATION") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(IF_MODIFIED_SINCE_HEADER, nowMinusOneHour) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certAuthDe, "DE", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListItem(c, certAuthEu, "EU", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListItem(c, certAuthDe2, "DE", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListItem(c, certAuthEu2, "EU", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListLength(c, 4)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(IF_MODIFIED_SINCE_HEADER, nowMinusOneHour) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certAuthDe, "DE", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListItem(c, certAuthEu, "EU", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListItem(c, certAuthDe2, "DE", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListItem(c, certAuthEu2, "EU", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListLength(c, 4)); mockMvc.perform(get("/trustList/AUTHENTICATION/DE") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certAuthDe, "DE", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListItem(c, certAuthDe2, "DE", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListLength(c, 2)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certAuthDe, "DE", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListItem(c, certAuthDe2, "DE", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListLength(c, 2)); mockMvc.perform(get("/trustList/DSC?page=0&pagesize=10") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(IF_MODIFIED_SINCE_HEADER, nowMinusOneMinute) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListLength(c, 2)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(IF_MODIFIED_SINCE_HEADER, nowMinusOneMinute) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListLength(c, 2)); mockMvc.perform(get("/trustList/DSC/DE?page=0&pagesize=10") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(IF_MODIFIED_SINCE_HEADER, nowMinusOneMinute) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListLength(c, 1)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(IF_MODIFIED_SINCE_HEADER, nowMinusOneMinute) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListLength(c, 1)); } @Test @@ -320,21 +312,21 @@ void testTrustListDownloadNoFilter() throws Exception { String authCertHash = trustedPartyTestHelper.getHash(TrustedPartyEntity.CertificateType.AUTHENTICATION, countryCode); mockMvc.perform(get("/trustList") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certDscDe, "DE", CertificateTypeDto.DSC, "sig1")) - .andExpect(c -> assertTrustListItem(c, certDscEu, "EU", CertificateTypeDto.DSC, "sig2")) - .andExpect(c -> assertTrustListItem(c, certCscaDe, "DE", CertificateTypeDto.CSCA, null)) - .andExpect(c -> assertTrustListItem(c, certCscaEu, "EU", CertificateTypeDto.CSCA, null)) - .andExpect(c -> assertTrustListItem(c, certUploadDe, "DE", CertificateTypeDto.UPLOAD, null)) - .andExpect(c -> assertTrustListItem(c, certUploadEu, "EU", CertificateTypeDto.UPLOAD, null)) - .andExpect(c -> assertTrustListItem(c, certAuthDe, "DE", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListItem(c, certAuthEu, "EU", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListLength(c, 8)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certDscDe, "DE", CertificateTypeDto.DSC, "sig1")) + .andExpect(c -> assertTrustListItem(c, certDscEu, "EU", CertificateTypeDto.DSC, "sig2")) + .andExpect(c -> assertTrustListItem(c, certCscaDe, "DE", CertificateTypeDto.CSCA, null)) + .andExpect(c -> assertTrustListItem(c, certCscaEu, "EU", CertificateTypeDto.CSCA, null)) + .andExpect(c -> assertTrustListItem(c, certUploadDe, "DE", CertificateTypeDto.UPLOAD, null)) + .andExpect(c -> assertTrustListItem(c, certUploadEu, "EU", CertificateTypeDto.UPLOAD, null)) + .andExpect(c -> assertTrustListItem(c, certAuthDe, "DE", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListItem(c, certAuthEu, "EU", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListLength(c, 8)); } @Test @@ -342,48 +334,48 @@ void testTrustListDownloadFilterByType() throws Exception { String authCertHash = trustedPartyTestHelper.getHash(TrustedPartyEntity.CertificateType.AUTHENTICATION, countryCode); mockMvc.perform(get("/trustList/AUTHENTICATION") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certAuthDe, "DE", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListItem(c, certAuthEu, "EU", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListLength(c, 2)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certAuthDe, "DE", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListItem(c, certAuthEu, "EU", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListLength(c, 2)); mockMvc.perform(get("/trustList/UPLOAD") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certUploadDe, "DE", CertificateTypeDto.UPLOAD, null)) - .andExpect(c -> assertTrustListItem(c, certUploadEu, "EU", CertificateTypeDto.UPLOAD, null)) - .andExpect(c -> assertTrustListLength(c, 2)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certUploadDe, "DE", CertificateTypeDto.UPLOAD, null)) + .andExpect(c -> assertTrustListItem(c, certUploadEu, "EU", CertificateTypeDto.UPLOAD, null)) + .andExpect(c -> assertTrustListLength(c, 2)); mockMvc.perform(get("/trustList/CSCA") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certCscaDe, "DE", CertificateTypeDto.CSCA, null)) - .andExpect(c -> assertTrustListItem(c, certCscaEu, "EU", CertificateTypeDto.CSCA, null)) - .andExpect(c -> assertTrustListLength(c, 2)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certCscaDe, "DE", CertificateTypeDto.CSCA, null)) + .andExpect(c -> assertTrustListItem(c, certCscaEu, "EU", CertificateTypeDto.CSCA, null)) + .andExpect(c -> assertTrustListLength(c, 2)); mockMvc.perform(get("/trustList/DSC") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certDscDe, "DE", CertificateTypeDto.DSC, "sig1")) - .andExpect(c -> assertTrustListItem(c, certDscEu, "EU", CertificateTypeDto.DSC, "sig2")) - .andExpect(c -> assertTrustListLength(c, 2)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certDscDe, "DE", CertificateTypeDto.DSC, "sig1")) + .andExpect(c -> assertTrustListItem(c, certDscEu, "EU", CertificateTypeDto.DSC, "sig2")) + .andExpect(c -> assertTrustListLength(c, 2)); } @Test @@ -391,48 +383,48 @@ void testTrustListDownloadFilterByTypeCaseInsensitive() throws Exception { String authCertHash = trustedPartyTestHelper.getHash(TrustedPartyEntity.CertificateType.AUTHENTICATION, countryCode); mockMvc.perform(get("/trustList/aUtHeNtiCaTiOn") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certAuthDe, "DE", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListItem(c, certAuthEu, "EU", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListLength(c, 2)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certAuthDe, "DE", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListItem(c, certAuthEu, "EU", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListLength(c, 2)); mockMvc.perform(get("/trustList/uploAd") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certUploadDe, "DE", CertificateTypeDto.UPLOAD, null)) - .andExpect(c -> assertTrustListItem(c, certUploadEu, "EU", CertificateTypeDto.UPLOAD, null)) - .andExpect(c -> assertTrustListLength(c, 2)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certUploadDe, "DE", CertificateTypeDto.UPLOAD, null)) + .andExpect(c -> assertTrustListItem(c, certUploadEu, "EU", CertificateTypeDto.UPLOAD, null)) + .andExpect(c -> assertTrustListLength(c, 2)); mockMvc.perform(get("/trustList/csCA") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certCscaDe, "DE", CertificateTypeDto.CSCA, null)) - .andExpect(c -> assertTrustListItem(c, certCscaEu, "EU", CertificateTypeDto.CSCA, null)) - .andExpect(c -> assertTrustListLength(c, 2)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certCscaDe, "DE", CertificateTypeDto.CSCA, null)) + .andExpect(c -> assertTrustListItem(c, certCscaEu, "EU", CertificateTypeDto.CSCA, null)) + .andExpect(c -> assertTrustListLength(c, 2)); mockMvc.perform(get("/trustList/dsc") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certDscDe, "DE", CertificateTypeDto.DSC, "sig1")) - .andExpect(c -> assertTrustListItem(c, certDscEu, "EU", CertificateTypeDto.DSC, "sig2")) - .andExpect(c -> assertTrustListLength(c, 2)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certDscDe, "DE", CertificateTypeDto.DSC, "sig1")) + .andExpect(c -> assertTrustListItem(c, certDscEu, "EU", CertificateTypeDto.DSC, "sig2")) + .andExpect(c -> assertTrustListLength(c, 2)); } @Test @@ -440,84 +432,84 @@ void testTrustListDownloadFilterByTypeAndCountry() throws Exception { String authCertHash = trustedPartyTestHelper.getHash(TrustedPartyEntity.CertificateType.AUTHENTICATION, countryCode); mockMvc.perform(get("/trustList/AUTHENTICATION/DE") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certAuthDe, "DE", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListLength(c, 1)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certAuthDe, "DE", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListLength(c, 1)); mockMvc.perform(get("/trustList/AUTHENTICATION/EU") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certAuthEu, "EU", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListLength(c, 1)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certAuthEu, "EU", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListLength(c, 1)); mockMvc.perform(get("/trustList/UPLOAD/DE") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certUploadDe, "DE", CertificateTypeDto.UPLOAD, null)) - .andExpect(c -> assertTrustListLength(c, 1)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certUploadDe, "DE", CertificateTypeDto.UPLOAD, null)) + .andExpect(c -> assertTrustListLength(c, 1)); mockMvc.perform(get("/trustList/UPLOAD/EU") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certUploadEu, "EU", CertificateTypeDto.UPLOAD, null)) - .andExpect(c -> assertTrustListLength(c, 1)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certUploadEu, "EU", CertificateTypeDto.UPLOAD, null)) + .andExpect(c -> assertTrustListLength(c, 1)); mockMvc.perform(get("/trustList/CSCA/DE") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certCscaDe, "DE", CertificateTypeDto.CSCA, null)) - .andExpect(c -> assertTrustListLength(c, 1)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certCscaDe, "DE", CertificateTypeDto.CSCA, null)) + .andExpect(c -> assertTrustListLength(c, 1)); mockMvc.perform(get("/trustList/CSCA/EU") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certCscaEu, "EU", CertificateTypeDto.CSCA, null)) - .andExpect(c -> assertTrustListLength(c, 1)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certCscaEu, "EU", CertificateTypeDto.CSCA, null)) + .andExpect(c -> assertTrustListLength(c, 1)); mockMvc.perform(get("/trustList/DSC/DE") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certDscDe, "DE", CertificateTypeDto.DSC, "sig1")) - .andExpect(c -> assertTrustListLength(c, 1)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certDscDe, "DE", CertificateTypeDto.DSC, "sig1")) + .andExpect(c -> assertTrustListLength(c, 1)); mockMvc.perform(get("/trustList/DSC/EU") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certDscEu, "EU", CertificateTypeDto.DSC, "sig2")) - .andExpect(c -> assertTrustListLength(c, 1)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certDscEu, "EU", CertificateTypeDto.DSC, "sig2")) + .andExpect(c -> assertTrustListLength(c, 1)); } @Test @@ -525,84 +517,84 @@ void testTrustListDownloadFilterByTypeAndCountryLowercase() throws Exception { String authCertHash = trustedPartyTestHelper.getHash(TrustedPartyEntity.CertificateType.AUTHENTICATION, countryCode); mockMvc.perform(get("/trustList/AUTHENTICATION/de") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certAuthDe, "DE", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListLength(c, 1)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certAuthDe, "DE", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListLength(c, 1)); mockMvc.perform(get("/trustList/AUTHENTICATION/eu") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certAuthEu, "EU", CertificateTypeDto.AUTHENTICATION, null)) - .andExpect(c -> assertTrustListLength(c, 1)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certAuthEu, "EU", CertificateTypeDto.AUTHENTICATION, null)) + .andExpect(c -> assertTrustListLength(c, 1)); mockMvc.perform(get("/trustList/UPLOAD/de") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certUploadDe, "DE", CertificateTypeDto.UPLOAD, null)) - .andExpect(c -> assertTrustListLength(c, 1)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certUploadDe, "DE", CertificateTypeDto.UPLOAD, null)) + .andExpect(c -> assertTrustListLength(c, 1)); mockMvc.perform(get("/trustList/UPLOAD/eu") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certUploadEu, "EU", CertificateTypeDto.UPLOAD, null)) - .andExpect(c -> assertTrustListLength(c, 1)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certUploadEu, "EU", CertificateTypeDto.UPLOAD, null)) + .andExpect(c -> assertTrustListLength(c, 1)); mockMvc.perform(get("/trustList/CSCA/de") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certCscaDe, "DE", CertificateTypeDto.CSCA, null)) - .andExpect(c -> assertTrustListLength(c, 1)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certCscaDe, "DE", CertificateTypeDto.CSCA, null)) + .andExpect(c -> assertTrustListLength(c, 1)); mockMvc.perform(get("/trustList/CSCA/eu") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certCscaEu, "EU", CertificateTypeDto.CSCA, null)) - .andExpect(c -> assertTrustListLength(c, 1)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certCscaEu, "EU", CertificateTypeDto.CSCA, null)) + .andExpect(c -> assertTrustListLength(c, 1)); mockMvc.perform(get("/trustList/DSC/de") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certDscDe, "DE", CertificateTypeDto.DSC, "sig1")) - .andExpect(c -> assertTrustListLength(c, 1)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certDscDe, "DE", CertificateTypeDto.DSC, "sig1")) + .andExpect(c -> assertTrustListLength(c, 1)); mockMvc.perform(get("/trustList/DSC/eu") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(c -> assertTrustListItem(c, certDscEu, "EU", CertificateTypeDto.DSC, "sig2")) - .andExpect(c -> assertTrustListLength(c, 1)); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListItem(c, certDscEu, "EU", CertificateTypeDto.DSC, "sig2")) + .andExpect(c -> assertTrustListLength(c, 1)); } @Test @@ -612,13 +604,13 @@ void testTrustListDownloadEmptyList() throws Exception { signerInformationRepository.deleteAll(); mockMvc.perform(get("/trustList/DSC") - .accept(MediaType.APPLICATION_JSON_VALUE) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) - .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) - ) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(content().json("[]")); + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().json("[]")); } @Test @@ -689,6 +681,55 @@ void testBadRequests(String url) throws Exception { .andExpect(status().isBadRequest()); } + @Test + void testTrustListDownloadPageableDefaultFallback() throws Exception { + prepareTestCertsCreatedAtNowMinusOneHour(); + String authCertHash = trustedPartyTestHelper.getHash(TrustedPartyEntity.CertificateType.AUTHENTICATION, countryCode); + + mockMvc.perform(get("/trustList?pagesize=5") + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListLength(c, 5)); + + KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("ec"); + for (int i = 0; i < 120; i++) { + signerInformationTestHelper.createSignerInformationInDB( + "DE", "sigN" + i, CertificateTestUtils.generateCertificate(keyPairGenerator.generateKeyPair(), + "EU", "EUTest"), nowMinusOneHour.minusSeconds(i)); + } + + mockMvc.perform(get("/trustList") + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListLength(c, 136)); + + mockMvc.perform(get("/trustList?page=0") + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListLength(c, 100)); + + mockMvc.perform(get("/trustList?page=1") + .accept(MediaType.APPLICATION_JSON_VALUE) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash) + .header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject) + ) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(c -> assertTrustListLength(c, 36)); + } + private void prepareTestCertsCreatedAtNowMinusOneHour() throws Exception { KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("ec"); certDscDe2 = CertificateTestUtils.generateCertificate(keyPairGenerator.generateKeyPair(), @@ -698,8 +739,8 @@ private void prepareTestCertsCreatedAtNowMinusOneHour() throws Exception { certDscEuDeleted = CertificateTestUtils.generateCertificate(keyPairGenerator.generateKeyPair(), "EU", "EUTestDeleted"); signerInformationTestHelper.createSignerInformationInDB("DE", "sig3", certDscDe2, nowMinusOneHour); - signerInformationTestHelper.createSignerInformationInDB("EU", "sig4",certDscEu2, nowMinusOneHour); - signerInformationTestHelper.createSignerInformationInDB("EU", "sig5_deleted",certDscEuDeleted, now.minusHours(2), nowMinusOneHour); + signerInformationTestHelper.createSignerInformationInDB("EU", "sig4", certDscEu2, nowMinusOneHour); + signerInformationTestHelper.createSignerInformationInDB("EU", "sig5_deleted", certDscEuDeleted, now.minusHours(2), nowMinusOneHour); certUploadDe2 = trustedPartyTestHelper.getTestCert("test1", TrustedPartyEntity.CertificateType.UPLOAD, "DE", nowMinusOneHour); certCscaDe2 = trustedPartyTestHelper.getTestCert("test2", TrustedPartyEntity.CertificateType.CSCA, "DE", nowMinusOneHour); @@ -715,14 +756,14 @@ private void assertTrustListItem(MvcResult result, X509Certificate certificate, private void assertTrustListItem(MvcResult result, X509Certificate certificate, String country, CertificateTypeDto certificateTypeDto, String signature, boolean deleted) throws CertificateEncodingException, UnsupportedEncodingException, JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper() - .registerModule(new JavaTimeModule()); + .registerModule(new JavaTimeModule()); List trustList = objectMapper.readValue(result.getResponse().getContentAsString(), new TypeReference<>() { }); Optional trustListOptional = trustList - .stream() - .filter(tl -> tl.getKid().equals(certificateUtils.getCertKid(certificate))) - .findFirst(); + .stream() + .filter(tl -> tl.getKid().equals(certificateUtils.getCertKid(certificate))) + .findFirst(); Assertions.assertTrue(trustListOptional.isPresent()); @@ -744,7 +785,7 @@ private void assertTrustListItem(MvcResult result, X509Certificate certificate, private void assertTrustListLength(MvcResult result, int expectedLength) throws UnsupportedEncodingException, JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper() - .registerModule(new JavaTimeModule()); + .registerModule(new JavaTimeModule()); List trustList = objectMapper.readValue(result.getResponse().getContentAsString(), new TypeReference<>() { }); Assertions.assertEquals(expectedLength, trustList.size());