From 4f8d9ab9d3a7e1d8b31e433e951bcb36289fccec Mon Sep 17 00:00:00 2001 From: Morphyum Date: Fri, 11 Mar 2022 10:57:27 +0100 Subject: [PATCH 01/11] * first version --- ...cGatewayRevocationListUploadConnector.java | 198 ++++++++++++++++++ .../client/DgcGatewayConnectorRestClient.java | 26 ++- .../dto/RevocationBatchDeleteRequestDto.java | 35 ++++ 3 files changed, 253 insertions(+), 6 deletions(-) create mode 100644 src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java create mode 100644 src/main/java/eu/europa/ec/dgc/gateway/connector/dto/RevocationBatchDeleteRequestDto.java diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java new file mode 100644 index 0000000..dca029a --- /dev/null +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java @@ -0,0 +1,198 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + +package eu.europa.ec.dgc.gateway.connector; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import eu.europa.ec.dgc.gateway.connector.client.DgcGatewayConnectorRestClient; +import eu.europa.ec.dgc.gateway.connector.config.DgcGatewayConnectorConfigProperties; +import eu.europa.ec.dgc.gateway.connector.dto.ProblemReportDto; +import eu.europa.ec.dgc.signing.SignedStringMessageBuilder; +import eu.europa.ec.dgc.utils.CertificateUtils; +import feign.FeignException; +import java.io.IOException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateEncodingException; +import java.security.cert.X509Certificate; +import javax.annotation.PostConstruct; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.bouncycastle.cert.X509CertificateHolder; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Lazy; +import org.springframework.context.annotation.Scope; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.stereotype.Service; + + +@ConditionalOnProperty("dgc.gateway.connector.enabled") +@Lazy +@Service +@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) +@RequiredArgsConstructor +@EnableScheduling +@Slf4j +public class DgcGatewayRevocationListUploadConnector { + + private final DgcGatewayConnectorRestClient dgcGatewayConnectorRestClient; + + private final DgcGatewayConnectorConfigProperties properties; + + private final CertificateUtils certificateUtils; + + @Qualifier("upload") + private final KeyStore uploadKeyStore; + + private X509CertificateHolder uploadCertificateHolder; + + private PrivateKey uploadCertificatePrivateKey; + + @PostConstruct + void init() throws KeyStoreException, CertificateEncodingException, IOException { + String uploadCertAlias = properties.getUploadKeyStore().getAlias(); + X509Certificate uploadCertificate = (X509Certificate) uploadKeyStore.getCertificate(uploadCertAlias); + + try { + uploadCertificatePrivateKey = + (PrivateKey) uploadKeyStore.getKey(uploadCertAlias, properties.getUploadKeyStore().getPassword()); + } catch (NoSuchAlgorithmException | UnrecoverableKeyException e) { + log.error("Failed to load PrivateKey from KeyStore"); + } + + if (uploadCertificatePrivateKey == null) { + log.error("Could not find UploadCertificate PrivateKey in Keystore"); + throw new KeyStoreException("Could not find UploadCertificate PrivateKey in Keystore"); + } + + if (uploadCertificate == null) { + log.error("Could not find UploadCertificate in Keystore"); + throw new KeyStoreException("Could not find UploadCertificate in Keystore"); + } + + uploadCertificateHolder = certificateUtils.convertCertificate(uploadCertificate); + } + + /** + * Uploads a JSON-File as RevocationBatch to DGC Gateway. + * + * @param json the JSON containing the ValidationRUle to upload. + * @throws DgcRevocationBatchUploadException with detailed information why the upload has failed. + */ + public void uploadRevocationBatch(String json) throws DgcRevocationBatchUploadException { + + String payload = new SignedStringMessageBuilder().withPayload(json) + .withSigningCertificate(uploadCertificateHolder, uploadCertificatePrivateKey).buildAsString(); + + try { + ResponseEntity response = dgcGatewayConnectorRestClient.uploadBatch(payload); + if (response.getStatusCode() == HttpStatus.CREATED) { + log.info("Successfully uploaded RevocationBatch"); + } + } catch (FeignException e) { + if (e.status() == HttpStatus.BAD_REQUEST.value()) { + handleBadRequest(e); + } else if (e.status() == HttpStatus.INTERNAL_SERVER_ERROR.value()) { + throw new DgcRevocationBatchUploadException(DgcRevocationBatchUploadException.Reason.SERVER_ERROR); + } else if (e.status() == HttpStatus.UNAUTHORIZED.value() || e.status() == HttpStatus.FORBIDDEN.value()) { + log.error("Client is not authorized. (Invalid Client Certificate)"); + throw new DgcRevocationBatchUploadException( + DgcRevocationBatchUploadException.Reason.INVALID_AUTHORIZATION); + } + } + } + + /** + * Deletes a RevocationBatch with given ID from DGC Gateway. + * + * @param ruleId The ID of the Rules to be deleted. + * @throws DgcRevocationBatchUploadException with detailed information why the delete has failed. + */ + public void deleteRevocationBatch(String ruleId) throws DgcRevocationBatchUploadException { + + String payload = new SignedStringMessageBuilder().withPayload(ruleId) + .withSigningCertificate(uploadCertificateHolder, uploadCertificatePrivateKey).buildAsString(); + + try { + ResponseEntity response = dgcGatewayConnectorRestClient.deleteBatch(payload); + if (response.getStatusCode() == HttpStatus.NO_CONTENT) { + log.info("Successfully deleted ValidationRule"); + } + } catch (FeignException e) { + if (e.status() == HttpStatus.BAD_REQUEST.value()) { + handleBadRequest(e); + } else if (e.status() == HttpStatus.INTERNAL_SERVER_ERROR.value()) { + throw new DgcRevocationBatchUploadException(DgcRevocationBatchUploadException.Reason.SERVER_ERROR); + } else if (e.status() == HttpStatus.UNAUTHORIZED.value() || e.status() == HttpStatus.FORBIDDEN.value()) { + log.error("Client is not authorized. (Invalid Client Certificate)"); + throw new DgcRevocationBatchUploadException( + DgcRevocationBatchUploadException.Reason.INVALID_AUTHORIZATION); + + } else if (e.status() == HttpStatus.NOT_FOUND.value()) { + log.info("ValidationRules with ID {} does not exists on DGCG", ruleId); + } + } + } + + private void handleBadRequest(FeignException e) throws DgcRevocationBatchUploadException { + if (e.responseBody().isPresent()) { + ObjectMapper objectMapper = new ObjectMapper(); + try { + ProblemReportDto problemReport = objectMapper.readValue(e.contentUTF8(), ProblemReportDto.class); + + throw new DgcRevocationBatchUploadException(DgcRevocationBatchUploadException.Reason.INVALID_BATCH, + String.format("%s: %s, %s", problemReport.getCode(), problemReport.getProblem(), + problemReport.getDetails())); + } catch (JsonProcessingException jsonException) { + throw new DgcRevocationBatchUploadException(DgcRevocationBatchUploadException.Reason.UNKNOWN_ERROR); + } + } + } + + public static class DgcRevocationBatchUploadException extends Exception { + + @Getter + private final Reason reason; + + public DgcRevocationBatchUploadException(Reason reason) { + super(); + this.reason = reason; + } + + public DgcRevocationBatchUploadException(Reason reason, String message) { + super(message); + this.reason = reason; + } + + public enum Reason { + UNKNOWN_ERROR, INVALID_AUTHORIZATION, INVALID_UPLOAD_CERT, INVALID_BATCH, SERVER_ERROR + } + } + +} diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/client/DgcGatewayConnectorRestClient.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/client/DgcGatewayConnectorRestClient.java index a673b64..2cf7a92 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/connector/client/DgcGatewayConnectorRestClient.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/client/DgcGatewayConnectorRestClient.java @@ -40,9 +40,9 @@ @ConditionalOnProperty("dgc.gateway.connector.enabled") @FeignClient( - name = "dgc-gateway-connector", - url = "${dgc.gateway.connector.endpoint}", - configuration = DgcGatewayConnectorRestClientConfig.class + name = "dgc-gateway-connector", + url = "${dgc.gateway.connector.endpoint}", + configuration = DgcGatewayConnectorRestClientConfig.class ) public interface DgcGatewayConnectorRestClient { @@ -124,12 +124,11 @@ public interface DgcGatewayConnectorRestClient { /** - * Downloads a batch list from the revocation list. - * + * Downloads a batch list from the revocation list. */ @GetMapping(value = "/revocation-list", produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity downloadRevocationList( - @RequestHeader(HttpHeaders.IF_MODIFIED_SINCE) String lastUpdate); + @RequestHeader(HttpHeaders.IF_MODIFIED_SINCE) String lastUpdate); /** * Downloads a batch of the revocation list. @@ -140,4 +139,19 @@ ResponseEntity downloadRevocationList( @GetMapping(value = "/revocation-list/{batchId}", produces = {"application/cms-text"}) ResponseEntity downloadBatch(@PathVariable("batchId") String batchId); + /** + * Uploads a batch to the revocation list. + * + * @param batch the CMS signed Batch JSON. + */ + @PostMapping(value = "/revocation-list", consumes = "application/cms-text") + ResponseEntity uploadBatch(@RequestBody String batch); + + /** + * Deletes a batch from the revocation list. + * + * @param batch the CMS signed Batch Identifier. + */ + @DeleteMapping(value = "/revocation-list", consumes = "application/cms-text") + ResponseEntity deleteBatch(@RequestBody String batch); } diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/dto/RevocationBatchDeleteRequestDto.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/dto/RevocationBatchDeleteRequestDto.java new file mode 100644 index 0000000..ab923aa --- /dev/null +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/dto/RevocationBatchDeleteRequestDto.java @@ -0,0 +1,35 @@ +/*- + * ---license-start + * eu-digital-green-certificates / dgc-lib + * --- + * Copyright (C) 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + +package eu.europa.ec.dgc.gateway.connector.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class RevocationBatchDeleteRequestDto { + + private String batchId; + +} From 0bd54127efda5b0b1e71ac3ae18e6840b24000cf Mon Sep 17 00:00:00 2001 From: Morphyum Date: Fri, 11 Mar 2022 11:17:55 +0100 Subject: [PATCH 02/11] * copied and adjusted tests for new uploads --- .../RevocationListUploadConnectorTest.java | 322 ++++++++++++++++++ 1 file changed, 322 insertions(+) create mode 100644 src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListUploadConnectorTest.java diff --git a/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListUploadConnectorTest.java b/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListUploadConnectorTest.java new file mode 100644 index 0000000..33a60b7 --- /dev/null +++ b/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListUploadConnectorTest.java @@ -0,0 +1,322 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + +package eu.europa.ec.dgc.gateway.connector; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import eu.europa.ec.dgc.gateway.connector.client.DgcGatewayConnectorRestClient; +import eu.europa.ec.dgc.signing.SignedStringMessageParser; +import eu.europa.ec.dgc.testdata.DgcTestKeyStore; +import eu.europa.ec.dgc.utils.CertificateUtils; +import feign.FeignException; +import feign.Request; +import feign.RequestTemplate; +import java.nio.charset.StandardCharsets; +import java.security.KeyStoreException; +import java.security.PrivateKey; +import java.security.cert.X509Certificate; +import java.util.HashMap; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +@SpringBootTest +@Slf4j +class RevocationListUploadConnectorTest { + + @MockBean + DgcGatewayConnectorRestClient restClientMock; + + @Autowired + DgcGatewayRevocationListUploadConnector connector; + + @Autowired + CertificateUtils certificateUtils; + + @Autowired + DgcTestKeyStore testKeyStore; + + + @Test + void testUploadOfRevocationList() throws Exception { + String dummyRevocationList = "dummyRevocationList"; + + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(String.class); + + when(restClientMock.uploadBatch(argumentCaptor.capture())) + .thenReturn(ResponseEntity.status(HttpStatus.CREATED).build()); + + connector.uploadRevocationBatch(dummyRevocationList); + + verify(restClientMock).uploadBatch(any()); + + SignedStringMessageParser parser = new SignedStringMessageParser(argumentCaptor.getValue()); + + Assertions.assertEquals(dummyRevocationList, parser.getPayload()); + Assertions.assertEquals(certificateUtils.convertCertificate(testKeyStore.getUpload()), + parser.getSigningCertificate()); + } + + @Test + void testDeleteCertificates() throws Exception { + String dummyRevocationListId = "Revo1234"; + + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(String.class); + + when(restClientMock.deleteBatch(argumentCaptor.capture())) + .thenReturn(ResponseEntity.status(HttpStatus.NO_CONTENT).build()); + + connector.deleteRevocationBatch(dummyRevocationListId); + + verify(restClientMock).deleteBatch(any()); + + SignedStringMessageParser parser = new SignedStringMessageParser(argumentCaptor.getValue()); + + Assertions.assertEquals(dummyRevocationListId, parser.getPayload()); + Assertions.assertEquals(certificateUtils.convertCertificate(testKeyStore.getUpload()), + parser.getSigningCertificate()); + } + + @Test + void initShouldFailWithoutCertificates() { + X509Certificate uploadCertBackup = testKeyStore.getUpload(); + testKeyStore.setUpload(null); + + Assertions.assertThrows(KeyStoreException.class, connector::init); + + testKeyStore.setUpload(uploadCertBackup); + + PrivateKey uploadPrivateKeyBackup = testKeyStore.getUploadPrivateKey(); + testKeyStore.setUploadPrivateKey(null); + + Assertions.assertThrows(KeyStoreException.class, connector::init); + + testKeyStore.setUploadPrivateKey(uploadPrivateKeyBackup); + + Assertions.assertDoesNotThrow(connector::init); + } + + @Test + void shouldThrowAnExceptionWhenUploadRequestFailed() { + String dummyRevocationList = "dummyRevocationList"; + + String problemReport = "{" + + "\"code\": \"0x500\"," + + "\"problem\": \"problem\"," + + "\"sendValue\": \"val\"," + + "\"details\": \"details\"" + + "}"; + + + doThrow(new FeignException.BadRequest("", dummyRequest(), problemReport.getBytes(StandardCharsets.UTF_8), null)) + .when(restClientMock).uploadBatch(any()); + + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException e = + Assertions.assertThrows(DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.class, + () -> connector.uploadRevocationBatch(dummyRevocationList)); + + Assertions.assertEquals( + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.INVALID_BATCH, e.getReason()); + } + + @Test + void shouldThrowAnExceptionWhenUploadRequestFailedWithBadJson() { + String dummyRevocationList = "dummyRevocationList"; + + String problemReport = "{" + + "code: \"0x500\"," + + "problem: \"problem\"," + + "sendValue: \"val\"," + + "details: \"details\"" + + "}"; + + + doThrow(new FeignException.BadRequest("", dummyRequest(), problemReport.getBytes(StandardCharsets.UTF_8), null)) + .when(restClientMock).uploadBatch(any()); + + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException e = + Assertions.assertThrows(DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.class, + () -> connector.uploadRevocationBatch(dummyRevocationList)); + + Assertions.assertEquals( + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.UNKNOWN_ERROR, e.getReason()); + } + + @Test + void shouldThrowAnExceptionWhenUploadRequestGetsInternalServerError() { + String dummyRevocationList = "dummyRevocationList"; + + doThrow(new FeignException.InternalServerError("", dummyRequest(), null, null)) + .when(restClientMock).uploadBatch(any()); + + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException e = + Assertions.assertThrows(DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.class, + () -> connector.uploadRevocationBatch(dummyRevocationList)); + Assertions.assertEquals( + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.SERVER_ERROR, e.getReason()); + } + + @Test + void shouldThrowAnExceptionWhenUploadRequestGetsUnauthorizedError() { + String dummyRevocationList = "dummyRevocationList"; + + doThrow(new FeignException.Unauthorized("", dummyRequest(), null, null)) + .when(restClientMock).uploadBatch(any()); + + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException e = + Assertions.assertThrows(DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.class, + () -> connector.uploadRevocationBatch(dummyRevocationList)); + Assertions.assertEquals( + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.INVALID_AUTHORIZATION, + e.getReason()); + } + + @Test + void shouldThrowAnExceptionWhenUploadRequestGetsForbiddenError() { + String dummyRevocationList = "dummyRevocationList"; + + doThrow(new FeignException.Forbidden("", dummyRequest(), null, null)) + .when(restClientMock).uploadBatch(any()); + + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException e = + Assertions.assertThrows(DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.class, + () -> connector.uploadRevocationBatch(dummyRevocationList)); + Assertions.assertEquals( + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.INVALID_AUTHORIZATION, + e.getReason()); + } + + @Test + void shouldThrowAnExceptionWhenDeleteRequestFailed() { + String dummyRevocationList = "dummyRevocationList"; + + String problemReport = "{" + + "\"code\": \"0x500\"," + + "\"problem\": \"problem\"," + + "\"sendValue\": \"val\"," + + "\"details\": \"details\"" + + "}"; + + + doThrow(new FeignException.BadRequest("", dummyRequest(), problemReport.getBytes(StandardCharsets.UTF_8), null)) + .when(restClientMock).deleteBatch(any()); + + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException e = + Assertions.assertThrows(DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.class, + () -> connector.deleteRevocationBatch(dummyRevocationList)); + + Assertions.assertEquals( + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.INVALID_BATCH, e.getReason()); + } + + @Test + void shouldThrowAnExceptionWhenDeleteRequestFailedWithBadJson() { + String dummyRevocationList = "dummyRevocationList"; + + String problemReport = "{" + + "code: \"0x500\"," + + "problem: \"problem\"," + + "sendValue: \"val\"," + + "details: \"details\"" + + "}"; + + + doThrow(new FeignException.BadRequest("", dummyRequest(), problemReport.getBytes(StandardCharsets.UTF_8), null)) + .when(restClientMock).deleteBatch(any()); + + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException e = + Assertions.assertThrows(DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.class, + () -> connector.deleteRevocationBatch(dummyRevocationList)); + + Assertions.assertEquals( + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.UNKNOWN_ERROR, e.getReason()); + } + + @Test + void shouldThrowAnExceptionWhenDeleteRequestGetsInternalServerError() { + String dummyRevocationList = "dummyRevocationList"; + + doThrow(new FeignException.InternalServerError("", dummyRequest(), null, null)) + .when(restClientMock).deleteBatch(any()); + + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException e = + Assertions.assertThrows(DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.class, + () -> connector.deleteRevocationBatch(dummyRevocationList)); + Assertions.assertEquals( + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.SERVER_ERROR, e.getReason()); + } + + @Test + void shouldThrowAnExceptionWhenDeleteRequestGetsUnauthorizedError() { + String dummyRevocationList = "dummyRevocationList"; + + doThrow(new FeignException.Unauthorized("", dummyRequest(), null, null)) + .when(restClientMock).deleteBatch(any()); + + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException e = + Assertions.assertThrows(DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.class, + () -> connector.deleteRevocationBatch(dummyRevocationList)); + Assertions.assertEquals( + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.INVALID_AUTHORIZATION, + e.getReason()); + } + + @Test + void shouldThrowAnExceptionWhenDeleteRequestGetsForbiddenError() { + String dummyRevocationList = "dummyRevocationList"; + + doThrow(new FeignException.Forbidden("", dummyRequest(), null, null)) + .when(restClientMock).deleteBatch(any()); + + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException e = + Assertions.assertThrows(DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.class, + () -> connector.deleteRevocationBatch(dummyRevocationList)); + Assertions.assertEquals( + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.INVALID_AUTHORIZATION, + e.getReason()); + } + + @Test + void shouldNotThrowAnExceptionWhenDeleteRequestGetsNotFoundError() { + String dummyRevocationList = "dummyRevocationList"; + + doThrow(new FeignException.NotFound("", dummyRequest(), null, null)) + .when(restClientMock).deleteBatch(any()); + + Assertions.assertDoesNotThrow(() -> connector.deleteRevocationBatch(dummyRevocationList)); + } + + /** + * Method to create dummy request which is required to throw FeignExceptions. + */ + private Request dummyRequest() { + return Request.create(Request.HttpMethod.GET, "url", new HashMap<>(), null, new RequestTemplate()); + } +} From 2da5118796a0c45bd4544336b5800276747acbe8 Mon Sep 17 00:00:00 2001 From: Morphyum Date: Fri, 11 Mar 2022 11:20:42 +0100 Subject: [PATCH 03/11] * updated file headers for 2022 --- .../DgcGatewayDownloadConnectorBuilder.java | 20 +++++++++++++++++ ...atewayRevocationListDownloadConnector.java | 20 +++++++++++++++++ .../RevocationBatchDownloadException.java | 20 +++++++++++++++++ .../RevocationBatchGoneException.java | 20 +++++++++++++++++ .../RevocationBatchParseException.java | 20 +++++++++++++++++ .../DgcFeignClientBuilder.java | 20 +++++++++++++++++ .../DgcFeignClientFactoryBean.java | 20 +++++++++++++++++ .../DgcFeignClientRegistrar.java | 20 +++++++++++++++++ .../ec/dgc/generation/Base45Encoder.java | 20 +++++++++++++++++ .../europa/ec/dgc/generation/CopyDigest.java | 20 +++++++++++++++++ .../ec/dgc/generation/DccBuilderBase.java | 20 +++++++++++++++++ .../ec/dgc/generation/DccRecoveryBuilder.java | 20 +++++++++++++++++ .../ec/dgc/generation/DccTestBuilder.java | 20 +++++++++++++++++ .../dgc/generation/DccVaccinationBuilder.java | 20 +++++++++++++++++ .../dgc/generation/DgcCryptedFinalizer.java | 20 +++++++++++++++++ .../dgc/generation/DgcCryptedPublisher.java | 20 +++++++++++++++++ .../ec/dgc/generation/DgcGenerator.java | 20 +++++++++++++++++ .../europa/ec/dgc/generation/DgcSigner.java | 20 +++++++++++++++++ .../ec/dgc/generation/DgciGenerator.java | 20 +++++++++++++++++ .../europa/ec/dgc/generation/dto/DgcData.java | 20 +++++++++++++++++ .../ec/dgc/generation/dto/DgcInitData.java | 20 +++++++++++++++++ .../DownloadConnectorBuilderTest.java | 20 +++++++++++++++++ .../RevocationListDownloadConnectorTest.java | 22 ++++++++++++++++++- .../ec/dgc/generation/Base45EncoderTest.java | 20 +++++++++++++++++ .../generation/DccRecoveryBuilderTest.java | 20 +++++++++++++++++ .../ec/dgc/generation/DccTestBuilderTest.java | 22 ++++++++++++++++++- .../generation/DccVaccinationBuilderTest.java | 20 +++++++++++++++++ .../generation/DgcCryptedPublisherTest.java | 20 +++++++++++++++++ .../ec/dgc/generation/DgcSignerTest.java | 20 +++++++++++++++++ .../europa/ec/dgc/generation/KeyHelper.java | 20 +++++++++++++++++ templates/file-header.txt | 2 +- 31 files changed, 603 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayDownloadConnectorBuilder.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayDownloadConnectorBuilder.java index 178d9c4..313914b 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayDownloadConnectorBuilder.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayDownloadConnectorBuilder.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.gateway.connector; import eu.europa.ec.dgc.gateway.connector.client.DgcGatewayConnectorRestClient; diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListDownloadConnector.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListDownloadConnector.java index 81ce665..415b0b6 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListDownloadConnector.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListDownloadConnector.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.gateway.connector; diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/exception/RevocationBatchDownloadException.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/exception/RevocationBatchDownloadException.java index 61ea591..23dc2b4 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/connector/exception/RevocationBatchDownloadException.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/exception/RevocationBatchDownloadException.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.gateway.connector.exception; import lombok.Getter; diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/exception/RevocationBatchGoneException.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/exception/RevocationBatchGoneException.java index ce7d50b..2d6b520 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/connector/exception/RevocationBatchGoneException.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/exception/RevocationBatchGoneException.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.gateway.connector.exception; import lombok.Getter; diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/exception/RevocationBatchParseException.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/exception/RevocationBatchParseException.java index 5027a26..f3377e9 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/connector/exception/RevocationBatchParseException.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/exception/RevocationBatchParseException.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.gateway.connector.exception; import lombok.Getter; diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/springbootworkaroundforks/DgcFeignClientBuilder.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/springbootworkaroundforks/DgcFeignClientBuilder.java index bdec252..487736d 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/connector/springbootworkaroundforks/DgcFeignClientBuilder.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/springbootworkaroundforks/DgcFeignClientBuilder.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.gateway.connector.springbootworkaroundforks; import feign.Feign; diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/springbootworkaroundforks/DgcFeignClientFactoryBean.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/springbootworkaroundforks/DgcFeignClientFactoryBean.java index 82ded60..378a480 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/connector/springbootworkaroundforks/DgcFeignClientFactoryBean.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/springbootworkaroundforks/DgcFeignClientFactoryBean.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.gateway.connector.springbootworkaroundforks; import feign.Capability; diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/springbootworkaroundforks/DgcFeignClientRegistrar.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/springbootworkaroundforks/DgcFeignClientRegistrar.java index 98c238b..40d7aaf 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/connector/springbootworkaroundforks/DgcFeignClientRegistrar.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/springbootworkaroundforks/DgcFeignClientRegistrar.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.gateway.connector.springbootworkaroundforks; import feign.Request; diff --git a/src/main/java/eu/europa/ec/dgc/generation/Base45Encoder.java b/src/main/java/eu/europa/ec/dgc/generation/Base45Encoder.java index 0900030..dc43e8f 100644 --- a/src/main/java/eu/europa/ec/dgc/generation/Base45Encoder.java +++ b/src/main/java/eu/europa/ec/dgc/generation/Base45Encoder.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation; /** diff --git a/src/main/java/eu/europa/ec/dgc/generation/CopyDigest.java b/src/main/java/eu/europa/ec/dgc/generation/CopyDigest.java index a4c3bc8..12f553f 100644 --- a/src/main/java/eu/europa/ec/dgc/generation/CopyDigest.java +++ b/src/main/java/eu/europa/ec/dgc/generation/CopyDigest.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation; import java.io.ByteArrayOutputStream; diff --git a/src/main/java/eu/europa/ec/dgc/generation/DccBuilderBase.java b/src/main/java/eu/europa/ec/dgc/generation/DccBuilderBase.java index 5d291c3..e69273e 100644 --- a/src/main/java/eu/europa/ec/dgc/generation/DccBuilderBase.java +++ b/src/main/java/eu/europa/ec/dgc/generation/DccBuilderBase.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation; import com.fasterxml.jackson.databind.node.JsonNodeFactory; diff --git a/src/main/java/eu/europa/ec/dgc/generation/DccRecoveryBuilder.java b/src/main/java/eu/europa/ec/dgc/generation/DccRecoveryBuilder.java index c9c513b..10b6606 100644 --- a/src/main/java/eu/europa/ec/dgc/generation/DccRecoveryBuilder.java +++ b/src/main/java/eu/europa/ec/dgc/generation/DccRecoveryBuilder.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation; import com.fasterxml.jackson.databind.node.ArrayNode; diff --git a/src/main/java/eu/europa/ec/dgc/generation/DccTestBuilder.java b/src/main/java/eu/europa/ec/dgc/generation/DccTestBuilder.java index f621450..0e6da7f 100644 --- a/src/main/java/eu/europa/ec/dgc/generation/DccTestBuilder.java +++ b/src/main/java/eu/europa/ec/dgc/generation/DccTestBuilder.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation; import com.fasterxml.jackson.databind.node.ArrayNode; diff --git a/src/main/java/eu/europa/ec/dgc/generation/DccVaccinationBuilder.java b/src/main/java/eu/europa/ec/dgc/generation/DccVaccinationBuilder.java index 91ad01f..91903e0 100644 --- a/src/main/java/eu/europa/ec/dgc/generation/DccVaccinationBuilder.java +++ b/src/main/java/eu/europa/ec/dgc/generation/DccVaccinationBuilder.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation; import com.fasterxml.jackson.databind.node.ArrayNode; diff --git a/src/main/java/eu/europa/ec/dgc/generation/DgcCryptedFinalizer.java b/src/main/java/eu/europa/ec/dgc/generation/DgcCryptedFinalizer.java index cb396d3..25c7baa 100644 --- a/src/main/java/eu/europa/ec/dgc/generation/DgcCryptedFinalizer.java +++ b/src/main/java/eu/europa/ec/dgc/generation/DgcCryptedFinalizer.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation; import java.security.GeneralSecurityException; diff --git a/src/main/java/eu/europa/ec/dgc/generation/DgcCryptedPublisher.java b/src/main/java/eu/europa/ec/dgc/generation/DgcCryptedPublisher.java index 00d1496..0652443 100644 --- a/src/main/java/eu/europa/ec/dgc/generation/DgcCryptedPublisher.java +++ b/src/main/java/eu/europa/ec/dgc/generation/DgcCryptedPublisher.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation; import eu.europa.ec.dgc.generation.dto.DgcData; diff --git a/src/main/java/eu/europa/ec/dgc/generation/DgcGenerator.java b/src/main/java/eu/europa/ec/dgc/generation/DgcGenerator.java index 841e01b..c5bd245 100644 --- a/src/main/java/eu/europa/ec/dgc/generation/DgcGenerator.java +++ b/src/main/java/eu/europa/ec/dgc/generation/DgcGenerator.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation; import com.upokecenter.cbor.CBORObject; diff --git a/src/main/java/eu/europa/ec/dgc/generation/DgcSigner.java b/src/main/java/eu/europa/ec/dgc/generation/DgcSigner.java index cf8d2c2..7756d86 100644 --- a/src/main/java/eu/europa/ec/dgc/generation/DgcSigner.java +++ b/src/main/java/eu/europa/ec/dgc/generation/DgcSigner.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation; import com.upokecenter.cbor.CBORObject; diff --git a/src/main/java/eu/europa/ec/dgc/generation/DgciGenerator.java b/src/main/java/eu/europa/ec/dgc/generation/DgciGenerator.java index fc9b3c9..1a857ec 100644 --- a/src/main/java/eu/europa/ec/dgc/generation/DgciGenerator.java +++ b/src/main/java/eu/europa/ec/dgc/generation/DgciGenerator.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation; import java.math.BigInteger; diff --git a/src/main/java/eu/europa/ec/dgc/generation/dto/DgcData.java b/src/main/java/eu/europa/ec/dgc/generation/dto/DgcData.java index f3a2d67..d320a9d 100644 --- a/src/main/java/eu/europa/ec/dgc/generation/dto/DgcData.java +++ b/src/main/java/eu/europa/ec/dgc/generation/dto/DgcData.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation.dto; public class DgcData { diff --git a/src/main/java/eu/europa/ec/dgc/generation/dto/DgcInitData.java b/src/main/java/eu/europa/ec/dgc/generation/dto/DgcInitData.java index b61aec0..0ee2b15 100644 --- a/src/main/java/eu/europa/ec/dgc/generation/dto/DgcInitData.java +++ b/src/main/java/eu/europa/ec/dgc/generation/dto/DgcInitData.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation.dto; public class DgcInitData { diff --git a/src/test/java/eu/europa/ec/dgc/gateway/connector/DownloadConnectorBuilderTest.java b/src/test/java/eu/europa/ec/dgc/gateway/connector/DownloadConnectorBuilderTest.java index c7518c2..e538b8d 100644 --- a/src/test/java/eu/europa/ec/dgc/gateway/connector/DownloadConnectorBuilderTest.java +++ b/src/test/java/eu/europa/ec/dgc/gateway/connector/DownloadConnectorBuilderTest.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.gateway.connector; import eu.europa.ec.dgc.gateway.connector.mapper.TrustListMapper; diff --git a/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListDownloadConnectorTest.java b/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListDownloadConnectorTest.java index 63e6362..b2b9487 100644 --- a/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListDownloadConnectorTest.java +++ b/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListDownloadConnectorTest.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.gateway.connector; import com.fasterxml.jackson.databind.ObjectMapper; @@ -309,4 +329,4 @@ private void assertEquals(RevocationBatchDto b1, RevocationBatchDto b2) { Assertions.assertEquals(b1.getEntries().get(i).getHash(), b2.getEntries().get(i).getHash()); } } -} \ No newline at end of file +} diff --git a/src/test/java/eu/europa/ec/dgc/generation/Base45EncoderTest.java b/src/test/java/eu/europa/ec/dgc/generation/Base45EncoderTest.java index c58748b..be9db15 100644 --- a/src/test/java/eu/europa/ec/dgc/generation/Base45EncoderTest.java +++ b/src/test/java/eu/europa/ec/dgc/generation/Base45EncoderTest.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation; import java.nio.charset.StandardCharsets; diff --git a/src/test/java/eu/europa/ec/dgc/generation/DccRecoveryBuilderTest.java b/src/test/java/eu/europa/ec/dgc/generation/DccRecoveryBuilderTest.java index 7151a84..86ceeb7 100644 --- a/src/test/java/eu/europa/ec/dgc/generation/DccRecoveryBuilderTest.java +++ b/src/test/java/eu/europa/ec/dgc/generation/DccRecoveryBuilderTest.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation; import java.time.LocalDate; diff --git a/src/test/java/eu/europa/ec/dgc/generation/DccTestBuilderTest.java b/src/test/java/eu/europa/ec/dgc/generation/DccTestBuilderTest.java index 7c2c394..f17ee05 100644 --- a/src/test/java/eu/europa/ec/dgc/generation/DccTestBuilderTest.java +++ b/src/test/java/eu/europa/ec/dgc/generation/DccTestBuilderTest.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation; import java.time.LocalDate; @@ -43,4 +63,4 @@ void genTestJson() { System.out.println(jsonString); } -} \ No newline at end of file +} diff --git a/src/test/java/eu/europa/ec/dgc/generation/DccVaccinationBuilderTest.java b/src/test/java/eu/europa/ec/dgc/generation/DccVaccinationBuilderTest.java index 56ee77b..98cbcda 100644 --- a/src/test/java/eu/europa/ec/dgc/generation/DccVaccinationBuilderTest.java +++ b/src/test/java/eu/europa/ec/dgc/generation/DccVaccinationBuilderTest.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation; import java.time.LocalDate; diff --git a/src/test/java/eu/europa/ec/dgc/generation/DgcCryptedPublisherTest.java b/src/test/java/eu/europa/ec/dgc/generation/DgcCryptedPublisherTest.java index e3add35..772ccdd 100644 --- a/src/test/java/eu/europa/ec/dgc/generation/DgcCryptedPublisherTest.java +++ b/src/test/java/eu/europa/ec/dgc/generation/DgcCryptedPublisherTest.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation; import eu.europa.ec.dgc.generation.dto.DgcData; diff --git a/src/test/java/eu/europa/ec/dgc/generation/DgcSignerTest.java b/src/test/java/eu/europa/ec/dgc/generation/DgcSignerTest.java index 976682f..c729f0f 100644 --- a/src/test/java/eu/europa/ec/dgc/generation/DgcSignerTest.java +++ b/src/test/java/eu/europa/ec/dgc/generation/DgcSignerTest.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation; import java.io.IOException; diff --git a/src/test/java/eu/europa/ec/dgc/generation/KeyHelper.java b/src/test/java/eu/europa/ec/dgc/generation/KeyHelper.java index 2304d6a..0d5e0e0 100644 --- a/src/test/java/eu/europa/ec/dgc/generation/KeyHelper.java +++ b/src/test/java/eu/europa/ec/dgc/generation/KeyHelper.java @@ -1,3 +1,23 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-lib + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + package eu.europa.ec.dgc.generation; import eu.europa.ec.dgc.testdata.CertificateTestUtils; diff --git a/templates/file-header.txt b/templates/file-header.txt index b7e5095..3697628 100644 --- a/templates/file-header.txt +++ b/templates/file-header.txt @@ -2,7 +2,7 @@ * ---license-start * eu-digital-green-certificates / dgc-lib * --- - * Copyright (C) 2021 T-Systems International GmbH and all other contributors + * Copyright (C) 2022 T-Systems International GmbH and all other contributors * --- * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 5ff9fc41a73df5a6286b8ce1cb20d4e36bcbc6d0 Mon Sep 17 00:00:00 2001 From: Morphyum Date: Mon, 14 Mar 2022 11:47:15 +0100 Subject: [PATCH 04/11] * changed revocation handling to work with the DTOs --- ...cGatewayRevocationListUploadConnector.java | 29 ++++++-- .../RevocationListUploadConnectorTest.java | 66 +++++++++++++++---- 2 files changed, 74 insertions(+), 21 deletions(-) diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java index dca029a..b00630a 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java @@ -22,9 +22,12 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import eu.europa.ec.dgc.gateway.connector.client.DgcGatewayConnectorRestClient; import eu.europa.ec.dgc.gateway.connector.config.DgcGatewayConnectorConfigProperties; import eu.europa.ec.dgc.gateway.connector.dto.ProblemReportDto; +import eu.europa.ec.dgc.gateway.connector.dto.RevocationBatchDeleteRequestDto; +import eu.europa.ec.dgc.gateway.connector.dto.RevocationBatchDto; import eu.europa.ec.dgc.signing.SignedStringMessageBuilder; import eu.europa.ec.dgc.utils.CertificateUtils; import feign.FeignException; @@ -102,18 +105,23 @@ void init() throws KeyStoreException, CertificateEncodingException, IOException /** * Uploads a JSON-File as RevocationBatch to DGC Gateway. * - * @param json the JSON containing the ValidationRUle to upload. + * @param revocationBatchDto the RevocationBatchDto to upload. * @throws DgcRevocationBatchUploadException with detailed information why the upload has failed. */ - public void uploadRevocationBatch(String json) throws DgcRevocationBatchUploadException { + public String uploadRevocationBatch(RevocationBatchDto revocationBatchDto) + throws DgcRevocationBatchUploadException, JsonProcessingException { - String payload = new SignedStringMessageBuilder().withPayload(json) + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new JavaTimeModule()); + String jsonString = mapper.writeValueAsString(revocationBatchDto); + String payload = new SignedStringMessageBuilder().withPayload(jsonString) .withSigningCertificate(uploadCertificateHolder, uploadCertificatePrivateKey).buildAsString(); try { ResponseEntity response = dgcGatewayConnectorRestClient.uploadBatch(payload); if (response.getStatusCode() == HttpStatus.CREATED) { log.info("Successfully uploaded RevocationBatch"); + return response.getHeaders().getETag(); } } catch (FeignException e) { if (e.status() == HttpStatus.BAD_REQUEST.value()) { @@ -126,17 +134,24 @@ public void uploadRevocationBatch(String json) throws DgcRevocationBatchUploadEx DgcRevocationBatchUploadException.Reason.INVALID_AUTHORIZATION); } } + return null; } /** * Deletes a RevocationBatch with given ID from DGC Gateway. * - * @param ruleId The ID of the Rules to be deleted. + * @param batchId The ID of the batch to be deleted. * @throws DgcRevocationBatchUploadException with detailed information why the delete has failed. */ - public void deleteRevocationBatch(String ruleId) throws DgcRevocationBatchUploadException { + public void deleteRevocationBatch(String batchId) throws DgcRevocationBatchUploadException, + JsonProcessingException { - String payload = new SignedStringMessageBuilder().withPayload(ruleId) + RevocationBatchDeleteRequestDto deleteRequest = new RevocationBatchDeleteRequestDto(); + deleteRequest.setBatchId(batchId); + ObjectMapper mapper = new ObjectMapper(); + String jsonString = mapper.writeValueAsString(deleteRequest); + + String payload = new SignedStringMessageBuilder().withPayload(jsonString) .withSigningCertificate(uploadCertificateHolder, uploadCertificatePrivateKey).buildAsString(); try { @@ -155,7 +170,7 @@ public void deleteRevocationBatch(String ruleId) throws DgcRevocationBatchUpload DgcRevocationBatchUploadException.Reason.INVALID_AUTHORIZATION); } else if (e.status() == HttpStatus.NOT_FOUND.value()) { - log.info("ValidationRules with ID {} does not exists on DGCG", ruleId); + log.info("ValidationRules with ID {} does not exists on DGCG", batchId); } } } diff --git a/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListUploadConnectorTest.java b/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListUploadConnectorTest.java index 33a60b7..3f7b32d 100644 --- a/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListUploadConnectorTest.java +++ b/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListUploadConnectorTest.java @@ -25,7 +25,13 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import eu.europa.ec.dgc.gateway.connector.client.DgcGatewayConnectorRestClient; +import eu.europa.ec.dgc.gateway.connector.dto.RevocationBatchDeleteRequestDto; +import eu.europa.ec.dgc.gateway.connector.dto.RevocationBatchDto; +import eu.europa.ec.dgc.gateway.connector.dto.RevocationHashTypeDto; import eu.europa.ec.dgc.signing.SignedStringMessageParser; import eu.europa.ec.dgc.testdata.DgcTestKeyStore; import eu.europa.ec.dgc.utils.CertificateUtils; @@ -36,7 +42,10 @@ import java.security.KeyStoreException; import java.security.PrivateKey; import java.security.cert.X509Certificate; +import java.time.ZonedDateTime; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -66,20 +75,18 @@ class RevocationListUploadConnectorTest { @Test void testUploadOfRevocationList() throws Exception { - String dummyRevocationList = "dummyRevocationList"; - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(String.class); when(restClientMock.uploadBatch(argumentCaptor.capture())) .thenReturn(ResponseEntity.status(HttpStatus.CREATED).build()); - connector.uploadRevocationBatch(dummyRevocationList); + connector.uploadRevocationBatch(getRevocation()); verify(restClientMock).uploadBatch(any()); SignedStringMessageParser parser = new SignedStringMessageParser(argumentCaptor.getValue()); - Assertions.assertEquals(dummyRevocationList, parser.getPayload()); + Assertions.assertEquals(getRevocationJSON(), parser.getPayload()); Assertions.assertEquals(certificateUtils.convertCertificate(testKeyStore.getUpload()), parser.getSigningCertificate()); } @@ -99,7 +106,7 @@ void testDeleteCertificates() throws Exception { SignedStringMessageParser parser = new SignedStringMessageParser(argumentCaptor.getValue()); - Assertions.assertEquals(dummyRevocationListId, parser.getPayload()); + Assertions.assertEquals(getDeleteJSON(dummyRevocationListId), parser.getPayload()); Assertions.assertEquals(certificateUtils.convertCertificate(testKeyStore.getUpload()), parser.getSigningCertificate()); } @@ -140,10 +147,11 @@ void shouldThrowAnExceptionWhenUploadRequestFailed() { DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException e = Assertions.assertThrows(DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.class, - () -> connector.uploadRevocationBatch(dummyRevocationList)); + () -> connector.uploadRevocationBatch(getRevocation())); Assertions.assertEquals( - DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.INVALID_BATCH, e.getReason()); + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.INVALID_BATCH, + e.getReason()); } @Test @@ -163,10 +171,11 @@ void shouldThrowAnExceptionWhenUploadRequestFailedWithBadJson() { DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException e = Assertions.assertThrows(DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.class, - () -> connector.uploadRevocationBatch(dummyRevocationList)); + () -> connector.uploadRevocationBatch(getRevocation())); Assertions.assertEquals( - DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.UNKNOWN_ERROR, e.getReason()); + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.UNKNOWN_ERROR, + e.getReason()); } @Test @@ -178,7 +187,7 @@ void shouldThrowAnExceptionWhenUploadRequestGetsInternalServerError() { DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException e = Assertions.assertThrows(DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.class, - () -> connector.uploadRevocationBatch(dummyRevocationList)); + () -> connector.uploadRevocationBatch(getRevocation())); Assertions.assertEquals( DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.SERVER_ERROR, e.getReason()); } @@ -192,7 +201,7 @@ void shouldThrowAnExceptionWhenUploadRequestGetsUnauthorizedError() { DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException e = Assertions.assertThrows(DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.class, - () -> connector.uploadRevocationBatch(dummyRevocationList)); + () -> connector.uploadRevocationBatch(getRevocation())); Assertions.assertEquals( DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.INVALID_AUTHORIZATION, e.getReason()); @@ -207,7 +216,7 @@ void shouldThrowAnExceptionWhenUploadRequestGetsForbiddenError() { DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException e = Assertions.assertThrows(DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.class, - () -> connector.uploadRevocationBatch(dummyRevocationList)); + () -> connector.uploadRevocationBatch(getRevocation())); Assertions.assertEquals( DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.INVALID_AUTHORIZATION, e.getReason()); @@ -233,7 +242,8 @@ void shouldThrowAnExceptionWhenDeleteRequestFailed() { () -> connector.deleteRevocationBatch(dummyRevocationList)); Assertions.assertEquals( - DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.INVALID_BATCH, e.getReason()); + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.INVALID_BATCH, + e.getReason()); } @Test @@ -256,7 +266,8 @@ void shouldThrowAnExceptionWhenDeleteRequestFailedWithBadJson() { () -> connector.deleteRevocationBatch(dummyRevocationList)); Assertions.assertEquals( - DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.UNKNOWN_ERROR, e.getReason()); + DgcGatewayRevocationListUploadConnector.DgcRevocationBatchUploadException.Reason.UNKNOWN_ERROR, + e.getReason()); } @Test @@ -319,4 +330,31 @@ void shouldNotThrowAnExceptionWhenDeleteRequestGetsNotFoundError() { private Request dummyRequest() { return Request.create(Request.HttpMethod.GET, "url", new HashMap<>(), null, new RequestTemplate()); } + + private RevocationBatchDto getRevocation() { + RevocationBatchDto revocation = new RevocationBatchDto(); + revocation.setCountry("SE"); + revocation.setExpires(ZonedDateTime.parse("2022-03-14T10:43:08.828Z")); + revocation.setKid("123456789012"); + revocation.setHashType(RevocationHashTypeDto.UCI); + RevocationBatchDto.BatchEntryDto entry = new RevocationBatchDto.BatchEntryDto("123456789123456789123456"); + List list = new ArrayList<>(); + list.add(entry); + revocation.setEntries(list); + return revocation; + } + + private String getRevocationJSON() throws JsonProcessingException { + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new JavaTimeModule()); + return mapper.writeValueAsString(getRevocation()); + } + + private String getDeleteJSON(String batchId) throws JsonProcessingException { + RevocationBatchDeleteRequestDto deleteRequest = new RevocationBatchDeleteRequestDto(); + deleteRequest.setBatchId(batchId); + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new JavaTimeModule()); + return mapper.writeValueAsString(deleteRequest); + } } From 8bce09dfe9c785e8d636d71c521e4492317c24ad Mon Sep 17 00:00:00 2001 From: "Marvin \"Morphyum\" Schwabe" Date: Tue, 15 Mar 2022 11:13:08 +0100 Subject: [PATCH 05/11] Update src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java Co-authored-by: Felix Dittrich <31076102+f11h@users.noreply.github.com> --- .../connector/DgcGatewayRevocationListUploadConnector.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java index b00630a..8684db0 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java @@ -111,7 +111,6 @@ void init() throws KeyStoreException, CertificateEncodingException, IOException public String uploadRevocationBatch(RevocationBatchDto revocationBatchDto) throws DgcRevocationBatchUploadException, JsonProcessingException { - ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JavaTimeModule()); String jsonString = mapper.writeValueAsString(revocationBatchDto); String payload = new SignedStringMessageBuilder().withPayload(jsonString) From 655a67212faf2af22ffbb65a5a461a1130667e2e Mon Sep 17 00:00:00 2001 From: "Marvin \"Morphyum\" Schwabe" Date: Tue, 15 Mar 2022 11:13:14 +0100 Subject: [PATCH 06/11] Update src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java Co-authored-by: Felix Dittrich <31076102+f11h@users.noreply.github.com> --- .../connector/DgcGatewayRevocationListUploadConnector.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java index 8684db0..bafd766 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java @@ -147,7 +147,6 @@ public void deleteRevocationBatch(String batchId) throws DgcRevocationBatchUploa RevocationBatchDeleteRequestDto deleteRequest = new RevocationBatchDeleteRequestDto(); deleteRequest.setBatchId(batchId); - ObjectMapper mapper = new ObjectMapper(); String jsonString = mapper.writeValueAsString(deleteRequest); String payload = new SignedStringMessageBuilder().withPayload(jsonString) From 0166925c2acb798725352148db353bd7de8b6100 Mon Sep 17 00:00:00 2001 From: "Marvin \"Morphyum\" Schwabe" Date: Tue, 15 Mar 2022 11:13:23 +0100 Subject: [PATCH 07/11] Update src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java Co-authored-by: Felix Dittrich <31076102+f11h@users.noreply.github.com> --- .../connector/DgcGatewayRevocationListUploadConnector.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java index bafd766..88cabe1 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java @@ -67,6 +67,8 @@ public class DgcGatewayRevocationListUploadConnector { private final DgcGatewayConnectorRestClient dgcGatewayConnectorRestClient; private final DgcGatewayConnectorConfigProperties properties; + + private final ObjectMapper objectMapper; private final CertificateUtils certificateUtils; From cdfaec06679f9380ccb63e998445cb570fa85203 Mon Sep 17 00:00:00 2001 From: "Marvin \"Morphyum\" Schwabe" Date: Tue, 15 Mar 2022 11:13:28 +0100 Subject: [PATCH 08/11] Update src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java Co-authored-by: Felix Dittrich <31076102+f11h@users.noreply.github.com> --- .../connector/DgcGatewayRevocationListUploadConnector.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java index 88cabe1..f17c900 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java @@ -177,7 +177,6 @@ public void deleteRevocationBatch(String batchId) throws DgcRevocationBatchUploa private void handleBadRequest(FeignException e) throws DgcRevocationBatchUploadException { if (e.responseBody().isPresent()) { - ObjectMapper objectMapper = new ObjectMapper(); try { ProblemReportDto problemReport = objectMapper.readValue(e.contentUTF8(), ProblemReportDto.class); From 2a0999f8f5e6c9f6b935c740efd2f3bdee9681d8 Mon Sep 17 00:00:00 2001 From: Morphyum Date: Tue, 15 Mar 2022 11:24:21 +0100 Subject: [PATCH 09/11] * inject objectMapper via Dependency Injection * added format to expires JSON Conversion --- .../connector/DgcGatewayRevocationListUploadConnector.java | 6 +++--- .../ec/dgc/gateway/connector/dto/RevocationBatchDto.java | 2 ++ .../connector/RevocationListUploadConnectorTest.java | 1 - 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java index f17c900..2be8bb9 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java @@ -113,8 +113,8 @@ void init() throws KeyStoreException, CertificateEncodingException, IOException public String uploadRevocationBatch(RevocationBatchDto revocationBatchDto) throws DgcRevocationBatchUploadException, JsonProcessingException { - mapper.registerModule(new JavaTimeModule()); - String jsonString = mapper.writeValueAsString(revocationBatchDto); + objectMapper.registerModule(new JavaTimeModule()); + String jsonString = objectMapper.writeValueAsString(revocationBatchDto); String payload = new SignedStringMessageBuilder().withPayload(jsonString) .withSigningCertificate(uploadCertificateHolder, uploadCertificatePrivateKey).buildAsString(); @@ -149,7 +149,7 @@ public void deleteRevocationBatch(String batchId) throws DgcRevocationBatchUploa RevocationBatchDeleteRequestDto deleteRequest = new RevocationBatchDeleteRequestDto(); deleteRequest.setBatchId(batchId); - String jsonString = mapper.writeValueAsString(deleteRequest); + String jsonString = objectMapper.writeValueAsString(deleteRequest); String payload = new SignedStringMessageBuilder().withPayload(jsonString) .withSigningCertificate(uploadCertificateHolder, uploadCertificatePrivateKey).buildAsString(); diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/dto/RevocationBatchDto.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/dto/RevocationBatchDto.java index 096537e..bd6eb0e 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/connector/dto/RevocationBatchDto.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/dto/RevocationBatchDto.java @@ -20,6 +20,7 @@ package eu.europa.ec.dgc.gateway.connector.dto; +import com.fasterxml.jackson.annotation.JsonFormat; import java.time.ZonedDateTime; import java.util.List; import lombok.AllArgsConstructor; @@ -34,6 +35,7 @@ public class RevocationBatchDto { private String country; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") private ZonedDateTime expires; private String kid; diff --git a/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListUploadConnectorTest.java b/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListUploadConnectorTest.java index 3f7b32d..318d8c5 100644 --- a/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListUploadConnectorTest.java +++ b/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListUploadConnectorTest.java @@ -85,7 +85,6 @@ void testUploadOfRevocationList() throws Exception { verify(restClientMock).uploadBatch(any()); SignedStringMessageParser parser = new SignedStringMessageParser(argumentCaptor.getValue()); - Assertions.assertEquals(getRevocationJSON(), parser.getPayload()); Assertions.assertEquals(certificateUtils.convertCertificate(testKeyStore.getUpload()), parser.getSigningCertificate()); From 32e031cbbddda40ffe0682976950f36ed15c8eac Mon Sep 17 00:00:00 2001 From: Morphyum Date: Tue, 15 Mar 2022 11:39:16 +0100 Subject: [PATCH 10/11] * removed JSONFormat from DTO since it made problems with the download function * added format just for the necessary testing --- .../ec/dgc/gateway/connector/dto/RevocationBatchDto.java | 1 - .../connector/RevocationListUploadConnectorTest.java | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/dto/RevocationBatchDto.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/dto/RevocationBatchDto.java index bd6eb0e..f518fcf 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/connector/dto/RevocationBatchDto.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/dto/RevocationBatchDto.java @@ -35,7 +35,6 @@ public class RevocationBatchDto { private String country; - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") private ZonedDateTime expires; private String kid; diff --git a/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListUploadConnectorTest.java b/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListUploadConnectorTest.java index 318d8c5..f8c3371 100644 --- a/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListUploadConnectorTest.java +++ b/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListUploadConnectorTest.java @@ -27,6 +27,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.util.StdDateFormat; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import eu.europa.ec.dgc.gateway.connector.client.DgcGatewayConnectorRestClient; import eu.europa.ec.dgc.gateway.connector.dto.RevocationBatchDeleteRequestDto; @@ -72,6 +73,7 @@ class RevocationListUploadConnectorTest { @Autowired DgcTestKeyStore testKeyStore; + ObjectMapper mapper = new ObjectMapper(); @Test void testUploadOfRevocationList() throws Exception { @@ -344,15 +346,15 @@ private RevocationBatchDto getRevocation() { } private String getRevocationJSON() throws JsonProcessingException { - ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JavaTimeModule()); + mapper.setDateFormat(new StdDateFormat().withColonInTimeZone(true)); return mapper.writeValueAsString(getRevocation()); } private String getDeleteJSON(String batchId) throws JsonProcessingException { RevocationBatchDeleteRequestDto deleteRequest = new RevocationBatchDeleteRequestDto(); deleteRequest.setBatchId(batchId); - ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new JavaTimeModule()); return mapper.writeValueAsString(deleteRequest); } From 9a4ff9ae9aed25530c614aa0b3dfd1a3a260ed70 Mon Sep 17 00:00:00 2001 From: Morphyum Date: Tue, 15 Mar 2022 11:43:53 +0100 Subject: [PATCH 11/11] * removed unused import --- .../europa/ec/dgc/gateway/connector/dto/RevocationBatchDto.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/eu/europa/ec/dgc/gateway/connector/dto/RevocationBatchDto.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/dto/RevocationBatchDto.java index f518fcf..096537e 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/connector/dto/RevocationBatchDto.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/dto/RevocationBatchDto.java @@ -20,7 +20,6 @@ package eu.europa.ec.dgc.gateway.connector.dto; -import com.fasterxml.jackson.annotation.JsonFormat; import java.time.ZonedDateTime; import java.util.List; import lombok.AllArgsConstructor;