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

Add webhook deserialization tests #35

Merged
merged 1 commit into from
Mar 26, 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
1 change: 1 addition & 0 deletions scripts/sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ examplesList=(
'get_event_200_botd_too_many_requests_error.json'
'get_event_200_identification_failed_error.json'
'get_event_200_identification_too_many_requests_error.json'
'webhook.json'
)

for example in ${examplesList[*]}; do
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/com/fingerprint/api/FingerprintApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class FingerprintApiTest {
private final String MOCK_REQUEST_IDENTIFICATION_MANY_REQUEST = "MOCK_REQUEST_IDENTIFICATION_MANY_REQUEST";
private final String MOCK_VISITOR_ID = "AcxioeQKffpXF8iGQK3P";
private final String MOCK_VISITOR_REQUEST_ID = "1655373780901.HhjRFX";
private final String MOCK_WEBHOOK_VISITOR_ID = "3HNey93AkBW6CRbxV6xP";
private final String MOCK_WEBHOOK_REQUEST_ID = "Px6VxbRC6WBkA39yeNH3";


private InputStream getFileAsIOStream(final String fileName) {
Expand Down Expand Up @@ -220,4 +222,23 @@ public void getVisitsTest() throws ApiException {
assertEquals(response.getVisitorId(), MOCK_VISITOR_ID);
}

/**
* Webhook
* Check that webhook correctly deserializes the JSON payload to the WebhookVisit object.
*
* @throws Exception if the file reading or deserialization fails.
*/
@Test
public void webhookTest() throws Exception {
ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule());
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
JsonNullableModule jnm = new JsonNullableModule();
mapper.registerModule(jnm);

WebhookVisit visit = mapper.readValue(getFileAsIOStream("mocks/webhook.json"), WebhookVisit.class);

assert visit.getVisitorId().equals(MOCK_WEBHOOK_VISITOR_ID);
assert visit.getRequestId().equals(MOCK_WEBHOOK_REQUEST_ID);
}

}
191 changes: 191 additions & 0 deletions src/test/resources/mocks/webhook.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
{
"requestId": "Px6VxbRC6WBkA39yeNH3",
"tag": {
"requestType": "signup",
"yourCustomId": 45321
},
"linkedId": "any-string",
"visitorId": "3HNey93AkBW6CRbxV6xP",
"visitorFound": true,
"timestamp": 1554910997788,
"time": "2019-10-12T07:20:50.52Z",
"incognito": false,
"url": "https://banking.example.com/signup",
"clientReferrer": "https://google.com?search=banking+services",
"ip": "216.3.128.12",
"ipLocation": {
"accuracyRadius": 1,
"city": {
"name": "Bolingbrook"
},
"continent": {
"code": "NA",
"name": "North America"
},
"country": {
"code": "US",
"name": "United States"
},
"latitude": 41.12933,
"longitude": -88.9954,
"postalCode": "60547",
"subdivisions": [
{
"isoCode": "IL",
"name": "Illinois"
}
],
"timezone": "America/Chicago"
},
"browserDetails": {
"browserName": "Chrome",
"browserFullVersion": "73.0.3683.86",
"browserMajorVersion": "73",
"os": "Mac OS X",
"osVersion": "10.14.3",
"device": "Other",
"userAgent": "(Macintosh; Intel Mac OS X 10_14_3) Chrome/73.0.3683.86"
},
"confidence": {
"score": 0.97
},
"firstSeenAt": {
"global": "2022-03-16T11:26:45.362Z",
"subscription": "2022-03-16T11:31:01.101Z"
},
"lastSeenAt": {
"global": "2022-03-16T11:28:34.023Z",
"subscription": null
},
"bot": {
"result": "bad",
"type": "selenium"
},
"userAgent": "(Macintosh; Intel Mac OS X 10_14_3) Chrome/73.0.3683.86",
"ipInfo": {
"v4": {
"address": "94.142.239.124",
"geolocation": {
"accuracyRadius": 20,
"latitude": 50.05,
"longitude": 14.4,
"postalCode": "150 00",
"timezone": "Europe/Prague",
"city": {
"name": "Prague"
},
"country": {
"code": "CZ",
"name": "Czechia"
},
"continent": {
"code": "EU",
"name": "Europe"
},
"subdivisions": [
{
"isoCode": "10",
"name": "Hlavni mesto Praha"
}
]
},
"asn": {
"asn": "7922",
"name": "COMCAST-7922",
"network": "73.136.0.0/13"
},
"datacenter": {
"result": true,
"name": "DediPath"
}
}
},
"rootApps": {
"result": false
},
"emulator": {
"result": false
},
"ipBlocklist": {
"result": false,
"details": {
"emailSpam": false,
"attackSource": false
}
},
"tor": {
"result": false
},
"vpn": {
"result": false,
"originTimezone": "Europe/Berlin",
"originCountry": "unknown",
"methods": {
"timezoneMismatch": false,
"publicVPN": false,
"auxiliaryMobile": false
}
},
"proxy": {
"result": false
},
"tampering": {
"result": false,
"anomalyScore": 0
},
"clonedApp": {
"result": false
},
"factoryReset": {
"time": "1970-01-01T00:00:00Z",
"timestamp": 0
},
"jailbroken": {
"result": false
},
"frida": {
"result": false
},
"privacySettings": {
"result": false
},
"virtualMachine": {
"result": false
},
"rawDeviceAttributes": {
"architecture": {
"value": 127
},
"audio": {
"value": 35.73832903057337
},
"canvas": {
"value": {
"Winding": true,
"Geometry": "4dce9d6017c3e0c052a77252f29f2b1c",
"Text": "dd2474a56ff78c1de3e7a07070ba3b7d"
}
},
"colorDepth": {
"value": 30
},
"colorGamut": {
"value": "srgb"
},
"contrast": {
"value": 0
},
"cookiesEnabled": {
"value": true
}
},
"highActivity": {
"result": false
},
"locationSpoofing": {
"result": true
},
"suspectScore": {
"result": 0
}
}
Loading