Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prerelease fixes #86

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/chilly-dryers-fail.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"mode": "pre",
"mode": "exit",
"tag": "develop",
"initialVersions": {
"fingerprint-pro-server-api-java-sdk": "6.2.0"
Expand Down
5 changes: 5 additions & 0 deletions .changeset/silly-pigs-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fingerprint-pro-server-api-java-sdk": major
---

Rename `IsValidWebhookSignature` to `isSignatureValid` in `WebhookValidation`
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.isSignatureValid(signature, webhook, secret);
if (!isValidSignature) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Webhook signature is not valid");
}
Expand Down
5 changes: 5 additions & 0 deletions docs/BotdBotResult.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@


# BotdBotResult
Bot detection result:
* `notDetected` - the visitor is not a bot
* `good` - good bot detected, such as Google bot, Baidu Spider, AlexaBot and so on
* `bad` - bad bot detected, such as Selenium, Puppeteer, Playwright, headless browsers, and so on


## Enum

Expand Down
19 changes: 19 additions & 0 deletions docs/ErrorCode.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@


# ErrorCode
Error code:
* `RequestCannotBeParsed` - the query parameters or JSON payload contains some errors
that prevented us from parsing it (wrong type/surpassed limits).
* `TokenRequired` - `Auth-API-Key` header is missing or empty.
* `TokenNotFound` - no Fingerprint application found for specified secret key.
* `SubscriptionNotActive` - Fingerprint application is not active.
* `WrongRegion` - server and application region differ.
* `FeatureNotEnabled` - this feature (for example, Delete API) is not enabled for your application.
* `RequestNotFound` - the specified request ID was not found. It never existed, expired, or it has been deleted.
* `VisitorNotFound` - The specified visitor ID was not found. It never existed or it may have already been deleted.
* `TooManyRequests` - the limit on secret API key requests per second has been exceeded.
* `429 Too Many Requests` - the limit on secret API key requests per second has been exceeded.
* `StateNotReady` - The event specified with request id is
not ready for updates yet. Try again.
This error happens in rare cases when update API is called immediately
after receiving the request id on the client. In case you need to send
information right away, we recommend using the JS agent API instead.
* `Failed` - internal server error.


## Enum

Expand Down
1 change: 1 addition & 0 deletions docs/VPNConfidence.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@


# VPNConfidence
A confidence rating for the VPN detection result — "low", "medium", or "high". Depends on the combination of results returned from all VPN detection methods.

## Enum

Expand Down
17 changes: 16 additions & 1 deletion docs/Velocity.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@

# Velocity

Sums key data points for a specific `visitorId`, `ipAddress` and `linkedId` at three distinct time intervals: 5 minutes, 1 hour, and 24 hours as follows: - Number of distinct IP addresses associated to the visitor ID. - Number of distinct linked IDs associated with the visitor ID. - Number of distinct countries associated with the visitor ID. - Number of identification events associated with the visitor ID. - Number of identification events associated with the detected IP address. - Number of distinct IP addresses associated with the provided linked ID. - Number of distinct visitor IDs associated with the provided linked ID. The `24h` interval of `distinctIp`, `distinctLinkedId`, `distinctCountry`, `distinctIpByLinkedId` and `distinctVisitorIdByLinkedId` will be omitted if the number of `events` for the visitor ID in the last 24 hours (`events.intervals.['24h']`) is higher than 20.000.
Sums key data points for a specific `visitorId`, `ipAddress` and `linkedId` at three distinct time
intervals: 5 minutes, 1 hour, and 24 hours as follows:

- Number of distinct IP addresses associated to the visitor ID.
- Number of distinct linked IDs associated with the visitor ID.
- Number of distinct countries associated with the visitor ID.
- Number of identification events associated with the visitor ID.
- Number of identification events associated with the detected IP address.
- Number of distinct IP addresses associated with the provided linked ID.
- Number of distinct visitor IDs associated with the provided linked ID.

The `24h` interval of `distinctIp`, `distinctLinkedId`, `distinctCountry`,
`distinctIpByLinkedId` and `distinctVisitorIdByLinkedId` will be omitted
if the number of `events` for the visitor ID in the last 24
hours (`events.intervals.['24h']`) is higher than 20.000.


## Properties

Expand Down
3 changes: 2 additions & 1 deletion docs/VelocityIntervals.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

# VelocityIntervals

