mirror of
https://github.com/aquasecurity/kube-hunter.git
synced 2026-05-14 05:07:02 +00:00
Fix linting issues with flake8 and black. Add pre-commit congifuration, update documnetation for it. Apply linting check in Travis CI.
24 lines
719 B
Python
24 lines
719 B
Python
import requests_mock
|
|
import json
|
|
|
|
from kube_hunter.core.events.types.common import NewHostEvent
|
|
|
|
|
|
# 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
|
|
def test_presetcloud():
|
|
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
|