mirror of
https://github.com/aquasecurity/kube-hunter.git
synced 2026-05-11 11:47:15 +00:00
28 lines
797 B
Python
28 lines
797 B
Python
import requests_mock
|
|
import json
|
|
|
|
from kube_hunter.conf import Config, set_config
|
|
from kube_hunter.core.events.types import NewHostEvent
|
|
|
|
set_config(Config())
|
|
|
|
|
|
def test_presetcloud():
|
|
"""Testing if it doesn't try to run get_cloud if the cloud type is already set.
|
|
get_cloud(1.2.3.4) will result with an error
|
|
"""
|
|
expcted = "AWS"
|
|
hostEvent = NewHostEvent(host="1.2.3.4", cloud=expcted)
|
|
assert expcted == hostEvent.cloud
|
|
|
|
|
|
def test_getcloud():
|
|
fake_host = "1.2.3.4"
|
|
expected_cloud = "Azure"
|
|
result = {"cloud": expected_cloud}
|
|
|
|
with requests_mock.mock() as m:
|
|
m.get(f"https://api.azurespeed.com/api/region?ipOrUrl={fake_host}", text=json.dumps(result))
|
|
hostEvent = NewHostEvent(host=fake_host)
|
|
assert hostEvent.cloud == expected_cloud
|