Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TheUnderScorer committed Oct 7, 2024
1 parent 9abc7d9 commit 690e0e3
Show file tree
Hide file tree
Showing 3 changed files with 392 additions and 23 deletions.
283 changes: 283 additions & 0 deletions test/mocks/get_event_200_with_broken_format.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
{
"products": {
"identification": {
"data": {
"visitorId": "Ibk1527CUFmcnjLwIs4A9",
"requestId": "1708102555327.NLOjmg",
"incognito": true,
"linkedId": {
"broken": "format"
},
"tag": {},
"time": "2019-05-21T16:40:13Z",
"timestamp": 1582299576512,
"url": "https://www.example.com/login?hope{this{works[!",
"ip": "61.127.217.15",
"ipLocation": {
"accuracyRadius": 10,
"latitude": 49.982,
"longitude": 36.2566,
"postalCode": "61202",
"timezone": "Europe/Dusseldorf",
"city": {
"name": "Dusseldorf"
},
"country": {
"code": "DE",
"name": "Germany"
},
"continent": {
"code": "EU",
"name": "Europe"
},
"subdivisions": [
{
"isoCode": "63",
"name": "North Rhine-Westphalia"
}
]
},
"browserDetails": {
"browserName": "Chrome",
"browserMajorVersion": "74",
"browserFullVersion": "74.0.3729",
"os": "Windows",
"osVersion": "7",
"device": "Other",
"userAgent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) ...."
},
"confidence": {
"score": 0.97
},
"visitorFound": false,
"firstSeenAt": {
"global": "2022-03-16T11:26:45.362Z",
"subscription": "2022-03-16T11:31:01.101Z"
},
"lastSeenAt": {
"global": null,
"subscription": null
}
}
},
"botd": {
"data": {
"bot": {
"result": "notDetected"
},
"url": "https://www.example.com/login?hope{this{works}[!",
"ip": "61.127.217.15",
"time": "2019-05-21T16:40:13Z",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 YaBrowser/24.1.0.0 Safari/537.36",
"requestId": "1708102555327.NLOjmg"
}
},
"rootApps": {
"data": {
"result": false
}
},
"emulator": {
"data": {
"result": false
}
},
"ipInfo": {
"data": {
"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"
}
},
"v6": {
"address": "2001:db8:3333:4444:5555:6666:7777:8888",
"geolocation": {
"accuracyRadius": 5,
"latitude": 49.982,
"longitude": 36.2566,
"postalCode": "10112",
"timezone": "Europe/Berlin",
"city": {
"name": "Berlin"
},
"country": {
"code": "DE",
"name": "Germany"
},
"continent": {
"code": "EU",
"name": "Europe"
},
"subdivisions": [
{
"isoCode": "BE",
"name": "Land Berlin"
}
]
},
"asn": {
"asn": "6805",
"name": "Telefonica Germany",
"network": "2a02:3100::/24"
},
"datacenter": {
"result": false,
"name": ""
}
}
}
},
"ipBlocklist": {
"data": {
"result": false,
"details": {
"emailSpam": false,
"attackSource": false
}
}
},
"tor": {
"data": {
"result": false
}
},
"vpn": {
"data": {
"result": false,
"originTimezone": "Europe/Berlin",
"originCountry": "unknown",
"methods": {
"timezoneMismatch": false,
"publicVPN": false,
"auxiliaryMobile": false
}
}
},
"proxy": {
"data": {
"result": false
}
},
"incognito": {
"data": {
"result": false
}
},
"tampering": {
"data": {
"result": false,
"anomalyScore": 0.1955
}
},
"clonedApp": {
"data": {
"result": false
}
},
"factoryReset": {
"data": {
"time": "1970-01-01T00:00:00Z",
"timestamp": 0
}
},
"jailbroken": {
"data": {
"result": false
}
},
"frida": {
"data": {
"result": false
}
},
"privacySettings": {
"data": {
"result": false
}
},
"virtualMachine": {
"data": {
"result": false
}
},
"rawDeviceAttributes": {
"data": {
"architecture": {
"value": 127
},
"audio": {
"value": 35.73832903057337
},
"canvas": {
"value": {
"Winding": true,
"Geometry": "4dce9d6017c3e0c052a77252f29f2b1c",
"Text": "dd2474a56ff78c1de3e7a07070ba3b7d"
}
},
"colorDepth": {
"value": 30
},
"colorGamut": {
"value": "p3"
},
"contrast": {
"value": 0
},
"cookiesEnabled": {
"value": true
},
"cpuClass": {},
"fonts": {
"value": [
"Arial Unicode MS",
"Gill Sans",
"Helvetica Neue",
"Menlo"
]
}
}
},
"highActivity": {
"data": {
"result": false
}
},
"locationSpoofing": {
"data": {
"result": false
}
}
}
}
27 changes: 17 additions & 10 deletions test/test_fingerprint_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

