From f49c1c2cd754af8e1f763559886d30ce69567a39 Mon Sep 17 00:00:00 2001 From: Ilya Taratukhin Date: Fri, 22 Nov 2024 16:42:08 +0100 Subject: [PATCH] feat: rename IsValidWebhookSignature to isSignatureValid in `WebhookValidation --- .changeset/silly-pigs-refuse.md | 5 +++++ README.md | 2 +- .../fingerprint/example/WebhookSignatureSample.java | 2 +- .../java/com/fingerprint/sdk/WebhookValidation.java | 2 +- .../java/com/fingerprint/WebhookValidationTest.java | 10 +++++----- template/README.mustache | 2 +- 6 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 .changeset/silly-pigs-refuse.md diff --git a/.changeset/silly-pigs-refuse.md b/.changeset/silly-pigs-refuse.md new file mode 100644 index 0000000..1d913e0 --- /dev/null +++ b/.changeset/silly-pigs-refuse.md @@ -0,0 +1,5 @@ +--- +"fingerprint-pro-server-api-java-sdk": major +--- + +Rename `IsValidWebhookSignature` to `isSignatureValid` in `WebhookValidation` diff --git a/README.md b/README.md index eddc50a..afcf83f 100644 --- a/README.md +++ b/README.md @@ -257,7 +257,7 @@ class WebhookController { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Missing fpjs-event-signature header"); } - final boolean isValidSignature = WebhookValidation.isValidWebhookSignature(signature, webhook, secret); + final boolean isValidSignature = WebhookValidation.isSignatureValid(signature, webhook, secret); if (!isValidSignature) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Webhook signature is not valid"); } diff --git a/examples/src/main/java/com/fingerprint/example/WebhookSignatureSample.java b/examples/src/main/java/com/fingerprint/example/WebhookSignatureSample.java index ac42ebc..6de4e57 100644 --- a/examples/src/main/java/com/fingerprint/example/WebhookSignatureSample.java +++ b/examples/src/main/java/com/fingerprint/example/WebhookSignatureSample.java @@ -13,7 +13,7 @@ public static void main(String... args) { final byte[] data = "data".getBytes(StandardCharsets.UTF_8); try { - boolean isSignatureValid = WebhookValidation.isValidWebhookSignature(header, data, secret); + boolean isSignatureValid = WebhookValidation.isSignatureValid(header, data, secret); if (isSignatureValid) { System.out.println("Webhook signature is valid"); } else { diff --git a/sdk/src/main/java/com/fingerprint/sdk/WebhookValidation.java b/sdk/src/main/java/com/fingerprint/sdk/WebhookValidation.java index b804b0c..a6ba033 100644 --- a/sdk/src/main/java/com/fingerprint/sdk/WebhookValidation.java +++ b/sdk/src/main/java/com/fingerprint/sdk/WebhookValidation.java @@ -20,7 +20,7 @@ public class WebhookValidation { * @throws NoSuchAlgorithmException in case HMAC-SHA-256 isn't available * @throws IllegalArgumentException if an invalid key is provided */ - public static boolean isValidWebhookSignature(String header, byte[] data, String secret) throws NoSuchAlgorithmException { + public static boolean isSignatureValid(String header, byte[] data, String secret) throws NoSuchAlgorithmException { String[] signatures = header.split(","); for (String signature : signatures) { String[] parts = signature.split("="); diff --git a/sdk/src/test/java/com/fingerprint/WebhookValidationTest.java b/sdk/src/test/java/com/fingerprint/WebhookValidationTest.java index 0e26863..8521cfb 100644 --- a/sdk/src/test/java/com/fingerprint/WebhookValidationTest.java +++ b/sdk/src/test/java/com/fingerprint/WebhookValidationTest.java @@ -17,32 +17,32 @@ public class WebhookValidationTest { @Test public void validHeaderTest() throws NoSuchAlgorithmException { - boolean result = WebhookValidation.isValidWebhookSignature(validHeader, data, secret); + boolean result = WebhookValidation.isSignatureValid(validHeader, data, secret); Assertions.assertTrue(result); } @Test public void invalidHeaderTest() throws NoSuchAlgorithmException { - boolean result = WebhookValidation.isValidWebhookSignature("v2=wrong", data, secret); + boolean result = WebhookValidation.isSignatureValid("v2=wrong", data, secret); assert !result; } @Test public void headerWithoutVersionTest() throws NoSuchAlgorithmException { - boolean result = WebhookValidation.isValidWebhookSignature("secretonly", data, secret); + boolean result = WebhookValidation.isSignatureValid("secretonly", data, secret); assert !result; } @Test public void emptySecretTest() throws NoSuchAlgorithmException { Assertions.assertThrows(IllegalArgumentException.class, () -> { - WebhookValidation.isValidWebhookSignature("v1=value", data, ""); + WebhookValidation.isSignatureValid("v1=value", data, ""); }); } @Test public void emptyDataTest() throws NoSuchAlgorithmException { - boolean result = WebhookValidation.isValidWebhookSignature(validHeader, "".getBytes(), secret); + boolean result = WebhookValidation.isSignatureValid(validHeader, "".getBytes(), secret); assert !result; } diff --git a/template/README.mustache b/template/README.mustache index 1950339..136a183 100644 --- a/template/README.mustache +++ b/template/README.mustache @@ -284,7 +284,7 @@ class WebhookController { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Missing fpjs-event-signature header"); } - final boolean isValidSignature = WebhookValidation.isValidWebhookSignature(signature, webhook, secret); + final boolean isValidSignature = WebhookValidation.isSignatureValid(signature, webhook, secret); if (!isValidSignature) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Webhook signature is not valid"); }