| 1 |
from datetime import datetime |
| 2 |
from typing import Any, Optional |
| 3 |
|
| 4 |
import pytest |
| 5 |
import responses |
| 6 |
from responses import matchers |
| 7 |
|
| 8 |
from censys.search import SearchClient |
| 9 |
from tests.utils import V2_URL, CensysTestCase |
| 10 |
|
| 11 |
TEST_CERT = "fb444eb8e68437bae06232b9f5091bccff62a768ca09e92eb5c9c2cf9d17c426" |
| 12 |
ALTERNATE_CERT = "9b00121b4e85d50667ded1a8aa39855771bdb67ceca6f18726b49374b41f0041" |
| 13 |
TEST_SEARCH_QUERY = "parsed.subject.country: AU" |
| 14 |
TEST_AGGREGATION_FIELD = "parsed.issuer.organization" |
| 15 |
|
| 16 |
EXAMPLE_CERT_JSON = { |
| 17 |
"fingerprint_sha256": "9b00121b4e85d50667ded1a8aa39855771bdb67ceca6f18726b49374b41f0041", |
| 18 |
"fingerprint_sha1": "d508e7f8163fb67434f84091dc7c2ca8afd5234d", |
| 19 |
"fingerprint_md5": "3818d99263b47ab28f7de5b293ee1418", |
| 20 |
"tbs_fingerprint_sha256": "4b098b6bd9459340fb0f3cfb80f0bc3283370c455d57ca20da40e7eecce341d5", |
| 21 |
"tbs_no_ct_fingerprint_sha256": "5c095a40e76c245323086d26d1fa428d3b443b42fb58c7dbb19b32dfe516b749", |
| 22 |
"spki_fingerprint_sha256": "cc9b074ebf41b484a56923d5585594967bda7a7f8b5be187ef0e7ae1ec90003c", |
| 23 |
"parent_spki_fingerprint_sha256": "390bc358202771a65e7be7a87924d7f2a079de04feb5ffd4163fae4fbf9b11e9", |
| 24 |
"parsed": { |
| 25 |
"version": 3, |
| 26 |
"serial_number": "311703586789118042424998420179537559397550", |
| 27 |
"issuer_dn": "C=US, O=Let's Encrypt, CN=R3", |
| 28 |
"issuer": { |
| 29 |
"common_name": ["R3"], |
| 30 |
"country": ["US"], |
| 31 |
"organization": ["Let's Encrypt"], |
| 32 |
}, |
| 33 |
"subject_dn": "CN=www.kgcontracting.co", |
| 34 |
"subject": {"common_name": ["www.kgcontracting.co"]}, |
| 35 |
"subject_key_info": { |
| 36 |
"key_algorithm": {"name": "RSA", "oid": "1.2.840.113549.1.1.1"}, |
| 37 |
"rsa": { |
| 38 |
"exponent": 65537, |
| 39 |
"_encoding": {"modulus": "DISPLAY_HEX"}, |
| 40 |
"modulus": "c0b3b7d595e250fcbc54c6f9e81113c12da29fe35350a02b8ab769a5e43f07df7ac8ff72c482b3e838d64e97cb3fa15e415acbcfe6758a4e7ac401b4a5294ecca6ad1b583ec2136a408524eeadca55ba4a8af490cb9c764efbdecbe59a4ca160905e5972548018f55194e7ac94b2153d97bd5f055d58ad3abe0d1daa3b3c97fed490f1bb58fc5c819618891d05c32d68aeaabada321736e417f0fa58d7093d352c1800191645d1b820f5f7c93301ab7ca78393e953b82719741b735a67ce6a63faec0ac9d2d917f03b9fc0a0ab8012f4763c50118663af897294e85ba6e11c5ca0fd749645c2a58ddf14ad62717b40b5e7b620d256be28789e1ebd62e8046acd", |
| 41 |
"length": 2048, |
| 42 |
}, |
| 43 |
"_encoding": {"fingerprint_sha256": "DISPLAY_HEX"}, |
| 44 |
"fingerprint_sha256": "754cb1e2e2088214a5970662bb5a60aec8a2e29b94f53529aa608abee6682c60", |
| 45 |
"_key": "rsa", |
| 46 |
}, |
| 47 |
"validity_period": { |
| 48 |
"not_before": "2022-12-31T11:37:55Z", |
| 49 |
"not_after": "2023-03-31T11:37:54Z", |
| 50 |
"length_seconds": 7775999, |
| 51 |
}, |
| 52 |
"signature": { |
| 53 |
"signature_algorithm": { |
| 54 |
"name": "SHA256-RSA", |
| 55 |
"oid": "1.2.840.113549.1.1.11", |
| 56 |
}, |
| 57 |
"_encoding": {"value": "DISPLAY_HEX"}, |
| 58 |
"value": "95347a7bd89da6a6bd9adcc509669d933b5e2a29b414317d72b02c583bfadbf616f5b6977824ee80484fe4ae0c38dbb1013d896b5a9db12fdc62296fbefbba84ed089a6e62c148cc9d1e60bfd9cf6e7d1c8f5e0f315872618a6805e5bf48432ce2d0aac07d4ab845a7f68c1a61c3dd37c0e40c26b386b1f37ff2fc50e6eacdc305ecd13da1c43bb1209cb13c5a6387cffb57fad81d01496b3c6499817ed1cf1a0ef809b6b408035b5de72423c6c7f84c3a9e9513c89fa8fc49bf6f90746561ebd1b4ea22e7557d3e505b5ecd289dbb8ce71c4d3acc2e67a27bbb12dd242c8fa512d19dc8b7bd6b88bcc6a6484bb39c894f7b756630a10525a9ab3359030aa2ad", |
| 59 |
"valid": True, |
| 60 |
"self_signed": False, |
| 61 |
}, |
| 62 |
# Removed extensions for brevity |
| 63 |
"serial_number_hex": "039403b7283199171fd9c1af1c8210f5a4ae", |
| 64 |
"redacted": False, |
| 65 |
}, |
| 66 |
"names": ["kgcontracting.co", "www.kgcontracting.co"], |
| 67 |
"validation_level": "DV", |
| 68 |
"validation": { |
| 69 |
"nss": { |
| 70 |
"ever_valid": True, |
| 71 |
"had_trusted_path": True, |
| 72 |
"chains": [ |
| 73 |
{ |
| 74 |
"_encoding": {"sha256fp": "DISPLAY_HEX"}, |
| 75 |
"sha256fp": [ |
| 76 |
"0ac730f6b3a98bab6aa97c9c4c71b34dd5599f4933630e6d24a26751bd12ebac", |
| 77 |
"96bcec06264976f37460779acf28c5a7cfe8a3c0aae11a8ffcee05c0bddf08c6", |
| 78 |
], |
| 79 |
}, |
| 80 |
{ |
| 81 |
"_encoding": {"sha256fp": "DISPLAY_HEX"}, |
| 82 |
"sha256fp": [ |
| 83 |
"67add1166b020ae61b8f5fc96813c04c2aa589960796865572a3c7e737613dfd", |
| 84 |
"96bcec06264976f37460779acf28c5a7cfe8a3c0aae11a8ffcee05c0bddf08c6", |
| 85 |
], |
| 86 |
}, |
| 87 |
], |
| 88 |
"_encoding": {"parents": "DISPLAY_HEX"}, |
| 89 |
"parents": [ |
| 90 |
"0ac730f6b3a98bab6aa97c9c4c71b34dd5599f4933630e6d24a26751bd12ebac", |
| 91 |
"67add1166b020ae61b8f5fc96813c04c2aa589960796865572a3c7e737613dfd", |
| 92 |
], |
| 93 |
"type": "LEAF", |
| 94 |
"is_valid": False, |
| 95 |
"has_trusted_path": False, |
| 96 |
"in_revocation_set": False, |
| 97 |
}, |
| 98 |
# Removed additional validation data for brevity |
| 99 |
}, |
| 100 |
"ever_seen_in_scan": True, |
| 101 |
"raw": "MIIFPzCCBCegAwIBAgISA5QDtygxmRcf2cGvHIIQ9aSuMA0GCSqGSIb3DQEBCwUAMDIxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQDEwJSMzAeFw0yMjEyMzExMTM3NTVaFw0yMzAzMzExMTM3NTRaMB8xHTAbBgNVBAMTFHd3dy5rZ2NvbnRyYWN0aW5nLmNvMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwLO31ZXiUPy8VMb56BETwS2in+NTUKArirdppeQ/B996yP9yxIKz6DjWTpfLP6FeQVrLz+Z1ik56xAG0pSlOzKatG1g+whNqQIUk7q3KVbpKivSQy5x2Tvvey+WaTKFgkF5ZclSAGPVRlOeslLIVPZe9XwVdWK06vg0dqjs8l/7UkPG7WPxcgZYYiR0Fwy1orqq62jIXNuQX8PpY1wk9NSwYABkWRdG4IPX3yTMBq3yng5PpU7gnGXQbc1pnzmpj+uwKydLZF/A7n8Cgq4AS9HY8UBGGY6+JcpToW6bhHFyg/XSWRcKljd8UrWJxe0C157Yg0la+KHieHr1i6ARqzQIDAQABo4ICYDCCAlwwDgYDVR0PAQH/BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBSmobmsnQiGs7WPX6up9C90HZ7ynTAfBgNVHSMEGDAWgBQULrMXt1hWy65QCUDmH6+dixTCxjBVBggrBgEFBQcBAQRJMEcwIQYIKwYBBQUHMAGGFWh0dHA6Ly9yMy5vLmxlbmNyLm9yZzAiBggrBgEFBQcwAoYWaHR0cDovL3IzLmkubGVuY3Iub3JnLzAxBgNVHREEKjAoghBrZ2NvbnRyYWN0aW5nLmNvghR3d3cua2djb250cmFjdGluZy5jbzBMBgNVHSAERTBDMAgGBmeBDAECATA3BgsrBgEEAYLfEwEBATAoMCYGCCsGAQUFBwIBFhpodHRwOi8vY3BzLmxldHNlbmNyeXB0Lm9yZzCCAQMGCisGAQQB1nkCBAIEgfQEgfEA7wB1ALc++yTfnE26dfI5xbpY9Gxd/ELPep81xJ4dCYEl7bSZAAABhWgwUWYAAAQDAEYwRAIgPnPJ0efxcIewdyN8cVA54dXzbNdWNd9EAXdnInNU3X0CIBfPtneRMMSLSWhR1a65cMO0Pg+h8x1rwD8zONe4cWlHAHYA6D7Q2j71BjUy51covIlryQPTy9ERa+zraeF3fW0GvW4AAAGFaDBTWAAABAMARzBFAiEAnHKNpDyb9HALbXPDsxVbVHPWKdW48GxzNYlM5h+/OvACIC5nfWT45zaOOXabpFgS+j0KLjzOdh2OiYJ2OS1ZK1R1MA0GCSqGSIb3DQEBCwUAA4IBAQCVNHp72J2mpr2a3MUJZp2TO14qKbQUMX1ysCxYO/rb9hb1tpd4JO6ASE/krgw427EBPYlrWp2xL9xiKW+++7qE7QiabmLBSMydHmC/2c9ufRyPXg8xWHJhimgF5b9IQyzi0KrAfUq4Raf2jBphw903wOQMJrOGsfN/8vxQ5urNwwXs0T2hxDuxIJyxPFpjh8/7V/rYHQFJazxkmYF+0c8aDvgJtrQIA1td5yQjxsf4TDqelRPIn6j8Sb9vkHRlYevRtOoi51V9PlBbXs0onbuM5xxNOswuZ6J7uxLdJCyPpRLRnci3vWuIvMamSEuznIlPe3VmMKEFJamrM1kDCqKt", |
| 102 |
"added_at": "2023-01-06T12:46:27Z", |
| 103 |
"modified_at": "2023-04-01T16:18:53Z", |
| 104 |
"validated_at": "2023-04-01T16:18:53Z", |
| 105 |
"parse_status": "CERTIFICATE_PARSE_STATUS_SUCCESS", |
| 106 |
"zlint": { |
| 107 |
"version": 3, |
| 108 |
"timestamp": "2023-03-14T22:25:59Z", |
| 109 |
"notices_present": True, |
| 110 |
"failed_lints": ["n_subject_common_name_included"], |
| 111 |
"warnings_present": False, |
| 112 |
"errors_present": False, |
| 113 |
"fatals_present": False, |
| 114 |
}, |
| 115 |
"precert": False, |
| 116 |
"revoked": False, |
| 117 |
"labels": [ |
| 118 |
"untrusted", |
| 119 |
"ever-trusted", |
| 120 |
"ct", |
| 121 |
"leaf", |
| 122 |
"dv", |
| 123 |
"was-trusted", |
| 124 |
"expired", |
| 125 |
], |
| 126 |
} |
| 127 |
VIEW_CERT_JSON = { |
| 128 |
"code": 200, |
| 129 |
"status": "OK", |
| 130 |
"result": EXAMPLE_CERT_JSON, |
| 131 |
} |
| 132 |
BULK_VIEW_CERTS_JSON = { |
| 133 |
"code": 200, |
| 134 |
"status": "OK", |
| 135 |
"result": [EXAMPLE_CERT_JSON], |
| 136 |
} |
| 137 |
SEARCH_CERTS_JSON = { |
| 138 |
"code": 200, |
| 139 |
"status": "OK", |
| 140 |
"result": { |
| 141 |
"query": TEST_SEARCH_QUERY, |
| 142 |
"total": 50000, |
| 143 |
"duration_ms": 356, |
| 144 |
"hits": [EXAMPLE_CERT_JSON], |
| 145 |
"links": {"prev": "prevCursorToken", "next": "nextCursorToken"}, |
| 146 |
}, |
| 147 |
} |
| 148 |
AGGREGATE_CERTS_JSON = { |
| 149 |
"code": 200, |
| 150 |
"status": "OK", |
| 151 |
"result": { |
| 152 |
"query": TEST_SEARCH_QUERY, |
| 153 |
"field": TEST_AGGREGATION_FIELD, |
| 154 |
"total": 58906, |
| 155 |
"duration_ms": 690, |
| 156 |
"buckets": [ |
| 157 |
{"key": "Internet Widgits Pty Ltd", "count": 23748}, |
| 158 |
{"key": "DigiCert Inc", "count": 10885}, |
| 159 |
{"key": "QuoVadis Limited", "count": 1883}, |
| 160 |
{"key": "Entrust, Inc.", "count": 1475}, |
| 161 |
{"key": "Webmin", "count": 1071}, |
| 162 |
], |
| 163 |
}, |
| 164 |
} |
| 165 |
VIEW_HOSTS_BY_CERT_JSON = { |
| 166 |
"code": 200, |
| 167 |
"status": "OK", |
| 168 |
"result": { |
| 169 |
"fp": TEST_CERT, |
| 170 |
"hosts": [ |
| 171 |
{ |
| 172 |
"ip": "string", |
| 173 |
"name": "string", |
| 174 |
"observed_at": "2021-08-02T14:56:38.711Z", |
| 175 |
"first_observed_at": "2021-08-02T14:56:38.711Z", |
| 176 |
} |
| 177 |
], |
| 178 |
"links": {"next": "nextCursorToken"}, |
| 179 |
}, |
| 180 |
} |
| 181 |
OBSERVATIONS_CERT_JSON = { |
| 182 |
"code": 200, |
| 183 |
"status": "OK", |
| 184 |
"result": { |
| 185 |
"fingerprint": "string", |
| 186 |
"observations": [ |
| 187 |
{ |
| 188 |
"ip": "string", |
| 189 |
"name": "string", |
| 190 |
"port": 0, |
| 191 |
"service_name": "string", |
| 192 |
"transport_protocol": "TCP", |
| 193 |
"first_observed_at": "2024-10-17T18:13:23.554Z", |
| 194 |
"last_observed_at": "2024-10-17T18:13:23.554Z", |
| 195 |
"first_updated_at": "2024-10-17T18:13:23.554Z", |
| 196 |
"last_updated_at": "2024-10-17T18:13:23.554Z", |
| 197 |
} |
| 198 |
], |
| 199 |
"links": {"next": "nextCursorToken"}, |
| 200 |
}, |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
class TestCerts(CensysTestCase): |
| 205 |
def setup_method(self): |
| 206 |
self.setUpApi(SearchClient(self.api_id, self.api_secret).v2.certs) |
| 207 |
|
| 208 |
def test_view(self): |
| 209 |
self.responses.add( |
| 210 |
responses.GET, |
| 211 |
f"{V2_URL}/certificates/{TEST_CERT}", |
| 212 |
status=200, |
| 213 |
json=VIEW_CERT_JSON, |
| 214 |
) |
| 215 |
result = self.api.view(TEST_CERT) |
| 216 |
assert result == VIEW_CERT_JSON["result"] |
| 217 |
|
| 218 |
@pytest.mark.parametrize("method_name", ["bulk_post", "bulk", "bulk_view"]) |
| 219 |
def test_bulk_post(self, method_name: str): |
| 220 |
self.responses.add( |
| 221 |
responses.POST, |
| 222 |
f"{V2_URL}/certificates/bulk", |
| 223 |
status=200, |
| 224 |
json=BULK_VIEW_CERTS_JSON, |
| 225 |
) |
| 226 |
method = getattr(self.api, method_name) |
| 227 |
result = method([TEST_CERT, ALTERNATE_CERT]) |
| 228 |
assert result == BULK_VIEW_CERTS_JSON["result"] |
| 229 |
|
| 230 |
def test_bulk_get(self): |
| 231 |
certs = [TEST_CERT, ALTERNATE_CERT] |
| 232 |
params = {"fingerprints": certs} |
| 233 |
self.responses.add( |
| 234 |
responses.GET, |
| 235 |
f"{V2_URL}/certificates/bulk", |
| 236 |
status=200, |
| 237 |
json=BULK_VIEW_CERTS_JSON, |
| 238 |
match=[matchers.query_param_matcher(params)], |
| 239 |
) |
| 240 |
result = self.api.bulk_get(certs) |
| 241 |
assert result == BULK_VIEW_CERTS_JSON["result"] |
| 242 |
|
| 243 |
def test_bulk_get_single(self): |
| 244 |
params = {"fingerprints": TEST_CERT} |
| 245 |
self.responses.add( |
| 246 |
responses.GET, |
| 247 |
f"{V2_URL}/certificates/bulk", |
| 248 |
status=200, |
| 249 |
json=BULK_VIEW_CERTS_JSON, |
| 250 |
match=[matchers.query_param_matcher(params)], |
| 251 |
) |
| 252 |
result = self.api.bulk_get(TEST_CERT) |
| 253 |
assert result == BULK_VIEW_CERTS_JSON["result"] |
| 254 |
|
| 255 |
@pytest.mark.parametrize( |
| 256 |
("method_name", "raw"), |
| 257 |
[ |
| 258 |
("search_post_raw", True), |
| 259 |
("raw_search", True), |
| 260 |
("search_post", False), |
| 261 |
], |
| 262 |
) |
| 263 |
def test_search_post(self, method_name: str, raw: bool): |
| 264 |
self.responses.add( |
| 265 |
responses.POST, |
| 266 |
f"{V2_URL}/certificates/search", |
| 267 |
status=200, |
| 268 |
json=SEARCH_CERTS_JSON, |
| 269 |
) |
| 270 |
method = getattr(self.api, method_name) |
| 271 |
result = method(TEST_SEARCH_QUERY) |
| 272 |
if raw: |
| 273 |
assert result == SEARCH_CERTS_JSON |
| 274 |
else: |
| 275 |
assert result == SEARCH_CERTS_JSON["result"] |
| 276 |
|
| 277 |
@pytest.mark.parametrize( |
| 278 |
("fields", "sort", "cursor"), |
| 279 |
[ |
| 280 |
(None, None, None), |
| 281 |
(["names", "fingerprint_sha256"], None, None), |
| 282 |
(None, ["parsed.issuer.organization", "parsed.subject.country"], None), |
| 283 |
( |
| 284 |
["names", "fingerprint_sha256"], |
| 285 |
["parsed.issuer.organization", "parsed.subject.country"], |
| 286 |
None, |
| 287 |
), |
| 288 |
(None, None, "nextCursorToken"), |
| 289 |
], |
| 290 |
) |
| 291 |
def test_search( |
| 292 |
self, |
| 293 |
fields: Optional[list[str]], |
| 294 |
sort: Optional[list[str]], |
| 295 |
cursor: Optional[str], |
| 296 |
): |
| 297 |
self.responses.add( |
| 298 |
responses.POST, |
| 299 |
f"{V2_URL}/certificates/search", |
| 300 |
status=200, |
| 301 |
json=SEARCH_CERTS_JSON, |
| 302 |
) |
| 303 |
query = self.api.search(TEST_SEARCH_QUERY, fields=fields, sort=sort, cursor=cursor) |
| 304 |
assert next(query) == SEARCH_CERTS_JSON["result"]["hits"] |
| 305 |
|
| 306 |
@pytest.mark.parametrize( |
| 307 |
("params", "expected_params"), |
| 308 |
[ |
| 309 |
({}, {"q": TEST_SEARCH_QUERY, "per_page": 50}), |
| 310 |
({"per_page": 1}, {"q": TEST_SEARCH_QUERY, "per_page": 1}), |
| 311 |
( |
| 312 |
{"cursor": "nextCursorToken"}, |
| 313 |
{"q": TEST_SEARCH_QUERY, "cursor": "nextCursorToken", "per_page": 50}, |
| 314 |
), |
| 315 |
( |
| 316 |
{"fields": ["names"]}, |
| 317 |
{"q": TEST_SEARCH_QUERY, "fields": "names", "per_page": 50}, |
| 318 |
), |
| 319 |
( |
| 320 |
{ |
| 321 |
"fields": [ |
| 322 |
"names", |
| 323 |
"fingerprint_sha256", |
| 324 |
"parsed.issuer.organization", |
| 325 |
"parsed.subject.postal_code", |
| 326 |
] |
| 327 |
}, |
| 328 |
{ |
| 329 |
"q": TEST_SEARCH_QUERY, |
| 330 |
"fields": [ |
| 331 |
"names", |
| 332 |
"fingerprint_sha256", |
| 333 |
"parsed.issuer.organization", |
| 334 |
"parsed.subject.postal_code", |
| 335 |
], |
| 336 |
"per_page": 50, |
| 337 |
}, |
| 338 |
), |
| 339 |
( |
| 340 |
{"sort": "parsed.subject.postal_code"}, |
| 341 |
{ |
| 342 |
"q": TEST_SEARCH_QUERY, |
| 343 |
"sort": "parsed.subject.postal_code", |
| 344 |
"per_page": 50, |
| 345 |
}, |
| 346 |
), |
| 347 |
( |
| 348 |
{"sort": ["parsed.subject.postal_code", "parsed.subject.country"]}, |
| 349 |
{ |
| 350 |
"q": TEST_SEARCH_QUERY, |
| 351 |
"sort": ["parsed.subject.postal_code", "parsed.subject.country"], |
| 352 |
"per_page": 50, |
| 353 |
}, |
| 354 |
), |
| 355 |
], |
| 356 |
) |
| 357 |
def test_search_get(self, params: dict[str, Any], expected_params: dict[str, Any]): |
| 358 |
self.responses.add( |
| 359 |
responses.GET, |
| 360 |
f"{V2_URL}/certificates/search", |
| 361 |
status=200, |
| 362 |
json=SEARCH_CERTS_JSON, |
| 363 |
match=[matchers.query_param_matcher(expected_params)], |
| 364 |
) |
| 365 |
result = self.api.search_get(TEST_SEARCH_QUERY, **params) |
| 366 |
assert result == SEARCH_CERTS_JSON["result"] |
| 367 |
|
| 368 |
def test_aggregate(self): |
| 369 |
params = { |
| 370 |
"q": TEST_SEARCH_QUERY, |
| 371 |
"field": TEST_AGGREGATION_FIELD, |
| 372 |
"num_buckets": 50, |
| 373 |
} |
| 374 |
self.responses.add( |
| 375 |
responses.GET, |
| 376 |
f"{V2_URL}/certificates/aggregate", |
| 377 |
status=200, |
| 378 |
json=AGGREGATE_CERTS_JSON, |
| 379 |
match=[matchers.query_param_matcher(params)], |
| 380 |
) |
| 381 |
result = self.api.aggregate(TEST_SEARCH_QUERY, TEST_AGGREGATION_FIELD) |
| 382 |
assert result == AGGREGATE_CERTS_JSON["result"] |
| 383 |
|
| 384 |
def test_get_hosts_by_cert(self): |
| 385 |
self.responses.add( |
| 386 |
responses.GET, |
| 387 |
f"{V2_URL}/certificates/{TEST_CERT}/hosts", |
| 388 |
status=200, |
| 389 |
json=VIEW_HOSTS_BY_CERT_JSON, |
| 390 |
) |
| 391 |
result = self.api.get_hosts_by_cert(TEST_CERT) |
| 392 |
assert result == VIEW_HOSTS_BY_CERT_JSON["result"] |
| 393 |
|
| 394 |
def test_get_hosts_by_cert_with_cursor(self): |
| 395 |
self.responses.add( |
| 396 |
responses.GET, |
| 397 |
f"{V2_URL}/certificates/{TEST_CERT}/hosts?cursor=nextCursorToken", |
| 398 |
status=200, |
| 399 |
json=VIEW_HOSTS_BY_CERT_JSON, |
| 400 |
) |
| 401 |
results = self.api.get_hosts_by_cert(TEST_CERT, cursor="nextCursorToken") |
| 402 |
assert results == VIEW_HOSTS_BY_CERT_JSON["result"] |
| 403 |
|
| 404 |
def test_get_observations_by_cert(self): |
| 405 |
self.responses.add( |
| 406 |
responses.GET, |
| 407 |
f"{V2_URL}/certificates/{TEST_CERT}/observations", |
| 408 |
status=200, |
| 409 |
json=OBSERVATIONS_CERT_JSON, |
| 410 |
) |
| 411 |
result = self.api.get_observations(TEST_CERT) |
| 412 |
assert result == OBSERVATIONS_CERT_JSON["result"] |
| 413 |
|
| 414 |
def test_get_observations_by_cert_with_cursor(self): |
| 415 |
self.responses.add( |
| 416 |
responses.GET, |
| 417 |
f"{V2_URL}/certificates/{TEST_CERT}/observations?per_page=50&cursor=nextCursorToken", |
| 418 |
status=200, |
| 419 |
json=OBSERVATIONS_CERT_JSON, |
| 420 |
) |
| 421 |
results = self.api.get_observations(TEST_CERT, cursor="nextCursorToken") |
| 422 |
assert results == OBSERVATIONS_CERT_JSON["result"] |
| 423 |
|
| 424 |
def test_get_observations_with_rfc3339_timestampts(self): |
| 425 |
self.responses.add( |
| 426 |
responses.GET, |
| 427 |
f"{V2_URL}/certificates/{TEST_CERT}/observations?per_page=50&start_time=2024-10-14T18%3A13%3A23.554000Z&end_time=2024-10-17T18%3A13%3A23.554000Z", |
| 428 |
status=200, |
| 429 |
json=OBSERVATIONS_CERT_JSON, |
| 430 |
) |
| 431 |
result = self.api.get_observations( |
| 432 |
TEST_CERT, |
| 433 |
start_time=datetime(2024, 10, 14, 18, 13, 23, 554000), |
| 434 |
end_time=datetime(2024, 10, 17, 18, 13, 23, 554000), |
| 435 |
) |
| 436 |
assert result == OBSERVATIONS_CERT_JSON["result"] |