From ec775da15605b3950ab761cb8514f5555b944f06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gst=C3=B6hl?= Date: Mon, 31 Jan 2022 16:16:42 +0100 Subject: [PATCH] simple controller: return bad request if no or invalid verification mode is provided --- .../check/ws/controller/SimpleController.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/controller/SimpleController.java b/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/controller/SimpleController.java index f5ce5f6..f9d9234 100644 --- a/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/controller/SimpleController.java +++ b/ch-covidcertificate-backend-verification-check/ch-covidcertificate-backend-verification-check-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verification/check/ws/controller/SimpleController.java @@ -50,6 +50,9 @@ public SimpleController(VerificationService verificationService) { @PostMapping("/verify") public @ResponseBody SimpleVerificationResponse verify(@RequestBody SimpleControllerPayload hCertPayload) { String verificationMode = hCertPayload.getMode(); + if(!getVerificationModes().contains(verificationMode)){ + throw new IllegalArgumentException("Invalid or no verification mode provided. Query /modes for currently available modes"); + } final var start = Instant.now(); // Decode hcert @@ -89,10 +92,20 @@ public SimpleController(VerificationService verificationService) { } - @ExceptionHandler(DecodingException.class) + @ExceptionHandler(DecodingException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public ResponseEntity invalidHCert(DecodingException e) { logger.info("Decoding exception thrown: {}", e.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMsg()); } -} \ No newline at end of file + + @ExceptionHandler(IllegalArgumentException.class) + @ResponseStatus(HttpStatus.BAD_REQUEST) + public ResponseEntity invalidMode(IllegalArgumentException e) { + logger.info("IllegalArgumentException thrown: {}", e.getMessage()); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage()); + } + + +} +