示例#1
0
 def doEppDomainInfo(self, *args, **kwargs):
     """
     Action method.
     """
     if self.skip_info:
         self.check_results = {dn: (dn in self.existing_domains) for dn in self.target_domain_names}
         self.event('skip-info')
         return
     try:
         response = rpc_client.cmd_domain_info(
             domain=self.current_domain_name,
             auth_info=self.auth_info or None,
         )
     except rpc_error.EPPError as exc:
         self.log(self.debug_level, 'Exception in doEppDomainInfo: %s' % exc)
         self.event('error', exc)
     else:
         if self.verify_registrant:
             known_domain = zdomains.domain_find(domain_name=self.current_domain_name)
             known_registrant_epp_id = None if not known_domain else known_domain.registrant.epp_id
             real_registrant_epp_id = response['epp']['response']['resData']['infData'].get('registrant', None)
             if real_registrant_epp_id and known_registrant_epp_id and known_registrant_epp_id != real_registrant_epp_id:
                 logger.warn('domain %s suppose to belong to another registrant: %r, but received another id: %r', 
                              self.current_domain_name, known_registrant_epp_id, real_registrant_epp_id)
                 self.event('error', zerrors.RegistrantAuthFailed(response=response))
                 return
         self.check_results[self.current_domain_name] = True
         self.event('response', response)
示例#2
0
 def doEppDomainInfo(self, *args, **kwargs):
     """
     Action method.
     """
     try:
         response = rpc_client.cmd_domain_info(
             domain=self.target_domain.name, )
     except rpc_error.EPPError as exc:
         self.log(self.debug_level,
                  'Exception in doEppDomainInfo: %s' % exc)
         self.event('error', exc)
     else:
         self.event('response', response)
示例#3
0
 def doEppDomainInfo(self, *args, **kwargs):
     """
     Action method.
     """
     try:
         response = rpc_client.cmd_domain_info(
             domain=self.target_domain.name,
             auth_info=self.target_domain.auth_key or None,
             raise_for_result=False,
         )
     except rpc_error.EPPError as exc:
         self.log(self.debug_level,
                  'Exception in doEppDomainInfo: %s' % exc)
         self.event('error', exc)
     else:
         self.latest_domain_info = response
         self.event('response', response)
def test_update_hostnames():
    if os.environ.get('E2E', '0') != '1':
        return pytest.skip('skip E2E')  # @UndefinedVariable
    tester = testsupport.prepare_tester_account()
    tester_domain = testsupport.prepare_tester_domain(
        domain_name='test.%s' % settings.ZENAIDA_SUPPORTED_ZONES[0],
        tester=tester,
        domain_epp_id=rpc_client.make_epp_id(tester.email),
        add_contacts=[
            'registrant',
            'admin',
        ],
        nameservers=[
            'ns1.google.com',
            'ns2.google.com',
            'ns3.google.com',
        ])
    scenario1 = []
    cs1 = domain_hostnames_synchronizer.DomainHostnamesSynchronizer(
        update_domain=True,
        log_events=True,
        log_transitions=True,
        raise_errors=True,
    )
    cs1.add_state_changed_callback(
        cb=lambda oldstate, newstate, event, *args, **kwargs: scenario1.append(
            (
                oldstate,
                newstate,
                event,
            )),
    )
    cs1.event(
        'run',
        target_domain=tester_domain,
        known_domain_info=rpc_client.cmd_domain_info(
            domain=tester_domain.name),
    )
    outputs1 = list(cs1.outputs)
    del cs1

    tester_domain.nameserver4 = 'ns4.google.com'
    tester_domain.save()
    scenario2 = []
    cs2 = domain_hostnames_synchronizer.DomainHostnamesSynchronizer(
        update_domain=True,
        log_events=True,
        log_transitions=True,
        raise_errors=True,
    )
    cs2.add_state_changed_callback(
        cb=lambda oldstate, newstate, event, *args, **kwargs: scenario2.append(
            (
                oldstate,
                newstate,
                event,
            )),
    )
    cs2.event(
        'run',
        target_domain=tester_domain,
        known_domain_info=rpc_client.cmd_domain_info(
            domain=tester_domain.name),
    )
    outputs2 = list(cs2.outputs)
    del cs2

    # one nameserver should be removed
    assert scenario1 == [
        ('AT_STARTUP', 'DOMAIN_INFO?', 'run'),
        ('DOMAIN_INFO?', 'HOSTS_CHECK', 'response'),
        ('HOSTS_CHECK', 'DOMAIN_UPDATE!', 'no-hosts-to-be-added'),
        ('DOMAIN_UPDATE!', 'DONE', 'response'),
    ]
    assert len(outputs1) == 1
    assert outputs1[0]['epp']['response']['result']['@code'] == '1000'
    # one nameserver should be added back
    assert scenario2 == [
        ('AT_STARTUP', 'DOMAIN_INFO?', 'run'),
        ('DOMAIN_INFO?', 'HOSTS_CHECK', 'response'),
        ('HOSTS_CHECK', 'HOSTS_CREATE', 'response'),
        ('HOSTS_CREATE', 'DOMAIN_UPDATE!', 'all-hosts-created'),
        ('DOMAIN_UPDATE!', 'DONE', 'response'),
    ]
    assert len(outputs2) == 1
    assert outputs2[0]['epp']['response']['result']['@code'] == '1000'
示例#5
0
    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)