-
-
Notifications
You must be signed in to change notification settings - Fork 803
Expand file tree
/
Copy pathtest_module_ipstack.py
More file actions
67 lines (63 loc) · 2.67 KB
/
test_module_ipstack.py
File metadata and controls
67 lines (63 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from .base import ModuleTestBase
class TestIPStack(ModuleTestBase):
targets = ["8.8.8.8"]
config_overrides = {"modules": {"ipstack": {"api_key": "asdf"}}}
async def setup_before_prep(self, module_test):
module_test.httpx_mock.add_response(
url="http://api.ipstack.com/check?access_key=asdf",
json={
"ip": "1.2.3.4",
"type": "ipv4",
"continent_code": "NA",
"continent_name": "North America",
"country_code": "US",
"country_name": "United States",
"region_code": "FL",
"region_name": "Florida",
"city": "Cape Canaveral",
"zip": "12345",
"latitude": 47.89263153076172,
"longitude": -97.04190063476562,
"location": {
"geoname_id": 5059429,
"capital": "Washington D.C.",
"languages": [{"code": "en", "name": "English", "native": "English"}],
"country_flag": "https://assets.ipstack.com/flags/us.svg",
"country_flag_emoji": "🇺🇸",
"country_flag_emoji_unicode": "U+1F1FA U+1F1F8",
"calling_code": "1",
"is_eu": False,
},
},
)
module_test.httpx_mock.add_response(
url="http://api.ipstack.com/8.8.8.8?access_key=asdf",
json={
"ip": "8.8.8.8",
"type": "ipv4",
"continent_code": "NA",
"continent_name": "North America",
"country_code": "US",
"country_name": "United States",
"region_code": "OH",
"region_name": "Ohio",
"city": "Glenmont",
"zip": "44628",
"latitude": 40.5369987487793,
"longitude": -82.12859344482422,
"location": {
"geoname_id": None,
"capital": "Washington D.C.",
"languages": [{"code": "en", "name": "English", "native": "English"}],
"country_flag": "https://assets.ipstack.com/flags/us.svg",
"country_flag_emoji": "🇺🇸",
"country_flag_emoji_unicode": "U+1F1FA U+1F1F8",
"calling_code": "1",
"is_eu": False,
},
},
)
def check(self, module_test, events):
assert any(
e.type == "GEOLOCATION" and e.data["ip"] == "8.8.8.8" and e.data["city"] == "Glenmont" for e in events
), "Failed to geolocate IP"