| 1 |
import responses |
| 2 |
|
| 3 |
from censys.asm import Beta |
| 4 |
|
| 5 |
from ..utils import CensysTestCase |
| 6 |
from .utils import BETA_URL |
| 7 |
|
| 8 |
TEST_LOGBOOK_DATA = { |
| 9 |
"nextWindowCursor": "string", |
| 10 |
"results": [ |
| 11 |
{ |
| 12 |
"type": "HOST", |
| 13 |
"logSubType": "ASSOCIATE", |
| 14 |
"ip": "string", |
| 15 |
"id": 0, |
| 16 |
"timestamp": "string", |
| 17 |
"logData": {}, |
| 18 |
} |
| 19 |
], |
| 20 |
} |
| 21 |
TEST_CLOUD_ASSETS = { |
| 22 |
"addedAssets": ["string"], |
| 23 |
"removedAssets": ["string"], |
| 24 |
"updatedAssets": ["string"], |
| 25 |
} |
| 26 |
TEST_INPUT_ASSETS = { |
| 27 |
"pageNumber": 0, |
| 28 |
"pageSize": 0, |
| 29 |
"totalPages": 0, |
| 30 |
"totalItems": 0, |
| 31 |
"assets": [{"type": "ASN", "value": "string", "source": "API", "label": "string"}], |
| 32 |
} |
| 33 |
TEST_ASSET_COUNTS = { |
| 34 |
"environment": "ALL", |
| 35 |
"newAssetsSince": "string", |
| 36 |
"requestCompleteTime": "string", |
| 37 |
"totalCount": 0, |
| 38 |
"totalNewCount": 0, |
| 39 |
"totalCountsBySubEnvironment": [{"environment": "string", "totalCount": 0, "totalNewCount": 0}], |
| 40 |
} |
| 41 |
TEST_HOST_COUNTS_BY_COUNTRY = { |
| 42 |
"environment": "ALL", |
| 43 |
"newAssetsSince": "string", |
| 44 |
"requestCompleteTime": "string", |
| 45 |
"totalCount": 0, |
| 46 |
"totalNewCount": 0, |
| 47 |
"totalCountsBySubEnvironment": [ |
| 48 |
{ |
| 49 |
"environment": "string", |
| 50 |
"totalCountsByCountry": [ |
| 51 |
{ |
| 52 |
"country": "string", |
| 53 |
"countryCode": "string", |
| 54 |
"totalCount": 0, |
| 55 |
"totalNewCount": 0, |
| 56 |
} |
| 57 |
], |
| 58 |
} |
| 59 |
], |
| 60 |
} |
| 61 |
TEST_USER_WORKSPACES = [{"workspace": "string", "roles": ["string"]}] |
| 62 |
|
| 63 |
|
| 64 |
class BetaUnitTest(CensysTestCase): |
| 65 |
def setup_method(self): |
| 66 |
self.client = Beta(self.api_key) |
| 67 |
|
| 68 |
def test_get_logbook_data(self): |
| 69 |
# Setup response |
| 70 |
self.responses.add( |
| 71 |
responses.POST, |
| 72 |
BETA_URL + "/logbook/getLogbookData", |
| 73 |
status=200, |
| 74 |
json=TEST_LOGBOOK_DATA, |
| 75 |
) |
| 76 |
# Actual call |
| 77 |
res = self.client.get_logbook_data(filters={"key": "value"}, cursor="cursor") |
| 78 |
# Assertions |
| 79 |
assert res == TEST_LOGBOOK_DATA |
| 80 |
|
| 81 |
def test_add_cloud_assets(self): |
| 82 |
# Setup response |
| 83 |
self.responses.add( |
| 84 |
responses.POST, |
| 85 |
BETA_URL + "/cloudConnector/addCloudAssets", |
| 86 |
status=200, |
| 87 |
json=TEST_CLOUD_ASSETS, |
| 88 |
) |
| 89 |
# Actual call |
| 90 |
res = self.client.add_cloud_assets(cloud_connector_uid="uid", cloud_assets=[{"key": "value"}]) |
| 91 |
# Assertions |
| 92 |
assert res == TEST_CLOUD_ASSETS |
| 93 |
|
| 94 |
def test_get_input_assets(self): |
| 95 |
# Setup response |
| 96 |
self.responses.add( |
| 97 |
responses.GET, |
| 98 |
BETA_URL + "/assets/inputAssets", |
| 99 |
status=200, |
| 100 |
json=TEST_INPUT_ASSETS, |
| 101 |
) |
| 102 |
# Actual call |
| 103 |
res = self.client.get_input_assets(page_number=1, page_size=10) |
| 104 |
# Assertions |
| 105 |
assert res == TEST_INPUT_ASSETS |
| 106 |
|
| 107 |
def test_get_asset_counts(self): |
| 108 |
# Setup response |
| 109 |
self.responses.add( |
| 110 |
responses.GET, |
| 111 |
BETA_URL + "/assets/counts", |
| 112 |
status=200, |
| 113 |
json=TEST_ASSET_COUNTS, |
| 114 |
) |
| 115 |
# Actual call |
| 116 |
res = self.client.get_asset_counts(since="2021-01-01T00:00:00Z", environment="env", asset_type="type") |
| 117 |
# Assertions |
| 118 |
assert res == TEST_ASSET_COUNTS |
| 119 |
|
| 120 |
def test_get_host_counts_by_country(self): |
| 121 |
# Setup response |
| 122 |
self.responses.add( |
| 123 |
responses.GET, |
| 124 |
BETA_URL + "/assets/hostCountsByCountry", |
| 125 |
status=200, |
| 126 |
json=TEST_HOST_COUNTS_BY_COUNTRY, |
| 127 |
) |
| 128 |
# Actual call |
| 129 |
res = self.client.get_host_counts_by_country(since="2021-01-01T00:00:00Z", environment="env") |
| 130 |
# Assertions |
| 131 |
assert res == TEST_HOST_COUNTS_BY_COUNTRY |
| 132 |
|
| 133 |
def test_get_user_workspaces(self): |
| 134 |
# Setup response |
| 135 |
self.responses.add( |
| 136 |
responses.GET, |
| 137 |
BETA_URL + "/users/user_uuid/workspaces", |
| 138 |
status=200, |
| 139 |
json=TEST_USER_WORKSPACES, |
| 140 |
) |
| 141 |
# Actual call |
| 142 |
res = self.client.get_user_workspaces(user_uuid="user_uuid") |
| 143 |
# Assertions |
| 144 |
assert res == TEST_USER_WORKSPACES |