Is absent if the velocity data could not be generated for the visitor ID.
Is absent if the velocity data could not be generated for the visitor ID.


## Properties

Expand Down
17 changes: 16 additions & 1 deletion docs/WebhookVelocity.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@

# WebhookVelocity

Sums key data points for a specific `visitorId`, `ipAddress` and `linkedId` at three distinct time intervals: 5 minutes, 1 hour, and 24 hours as follows: - Number of distinct IP addresses associated to the visitor ID. - Number of distinct linked IDs associated with the visitor ID. - Number of distinct countries associated with the visitor ID. - Number of identification events associated with the visitor ID. - Number of identification events associated with the detected IP address. - Number of distinct IP addresses associated with the provided linked ID. - Number of distinct visitor IDs associated with the provided linked ID. The `24h` interval of `distinctIp`, `distinctLinkedId`, `distinctCountry`, `distinctIpByLinkedId` and `distinctVisitorIdByLinkedId` will be omitted if the number of `events` for the visitor ID in the last 24 hours (`events.intervals.['24h']`) is higher than 20.000.
Sums key data points for a specific `visitorId`, `ipAddress` and `linkedId` at three distinct time
intervals: 5 minutes, 1 hour, and 24 hours as follows:

- Number of distinct IP addresses associated to the visitor ID.
- Number of distinct linked IDs associated with the visitor ID.
- Number of distinct countries associated with the visitor ID.
- Number of identification events associated with the visitor ID.
- Number of identification events associated with the detected IP address.
- Number of distinct IP addresses associated with the provided linked ID.
- Number of distinct visitor IDs associated with the provided linked ID.

The `24h` interval of `distinctIp`, `distinctLinkedId`, `distinctCountry`,
`distinctIpByLinkedId` and `distinctVisitorIdByLinkedId` will be omitted
if the number of `events` for the visitor ID in the last 24
hours (`events.intervals.['24h']`) is higher than 20.000.


## Properties

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.isSignatureValid(header, data, secret);
if (isSignatureValid) {
System.out.println("Webhook signature is valid");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -20,7 +20,7 @@ public class Webhook {
* @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("=");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,40 +9,40 @@
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";
private static final byte[] data = "data".getBytes(StandardCharsets.UTF_8);

@Test
public void validHeaderTest() throws NoSuchAlgorithmException {
boolean result = Webhook.isValidWebhookSignature(validHeader, data, secret);
boolean result = WebhookValidation.isSignatureValid(validHeader, data, secret);
Assertions.assertTrue(result);
}

@Test
public void invalidHeaderTest() throws NoSuchAlgorithmException {
boolean result = Webhook.isValidWebhookSignature("v2=wrong", data, secret);
boolean result = WebhookValidation.isSignatureValid("v2=wrong", data, secret);
assert !result;
}

@Test
public void headerWithoutVersionTest() throws NoSuchAlgorithmException {
boolean result = Webhook.isValidWebhookSignature("secretonly", data, secret);
boolean result = WebhookValidation.isSignatureValid("secretonly", data, secret);
assert !result;
}

@Test
public void emptySecretTest() throws NoSuchAlgorithmException {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
Webhook.isValidWebhookSignature("v1=value", data, "");
WebhookValidation.isSignatureValid("v1=value", data, "");
});
}

@Test
public void emptyDataTest() throws NoSuchAlgorithmException {
boolean result = Webhook.isValidWebhookSignature(validHeader, "".getBytes(), secret);
boolean result = WebhookValidation.isSignatureValid(validHeader, "".getBytes(), secret);
assert !result;
}

Expand Down
4 changes: 2 additions & 2 deletions template/README.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.isSignatureValid(signature, webhook, secret);
if (!isValidSignature) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Webhook signature is not valid");
}
Expand Down
10 changes: 10 additions & 0 deletions template/enum_outer_doc.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# {{classname}}
{{#unescapedDescription}}
{{{.}}}

{{/unescapedDescription}}
## Enum

{{#allowableValues}}{{#enumVars}}
* `{{name}}` (value: `{{{value}}}`)
{{/enumVars}}{{/allowableValues}}
2 changes: 1 addition & 1 deletion template/pojo_doc.mustache
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# {{classname}}

{{#description}}
{{{description}}}
{{{unescapedDescription}}}
{{/description}}

## Properties
Expand Down
Loading