diff --git a/tests/samples/bad_response_01.json b/tests/samples/bad_response_01.json new file mode 100644 index 0000000..c66b659 --- /dev/null +++ b/tests/samples/bad_response_01.json @@ -0,0 +1,420 @@ +{ + "handle": null, + "ldhName": "something-not-real.com", + "nameServers": [ + { + "ldhName": "a.share-dns.com", + "status": [ + "active" + ], + "objectClassName": "nameserver", + "lang": "en" + }, + { + "ldhName": "b.share-dns.net", + "status": [ + "active" + ], + "objectClassName": "nameserver", + "lang": "en" + } + ], + "secureDNS": { + "delegationSigned": false + }, + "entities": [ + { + "vcardArray": [ + "vcard", + [ + "version", + "{}", + "text", + "4.0" + ], + [ + "kind", + "{}", + "text", + "individual" + ], + [ + "fn", + "{}", + "text", + "Domain" + ], + [ + "adr", + "{}", + "text" + ], + [ + [ + "{}", + "{}", + "City, State, undefined" + ], + "New York", + "Nebraska", + "10001", + "United States" + ], + [ + "email", + "{}", + "text", + "cwp7panel@gmail.com" + ], + [ + "tel", + { + "type": "voice" + }, + "uri", + "+1.123456789" + ] + ], + "status": [ + "Active" + ], + "roles": [ + "registrant" + ], + "objectClassName": "entity", + "lang": "en" + }, + { + "vcardArray": [ + "vcard", + [ + "version", + "{}", + "text", + "4.0" + ], + [ + "kind", + "{}", + "text", + "individual" + ], + [ + "fn", + "{}", + "text", + "Domain" + ], + [ + "adr", + "{}", + "text" + ], + [ + [ + "{}", + "{}", + "City, State, undefined" + ], + "New York", + "Nebraska", + "10001", + "United States" + ], + [ + "email", + "{}", + "text", + "cwp7panel@gmail.com" + ], + [ + "tel", + { + "type": "voice" + }, + "uri", + "+1.123456789" + ] + ], + "status": [ + "Active" + ], + "objectClassName": "entity", + "lang": "en" + }, + { + "vcardArray": [ + "vcard", + [ + "version", + "{}", + "text", + "4.0" + ], + [ + "kind", + "{}", + "text", + "individual" + ], + [ + "fn", + "{}", + "text", + "Domain" + ], + [ + "adr", + "{}", + "text" + ], + [ + [ + "{}", + "{}", + "City, State, undefined" + ], + "New York", + "Nebraska", + "10001", + "United States" + ], + [ + "email", + "{}", + "text", + "cwp7panel@gmail.com" + ], + [ + "tel", + { + "type": "voice" + }, + "uri", + "+1.123456789" + ] + ], + "status": [ + "Active" + ], + "roles": [ + "billing" + ], + "objectClassName": "entity", + "lang": "en" + }, + { + "vcardArray": [ + "vcard", + [ + "version", + "{}", + "text", + "4.0" + ], + [ + "kind", + "{}", + "text", + "individual" + ], + [ + "fn", + "{}", + "text", + "Domain" + ], + [ + "adr", + "{}", + "text" + ], + [ + [ + "{}", + "{}", + "City, State, undefined" + ], + "New York", + "Nebraska", + "10001", + "United States" + ], + [ + "email", + "{}", + "text", + "cwp7panel@gmail.com" + ], + [ + "tel", + { + "type": "voice" + }, + "uri", + "+1.123456789" + ] + ], + "status": [ + "Active" + ], + "roles": [ + "tech" + ], + "objectClassName": "entity", + "lang": "en" + }, + { + "vcardArray": [ + [ + "version", + "{}", + "text", + "4.0" + ], + [ + "version", + "{}", + "text", + "4.0" + ] + ], + "status": [ + "active" + ], + "roles": [ + "Registrar" + ], + "objectClassName": "entity", + "lang": "en", + "publicIds": [ + { + "type": "IANA Registrar ID", + "identifier": "1250" + } + ], + "entities": { + "vcardArray": [ + "vcard", + [ + [ + "version", + "{}", + "text", + "4.0" + ], + [ + "org", + "{}", + "text", + "OwnRegistrar Inc" + ], + [ + "fn", + "{}", + "text", + "individual" + ], + [ + "tel", + { + "type": "voice" + }, + "uri", + "+1.212 401 6235" + ], + [ + "email", + "{}", + "text", + "abuse@ownregistrar.com" + ] + ] + ], + "status": [ + "active" + ], + "roles": [ + "Registrar" + ], + "objectClassName": "abuse", + "lang": "en" + }, + "links": [ + { + "title": "Registrar URL", + "type": "application/rdap+json", + "rel": "self", + "href": "www.ownregistrar.com" + } + ] + } + ], + "status": [ + "active" + ], + "events": [ + { + "eventAction": "registration", + "eventDate": "2023-07-05T00:00:00" + }, + { + "eventAction": "expiration", + "eventDate": "2024-07-05T00:00:00" + }, + { + "eventAction": "last changed", + "eventDate": "2023-07-05T00:00:00" + }, + { + "eventAction": "last update of RDAP database", + "eventDate": "2023-10-02T15:31:50" + } + ], + "notices": [ + { + "title": "Status Codes", + "description": [ + "For more information on domain status codes, please visit https://icann.org/epp" + ], + "links": [ + { + "title": "More information on domain status codes", + "type": "text/html", + "rel": "related", + "href": "https://icann.org/epp" + } + ] + }, + { + "title": "RDDS Inaccuracy Complaint Form", + "description": [ + "URL of the ICANN RDDS Inaccuracy Complaint Form: https://www.icann.org/wicf/." + ], + "links": [ + { + "title": "CANN RDDS Inaccuracy Complaint Form", + "type": "text/html", + "rel": "related", + "href": "https://www.icann.org/wicf/" + } + ] + }, + { + "title": "Terms of Use", + "links": [ + { + "title": "Terms of Use", + "href": "https://rdapserver.net/terms-of-use/" + } + ] + } + ], + "rdapConformance": [ + "icann_rdap_response_profile_0", + "icann_rdap_technical_implementation_guide_0", + "rdap_level_0" + ], + "objectClassName": "domain", + "lang": "en" +} diff --git a/tests/samples/bad_response_02.json b/tests/samples/bad_response_02.json new file mode 100644 index 0000000..6effd7a --- /dev/null +++ b/tests/samples/bad_response_02.json @@ -0,0 +1,80 @@ +{ + "handle": null, + "ldhName": "something-not-real.com", + "nameServers": [ + "BOOOOOM" + ], + "secureDNS": { + "delegationSigned": false + }, + "entities": [ + {"vcardArray": {}} + ], + "status": [ + "active" + ], + "events": [ + { + "eventAction": "registration", + "eventDate": "2023-07-05T00:00:00" + }, + { + "eventAction": "expiration", + "eventDate": "2024-07-05T00:00:00" + }, + { + "eventAction": "last changed", + "eventDate": "2023-07-05T00:00:00" + }, + { + "eventAction": "last update of RDAP database", + "eventDate": "2023-10-02T15:31:50" + } + ], + "notices": [ + { + "title": "Status Codes", + "description": [ + "For more information on domain status codes, please visit https://icann.org/epp" + ], + "links": [ + { + "title": "More information on domain status codes", + "type": "text/html", + "rel": "related", + "href": "https://icann.org/epp" + } + ] + }, + { + "title": "RDDS Inaccuracy Complaint Form", + "description": [ + "URL of the ICANN RDDS Inaccuracy Complaint Form: https://www.icann.org/wicf/." + ], + "links": [ + { + "title": "CANN RDDS Inaccuracy Complaint Form", + "type": "text/html", + "rel": "related", + "href": "https://www.icann.org/wicf/" + } + ] + }, + { + "title": "Terms of Use", + "links": [ + { + "title": "Terms of Use", + "href": "https://rdapserver.net/terms-of-use/" + } + ] + } + ], + "rdapConformance": [ + "icann_rdap_response_profile_0", + "icann_rdap_technical_implementation_guide_0", + "rdap_level_0" + ], + "objectClassName": "domain", + "lang": "en" +} diff --git a/tests/test_response.py b/tests/test_response.py index ad1a8b6..b5f43e8 100644 --- a/tests/test_response.py +++ b/tests/test_response.py @@ -4,19 +4,21 @@ from datetime import datetime from whodap.response import DomainResponse, WHOISKeys +from whodap.errors import RDAPConformanceException -class TestDomainResponse(unittest.TestCase): - def load_file(self, filename: str): - base_dir = os.path.abspath(os.path.dirname(__file__)) - with open(os.path.join(base_dir, "samples", filename)) as data: - return data.read() +def load_file(filename: str): + base_dir = os.path.abspath(os.path.dirname(__file__)) + with open(os.path.join(base_dir, "samples", filename)) as data: + return data.read() + +class TestDomainResponse(unittest.TestCase): def setUp(self) -> None: self.address = "123 main street" self.phone = "tel+18005555555" self.test_filename = "google.com.json" - self.json_string = self.load_file(self.test_filename) + self.json_string = load_file(self.test_filename) self.resp = DomainResponse.from_json(self.json_string) def test_to_dict(self): @@ -42,7 +44,19 @@ def test_to_whois_dict(self): ): assert type(v) == datetime, f"{type(v)} is not datetime" if k == WHOISKeys.DNSSEC: - assert type(v) == bool, f"{type(v)} is not bool" + assert type(v) == str, f"{type(v)} is not bool" + + def test_to_whois_dict_strict(self): + self.test_filename = "bad_response_01.json" + self.json_string = load_file(self.test_filename) + self.resp = DomainResponse.from_json(self.json_string) + self.assertRaises( + RDAPConformanceException, self.resp.to_whois_dict, strict=True + ) + self.test_filename = "bad_response_02.json" + self.json_string = load_file(self.test_filename) + self.resp = DomainResponse.from_json(self.json_string) + self.assertRaises(RDAPConformanceException, self.resp.to_whois_dict, True) def test_to_whois_json(self): whois_dict = self.resp.to_whois_dict() @@ -92,7 +106,7 @@ def test_convert_dates(self): ), f"unexpected output from _convert_date" def test_flat_entities(self): - flattened_entities = self.resp._flat_entities(self.resp.entities) + flattened_entities = self.resp._flat_entities(self.resp.entities, strict=False) for role, role_values in flattened_entities.items(): assert role in ( "abuse",