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/DgcGatewayRevocationListUploadConnector.java b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java new file mode 100644 index 0000000..2be8bb9 --- /dev/null +++ b/src/main/java/eu/europa/ec/dgc/gateway/connector/DgcGatewayRevocationListUploadConnector.java @@ -0,0 +1,212 @@ +/*- + * ---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 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; +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 ObjectMapper objectMapper; + + 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 revocationBatchDto the RevocationBatchDto to upload. + * @throws DgcRevocationBatchUploadException with detailed information why the upload has failed. + */ + public String uploadRevocationBatch(RevocationBatchDto revocationBatchDto) + throws DgcRevocationBatchUploadException, JsonProcessingException { + + objectMapper.registerModule(new JavaTimeModule()); + String jsonString = objectMapper.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()) { + 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); + } + } + return null; + } + + /** + * Deletes a RevocationBatch with given ID from DGC Gateway. + * + * @param batchId The ID of the batch to be deleted. + * @throws DgcRevocationBatchUploadException with detailed information why the delete has failed. + */ + public void deleteRevocationBatch(String batchId) throws DgcRevocationBatchUploadException, + JsonProcessingException { + + RevocationBatchDeleteRequestDto deleteRequest = new RevocationBatchDeleteRequestDto(); + deleteRequest.setBatchId(batchId); + String jsonString = objectMapper.writeValueAsString(deleteRequest); + + String payload = new SignedStringMessageBuilder().withPayload(jsonString) + .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", batchId); + } + } + } + + private void handleBadRequest(FeignException e) throws DgcRevocationBatchUploadException { + if (e.responseBody().isPresent()) { + 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; + +} 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/gateway/connector/RevocationListUploadConnectorTest.java b/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListUploadConnectorTest.java new file mode 100644 index 0000000..f8c3371 --- /dev/null +++ b/src/test/java/eu/europa/ec/dgc/gateway/connector/RevocationListUploadConnectorTest.java @@ -0,0 +1,361 @@ +/*- + * ---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 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; +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; +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.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; +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; + + ObjectMapper mapper = new ObjectMapper(); + + @Test + void testUploadOfRevocationList() throws Exception { + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(String.class); + + when(restClientMock.uploadBatch(argumentCaptor.capture())) + .thenReturn(ResponseEntity.status(HttpStatus.CREATED).build()); + + connector.uploadRevocationBatch(getRevocation()); + + verify(restClientMock).uploadBatch(any()); + + SignedStringMessageParser parser = new SignedStringMessageParser(argumentCaptor.getValue()); + Assertions.assertEquals(getRevocationJSON(), 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(getDeleteJSON(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(getRevocation())); + + 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(getRevocation())); + + 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(getRevocation())); + 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(getRevocation())); + 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(getRevocation())); + 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()); + } + + 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 { + 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); + + mapper.registerModule(new JavaTimeModule()); + return mapper.writeValueAsString(deleteRequest); + } +} 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.