From 817b4443db7d9eea45ac36d3843335762ead01b5 Mon Sep 17 00:00:00 2001 From: Ilya Taratukhin Date: Fri, 22 Nov 2024 16:35:48 +0100 Subject: [PATCH] feat: rename `Webhook` class to `WebhookValidation` --- .changeset/chilly-dryers-fail.md | 6 ++++++ README.md | 4 ++-- .../example/WebhookSignatureSample.java | 4 ++-- .../sdk/{Webhook.java => WebhookValidation.java} | 2 +- ...WebhookTest.java => WebhookValidationTest.java} | 14 +++++++------- template/README.mustache | 4 ++-- 6 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 .changeset/chilly-dryers-fail.md rename sdk/src/main/java/com/fingerprint/sdk/{Webhook.java => WebhookValidation.java} (98%) rename sdk/src/test/java/com/fingerprint/{WebhookTest.java => WebhookValidationTest.java} (67%) diff --git a/.changeset/chilly-dryers-fail.md b/.changeset/chilly-dryers-fail.md new file mode 100644 index 00000000..9549a7cd --- /dev/null +++ b/.changeset/chilly-dryers-fail.md @@ -0,0 +1,6 @@ +--- +"fingerprint-pro-server-api-java-sdk": major +--- + +Rename `Webhook` class to `WebhookValidation`. +Right now, `Webhook` class points to the actual data model. diff --git a/README.md b/README.md index 4afa7a69..eddc50a7 100644 --- a/README.md +++ b/README.md @@ -240,7 +240,7 @@ This SDK provides utility method for verifying the HMAC signature of the incomin Here is an example implementation using Spring Boot: ```java -import com.fingerprint.sdk.Webhook; +import com.fingerprint.sdk.WebhookValidation; @RestController class WebhookController { @@ -257,7 +257,7 @@ class WebhookController { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Missing fpjs-event-signature header"); } - final boolean isValidSignature = Webhook.isValidWebhookSignature(signature, webhook, secret); + final boolean isValidSignature = WebhookValidation.isValidWebhookSignature(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 7702f70b..ac42ebc6 100644 --- a/examples/src/main/java/com/fingerprint/example/WebhookSignatureSample.java +++ b/examples/src/main/java/com/fingerprint/example/WebhookSignatureSample.java @@ -1,6 +1,6 @@ package com.fingerprint.example; -import com.fingerprint.sdk.Webhook; +import com.fingerprint.sdk.WebhookValidation; import java.nio.charset.StandardCharsets; import java.security.NoSuchAlgorithmException; @@ -13,7 +13,7 @@ public static void main(String... args) { final byte[] data = "data".getBytes(StandardCharsets.UTF_8); try { - boolean isSignatureValid = Webhook.isValidWebhookSignature(header, data, secret); + boolean isSignatureValid = WebhookValidation.isValidWebhookSignature(header, data, secret); if (isSignatureValid) { System.out.println("Webhook signature is valid"); } else { diff --git a/sdk/src/main/java/com/fingerprint/sdk/Webhook.java b/sdk/src/main/java/com/fingerprint/sdk/WebhookValidation.java similarity index 98% rename from sdk/src/main/java/com/fingerprint/sdk/Webhook.java rename to sdk/src/main/java/com/fingerprint/sdk/WebhookValidation.java index daf20981..b804b0ce 100644 --- a/sdk/src/main/java/com/fingerprint/sdk/Webhook.java +++ b/sdk/src/main/java/com/fingerprint/sdk/WebhookValidation.java @@ -8,7 +8,7 @@ import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; -public class Webhook { +public class WebhookValidation { /** * Verifies the HMAC signature extracted from the "fpjs-event-signature" header of the incoming request. diff --git a/sdk/src/test/java/com/fingerprint/WebhookTest.java b/sdk/src/test/java/com/fingerprint/WebhookValidationTest.java similarity index 67% rename from sdk/src/test/java/com/fingerprint/WebhookTest.java rename to sdk/src/test/java/com/fingerprint/WebhookValidationTest.java index 9e1b5e95..0e268639 100644 --- a/sdk/src/test/java/com/fingerprint/WebhookTest.java +++ b/sdk/src/test/java/com/fingerprint/WebhookValidationTest.java @@ -1,6 +1,6 @@ package com.fingerprint; -import com.fingerprint.sdk.Webhook; +import com.fingerprint.sdk.WebhookValidation; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -9,7 +9,7 @@ import java.security.NoSuchAlgorithmException; @TestInstance(TestInstance.Lifecycle.PER_CLASS) -public class WebhookTest { +public class WebhookValidationTest { private static final String validHeader = "v1=1b2c16b75bd2a870c114153ccda5bcfca63314bc722fa160d690de133ccbb9db"; private static final String secret = "secret"; @@ -17,32 +17,32 @@ public class WebhookTest { @Test public void validHeaderTest() throws NoSuchAlgorithmException { - boolean result = Webhook.isValidWebhookSignature(validHeader, data, secret); + boolean result = WebhookValidation.isValidWebhookSignature(validHeader, data, secret); Assertions.assertTrue(result); } @Test public void invalidHeaderTest() throws NoSuchAlgorithmException { - boolean result = Webhook.isValidWebhookSignature("v2=wrong", data, secret); + boolean result = WebhookValidation.isValidWebhookSignature("v2=wrong", data, secret); assert !result; } @Test public void headerWithoutVersionTest() throws NoSuchAlgorithmException { - boolean result = Webhook.isValidWebhookSignature("secretonly", data, secret); + boolean result = WebhookValidation.isValidWebhookSignature("secretonly", data, secret); assert !result; } @Test public void emptySecretTest() throws NoSuchAlgorithmException { Assertions.assertThrows(IllegalArgumentException.class, () -> { - Webhook.isValidWebhookSignature("v1=value", data, ""); + WebhookValidation.isValidWebhookSignature("v1=value", data, ""); }); } @Test public void emptyDataTest() throws NoSuchAlgorithmException { - boolean result = Webhook.isValidWebhookSignature(validHeader, "".getBytes(), secret); + boolean result = WebhookValidation.isValidWebhookSignature(validHeader, "".getBytes(), secret); assert !result; } diff --git a/template/README.mustache b/template/README.mustache index d155423d..19503395 100644 --- a/template/README.mustache +++ b/template/README.mustache @@ -267,7 +267,7 @@ This SDK provides utility method for verifying the HMAC signature of the incomin Here is an example implementation using Spring Boot: ```java -import com.fingerprint.sdk.Webhook; +import com.fingerprint.sdk.WebhookValidation; @RestController class WebhookController { @@ -284,7 +284,7 @@ class WebhookController { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Missing fpjs-event-signature header"); } - final boolean isValidSignature = Webhook.isValidWebhookSignature(signature, webhook, secret); + final boolean isValidSignature = WebhookValidation.isValidWebhookSignature(signature, webhook, secret); if (!isValidSignature) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Webhook signature is not valid"); }