def doEppDomainUpdate(self, *args, **kwargs): """ Action method. """ add_contacts, remove_contacts, change_registrant = zdomains.compare_contacts( domain_object=self.target_domain, domain_info_response=args[0], ) add_nameservers, remove_nameservers = zdomains.compare_nameservers( domain_object=self.target_domain, domain_info_response=args[0], ) if not (add_contacts or remove_contacts or add_nameservers or remove_nameservers or change_registrant): self.event('no-updates') return try: response = rpc_client.cmd_domain_update( domain=self.target_domain.name, change_registrant=change_registrant, add_contacts_list=add_contacts, remove_contacts_list=remove_contacts, add_nameservers_list=add_nameservers, remove_nameservers_list=remove_nameservers, ) except rpc_error.EPPError as exc: self.log(self.debug_level, 'Exception in doEppDomainUpdate: %s' % exc) self.event('error', exc) else: self.event('response', response)
def test_switch_3_contacts(self): add_contacts, remove_contacts, change_registrant = zdomains.compare_contacts( self._prepare_domain(reg_id='registrant_0', admin_id='admin_1', bil_id='billing_1', tech_id='tech_1'), self._prepare_response(reg_id='registrant_0', admin_id='admin_2', bil_id='billing_2', tech_id='tech_2') ) assert add_contacts == [{'id': 'admin_1', 'type': 'admin'}, {'id': 'billing_1', 'type': 'billing'}, {'id': 'tech_1', 'type': 'tech'}, ] assert remove_contacts == [{'id': 'admin_2', 'type': 'admin'}, {'id': 'billing_2', 'type': 'billing'}, {'id': 'tech_2', 'type': 'tech'}, ] assert change_registrant is None
def test_remove_1_contact(self): add_contacts, remove_contacts, change_registrant = zdomains.compare_contacts( self._prepare_domain(reg_id='registrant_0', admin_id=None, bil_id='billing_0', tech_id='tech_0'), self._prepare_response(reg_id='registrant_0', admin_id='admin_0', bil_id='billing_0', tech_id='tech_0') ) assert add_contacts == [] assert remove_contacts == [{'id': 'admin_0', 'type': 'admin'}, ] assert change_registrant is None
def test_change_registrant(self): add_contacts, remove_contacts, change_registrant = zdomains.compare_contacts( self._prepare_domain(reg_id='registrant_1', admin_id='admin_0', bil_id='billing_0', tech_id='tech_0'), self._prepare_response(reg_id='registrant_2', admin_id='admin_0', bil_id='billing_0', tech_id='tech_0') ) assert add_contacts == [] assert remove_contacts == [] assert change_registrant == 'registrant_1'
def doPrepareDomainChange(self, *args, **kwargs): """ Action method. """ self.add_contacts = [] self.remove_contacts = [] self.change_registrant = None self.add_contacts, self.remove_contacts, self.change_registrant = zdomains.compare_contacts( domain_object=self.target_domain, domain_info_response=args[0], target_contacts=list(self.target_contacts.items()), )
def doUseExistingContacts(self, *args, **kwargs): """ Action method. """ self.new_registrant_epp_id = self.known_registrant.epp_id first_contact = self.known_registrant.owner.contacts.first() if not first_contact: first_contact = zcontacts.contact_create_from_profile( self.known_registrant.owner, self.known_registrant.owner.profile) if first_contact.epp_id: if not self.new_domain_contacts.get('admin'): self.new_domain_contacts['admin'] = first_contact.epp_id if self.target_domain: self.target_domain.refresh_from_db() target_contacts = None if not self.target_domain.list_contacts(): target_contacts = list({ 'admin': first_contact, 'billing': first_contact, 'tech': first_contact, }.items()), self.contacts_to_add, self.contacts_to_remove, change_registrant = zdomains.compare_contacts( domain_object=self.target_domain, domain_info_response=self.domain_info_response, target_contacts=target_contacts, ) if change_registrant and self.rewrite_contacts: self.new_registrant_epp_id = change_registrant self.received_contacts.clear() for role, cont in self.target_domain.list_contacts(): if cont and cont.epp_id: self.received_contacts.append({ 'type': role, 'id': cont.epp_id, })
def doEppDomainInfo(self, *args, **kwargs): """ Action method. """ try: response = rpc_client.cmd_domain_info( domain=self.domain_name, raise_for_result=False, ) except rpc_error.EPPError as exc: self.log(self.debug_level, 'Exception in doEppDomainInfo: %s' % exc) self.event('error', exc) return # catch "2201 Authorization error" result, that means domain exists, but have another owner try: code = int(response['epp']['response']['result']['@code']) except ( ValueError, IndexError, TypeError, ) as exc: self.log(self.debug_level, 'Exception in doEppDomainInfo: %s' % exc) self.event('error', exc) return if code == 2201: self.domain_info_response = response self.event('response', response) return # check create/expire date try: datetime.datetime.strptime( response['epp']['response']['resData']['infData']['exDate'], '%Y-%m-%dT%H:%M:%S.%fZ', ) datetime.datetime.strptime( response['epp']['response']['resData']['infData']['crDate'], '%Y-%m-%dT%H:%M:%S.%fZ', ) except Exception as exc: self.log(self.debug_level, 'Exception in doEppDomainInfo: %s' % exc) raise rpc_error.EPPBadResponse('response field not recognized') # detect current nameservers try: current_nameservers = response['epp']['response']['resData'][ 'infData']['ns']['hostObj'] except: current_nameservers = [] if not isinstance(current_nameservers, list): current_nameservers = [ current_nameservers, ] self.received_nameservers = current_nameservers # detect current contacts try: current_contacts = response['epp']['response']['resData'][ 'infData']['contact'] except: current_contacts = [] if not isinstance(current_contacts, list): current_contacts = [ current_contacts, ] self.received_contacts = [{ 'type': i['@type'], 'id': i['#text'], } for i in current_contacts] self.new_domain_contacts = { i['@type']: i['#text'] for i in current_contacts } # compare known contacts we have in DB with contacts received from back-end if not self.target_domain: self.contacts_changed = True else: if not self.refresh_contacts: add_contacts, remove_contacts, change_registrant = zdomains.compare_contacts( domain_object=self.target_domain, domain_info_response=response, ) if add_contacts or remove_contacts or change_registrant: self.contacts_changed = True # detect current registrant try: self.received_registrant_epp_id = response['epp']['response'][ 'resData']['infData']['registrant'] except Exception as exc: self.log(self.debug_level, 'Exception in doEppDomainInfo: %s' % exc) self.event('error', zerrors.RegistrantUnknown(response=response)) return self.domain_info_response = response if self.expected_owner: # if pending order exists, select registrant from the owner of that order self.known_registrant = self.expected_owner.registrants.first() if self.known_registrant and self.known_registrant.epp_id: self.received_registrant_epp_id = self.known_registrant.epp_id logger.info('trying to use registrant from existing owner: %r', self.known_registrant) else: # find registrant in local DB self.known_registrant = zcontacts.registrant_find( epp_id=self.received_registrant_epp_id) logger.info('trying to find registrant by epp id %r: %r', self.received_registrant_epp_id, self.known_registrant) if self.rewrite_contacts and self.known_registrant: logger.info( 'going to rewrite domain %r contacts from existing owner %r', self.domain_name, self.known_registrant.owner) self.event('rewrite-contacts', response) return if self.known_registrant: logger.info('registrant for domain %r is known: %r', self.domain_name, self.known_registrant) self.event('response', response) return if not self.create_new_owner_allowed: if self.domain_transferred_away: logger.error('domain %r is marked as transferred away', self.domain_name) self.event('domain-transferred-away') else: # fail if registrant not exist in local DB # that means owner of the domain changed, or his contact is not in sync with back-end # this also happens when domain is transferred to Zenaida, but user account not exist yet logger.error('registrant %r not exist in local DB', self.received_registrant_epp_id) self.event( 'error', zerrors.RegistrantAuthFailed( 'registrant not exist in local DB')) return # currently registrant not exist in local DB, user account needs to be checked and created first logger.info( 'registrant not exist in local DB, going to create new registrant') self.event('registrant-unknown', response)