def test_parse_email_address(self): contact_dict = {"contact_type": "ADMIN", "email_address": "*****@*****.**"} c = WhoisContact.from_dict(contact_dict) self.assertEqual("ADMIN", c.contact_type) self.assertEqual("*****@*****.**", c.email_address.address_value) self.assertEqual(Address.CAT_EMAIL, c.email_address.category)
def test_parse_email_address(self): contact_dict = {'contact_type': "ADMIN", 'email_address': "*****@*****.**"} c = WhoisContact.from_dict(contact_dict) self.assertEqual("ADMIN", c.contact_type) self.assertEqual("*****@*****.**", c.email_address.address_value) self.assertEqual(Address.CAT_EMAIL, c.email_address.category)
def test_issue_227_binding_init(self): # Fax_Number and Organization were added to the __init__ method of # WhoisContactType, but not to its subclass (WhoisRegistrantType). Once # the objects are constructed, they should have equivalent dictionary # represesntations (as long as the extra fields in the subclass are not # present). contact_obj = WhoisContactType( contact_type="ADMIN", Contact_ID=StringObjectPropertyType(valueOf_="abc123"), Fax_Number=StringObjectPropertyType(valueOf_=u("(800) 555-1200")), Organization=StringObjectPropertyType(valueOf_=u("XYZ Hosting")), ) contact = WhoisContact.from_obj(contact_obj) reg_obj = WhoisRegistrantInfoType( contact_type="ADMIN", Contact_ID=StringObjectPropertyType(valueOf_="abc123"), Fax_Number=StringObjectPropertyType(valueOf_=u("(800) 555-1200")), Organization=StringObjectPropertyType(valueOf_=u("XYZ Hosting")), ) registrant = WhoisRegistrant.from_obj(reg_obj) self.assertEqual(contact.to_dict(), registrant.to_dict())
def __create_whois_object(self, domain): """ Creates a CybOX WHOISObjectType object """ if not domain: return None if(self.__verbose_output): sys.stderr.write("** creating Whois object for: %s\n" % domain) if self.http_whois: record = self.__get_whois_record_http(domain) else: record = self.__get_whois_record(domain) if not record: return None whois = WhoisEntry() record['status'] = ['OK' if status == 'ACTIVE' else status for status in record['status']] #Only build registrar info objects if we have the relevant info if (record['registrar'] or record['whois_server'] or record['registrar_address'] or record['referral_url'] or record['registrar_contacts']): registrar = WhoisRegistrar() registrar.name = String(record.get('registrar')) registrar.address = String(record.get('registrar_address')) registrar.whois_server = URI(record.get('whois_server')) registrar.referral_url = URI(record.get('referral_url')) contacts = WhoisContacts() for email in record['registrar_contacts']: contact = WhoisContact() contact.contact_type = 'ADMIN' contact.name = String(record.get('registrar')) contact.email_address = EmailAddress(email) contacts.append(contact) registrar.contacts = contacts whois.registrar_info = registrar whois.domain_name = self.__create_domain_name_object(record.get('domain_name')) nservers = WhoisNameservers() for url in record.get('name_servers', []): nservers.append(self.__create_url_object(url)) if nservers: whois.nameservers = nservers status = WhoisStatuses() for s in record.get('status', []): status.append(WhoisStatus(s)) if status: whois.status = status whois.updated_date = DateTime(record.get('updated_date')) whois.creation_date = DateTime(record.get('creation_date')) whois.expiration_date = DateTime(record.get('expiration_date')) return whois