import io
import os
import unittest

import urllib3
Expand All @@ -30,9 +31,14 @@


class MockPoolManager(object):
def __init__(self, tc):


def __init__(self, tc, request_headers=None):
if request_headers is None:
request_headers = {}
self._tc = tc
self._reqs = []
self.request_headers = request_headers

def expect_request(self, *args, **kwargs):
self._reqs.append((args, kwargs))
Expand Down Expand Up @@ -72,14 +78,15 @@ def request(self, *args, **kwargs):
if mock_file_by_first_argument == 'update_event':
return urllib3.HTTPResponse(status=200, body='OK')
try:
with io.open('./test/mocks/' + mock_file_by_first_argument, 'r', encoding='utf-8') as mock_file:
path = './test/mocks/' + mock_file_by_first_argument

if not os.path.isfile(path):
path = './test/mocks/shared/' + mock_file_by_first_argument

with io.open(path, 'r', encoding='utf-8') as mock_file:
answer_mock = mock_file.read()
mock_file.close()
headers = {}
if mock_file_by_first_argument == 'get_visits_429_too_many_requests_error.json':
headers.update({'Retry-After': '4'})

return urllib3.HTTPResponse(status=status, body=answer_mock, headers=headers)
return urllib3.HTTPResponse(status=status, body=answer_mock, headers=self.request_headers)
except IOError as e:
print(e)
return urllib3.HTTPResponse(status=200, body='{"visitorId": "%s", "visits": []}' % mock_file_by_first_argument)
Expand Down Expand Up @@ -161,7 +168,7 @@ def test_get_visits_error_403(self):

def test_get_visits_error_429(self):
"""Test checks correct code run result in case of 429 error for get_visits method"""
mock_pool = MockPoolManager(self)
mock_pool = MockPoolManager(self, request_headers={'Retry-After': '4'})
self.api.api_client.rest_client.pool_manager = mock_pool
mock_file = 'get_visits_429_too_many_requests_error.json'
mock_pool.expect_request('GET', TestFingerprintApi.get_visitors_path(visitor_id=mock_file),
Expand All @@ -177,7 +184,7 @@ def test_get_visits_error_429_empty_retry_after(self):
"""Test checks retry after value in exception in case of 429 error for get_visits method"""
mock_pool = MockPoolManager(self)
self.api.api_client.rest_client.pool_manager = mock_pool
mock_file = 'get_visits_429_too_many_requests_error_empty_header.json'
mock_file = 'get_visits_429_too_many_requests_error.json'
mock_pool.expect_request('GET', TestFingerprintApi.get_visitors_path(visitor_id=mock_file),
fields=[self.integration_info], headers=self.request_headers,
preload_content=True, timeout=None, status=429)
Expand Down Expand Up @@ -501,7 +508,7 @@ def test_get_event_wrong_shape(self):
mock_pool = MockPoolManager(self)
self.api.api_client.rest_client.pool_manager = mock_pool

mock_file = 'get_event_200_wrong_shape.json'
mock_file = 'get_event_200_with_broken_format.json'
mock_pool.expect_request('GET', TestFingerprintApi.get_events_path(request_id=mock_file),
fields=[self.integration_info], headers=self.request_headers,
preload_content=True, timeout=None)
Expand Down
Loading

0 comments on commit 690e0e3

Please sign in to comment.