예제 #1
0
def test_single_domain_another_registrar():
    if os.environ.get('E2E', '0') != '1':
        return pytest.skip('skip E2E')  # @UndefinedVariable
    scenario = []
    dc = domains_checker.DomainsChecker(
        log_events=True,
        log_transitions=True,
    )
    dc.add_state_changed_callback(
        cb=lambda oldstate, newstate, event, *args, **kwargs: scenario.append((
            oldstate,
            newstate,
            event,
        )),
    )
    test_domain_name = 'owned-by-another-registar.%s' % settings.ZENAIDA_SUPPORTED_ZONES[
        0]
    dc.event('run', [
        test_domain_name,
    ])
    outputs = list(dc.outputs)
    del dc
    assert scenario == [
        ('AT_STARTUP', 'CHECK_MANY', 'run'),
        ('CHECK_MANY', 'INFO_ONE', 'response'),
        ('INFO_ONE', 'FAILED', 'error'),
    ]
    assert len(outputs) == 3
    assert outputs[0] == [
        test_domain_name,
    ]
    assert outputs[1]['epp']['response']['result']['@code'] == '1000'
    assert isinstance(outputs[2], rpc_error.EPPResponseEmpty)
예제 #2
0
def test_single_domain_not_exist():
    if os.environ.get('E2E', '0') != '1':
        return pytest.skip('skip E2E')  # @UndefinedVariable
    scenario = []
    dc = domains_checker.DomainsChecker(
        log_events=True,
        log_transitions=True,
    )
    dc.add_state_changed_callback(
        cb=lambda oldstate, newstate, event, *args, **kwargs: scenario.append((
            oldstate,
            newstate,
            event,
        )),
    )
    test_domain_name = 'this-domain-not-exist.%s' % settings.ZENAIDA_SUPPORTED_ZONES[
        0]
    dc.event('run', [
        test_domain_name,
    ])
    outputs = list(dc.outputs)
    del dc
    assert scenario == [
        ('AT_STARTUP', 'CHECK_MANY', 'run'),
        ('CHECK_MANY', 'DONE', 'response'),
    ]
    assert len(outputs) == 3
    assert outputs[0] == []
    assert outputs[1]['epp']['response']['result']['@code'] == '1000'
    assert outputs[2] == {
        test_domain_name: False,
    }
예제 #3
0
def domains_check(domain_names,
                  verify_registrant=False,
                  raise_errors=False,
                  log_events=True,
                  log_transitions=True):
    """
    Checks if those domains existing on Back-End.
    Returns dictionary object with check results.
    If `verify_registrant` is True process will also send domain_info() request to check epp_id on Back-End
    and compare with current registrant information stored in DB for every domain : epp_id must be in sync.
    Returns None if error happened, or raise Exception if `raise_errors` is True.
    """
    dc = domains_checker.DomainsChecker(
        skip_info=(not verify_registrant),
        verify_registrant=verify_registrant,
        stop_on_error=True,
        log_events=log_events,
        log_transitions=log_transitions,
        raise_errors=raise_errors,
    )
    dc.event('run', domain_names)
    outputs = list(dc.outputs)
    del dc
    logger.debug('domains_checker(%r) finished with %d outputs', domain_names,
                 len(outputs))

    if not outputs or not outputs[-1] or isinstance(outputs[-1], Exception):
        if outputs and isinstance(outputs[-1], Exception):
            logger.error(outputs[-1])
        return None

    logger.info('domains_checker(%r) OK', domain_names)
    return outputs[-1]
예제 #4
0
def test_single_domain_another_registrant():
    if os.environ.get('E2E', '0') != '1':
        return pytest.skip('skip E2E')  # @UndefinedVariable
    tester_domain = testsupport.prepare_tester_domain(
        domain_name='test-readonly.%s' % settings.ZENAIDA_SUPPORTED_ZONES[0],
        add_contacts=[
            'registrant',
            'admin',
        ],
        epp_id_dict={
            'registrant': 'ThisIDNotExist1',
            'admin': 'ThisIDNotExist2',
        },
        nameservers=[
            'notexist1.com',
            'notexist2.com',
        ],
    )
    scenario = []
    dc = domains_checker.DomainsChecker(
        log_events=True,
        log_transitions=True,
    )
    dc.add_state_changed_callback(
        cb=lambda oldstate, newstate, event, *args, **kwargs: scenario.append((
            oldstate,
            newstate,
            event,
        )),
    )
    dc.event('run', [
        tester_domain.name,
    ])
    outputs = list(dc.outputs)
    del dc
    assert scenario == [
        ('AT_STARTUP', 'CHECK_MANY', 'run'),
        ('CHECK_MANY', 'INFO_ONE', 'response'),
        ('INFO_ONE', 'FAILED', 'error'),
    ]
    assert len(outputs) == 3
    assert outputs[0] == [
        tester_domain.name,
    ]
    assert outputs[1]['epp']['response']['result']['@code'] == '1000'
    assert isinstance(outputs[2], zerrors.RegistrantAuthFailed)
예제 #5
0
 def doRunDomainsChecker(self, *args, **kwargs):
     """
     Action method.
     """
     dc = domains_checker.DomainsChecker(
         skip_info=False,
         verify_registrant=False,
         stop_on_error=True,
         log_events=self.log_events,
         log_transitions=self.log_transitions,
         raise_errors=self.raise_errors,
     )
     try:
         dc.event('run', [
             self.target_domain.name,
         ])
     except Exception as exc:
         self.log(self.debug_level, 'Exception in DomainsChecker: %s' % exc)
         del dc
         self.event('verify-failed', exc)
         return
     self.outputs.extend(list(dc.outputs))
     del dc
     domain_check_result = self.outputs[-1].get(self.target_domain.name)
     if isinstance(domain_check_result, Exception):
         self.event('verify-failed', domain_check_result)
         return
     if not domain_check_result:
         self.event(
             'verify-failed',
             Exception('domain %r not exist' % self.target_domain.name))
         return
     if self.target_domain:
         zdomains.domain_update_statuses(
             domain_object=self.target_domain,
             domain_info_response=self.outputs[-2],
         )
     self.event('verify-ok')
예제 #6
0
 def doRunDomainsChecker(self, *args, **kwargs):
     """
     Action method.
     """
     dc = domains_checker.DomainsChecker(
         skip_info=False,
         verify_registrant=False,
         stop_on_error=True,
         log_events=self.log_events,
         log_transitions=self.log_transitions,
         raise_errors=self.raise_errors,
     )
     try:
         dc.event('run', [
             self.target_domain.name,
         ])
     except Exception as exc:
         self.log(self.debug_level, 'Exception in DomainsChecker: %s' % exc)
         self.event('verify-failed', exc)
     else:
         self.outputs.extend(list(dc.outputs))
         del dc
         self.event('verify-ok')
예제 #7
0
def test_no_domains():
    if os.environ.get('E2E', '0') != '1':
        return pytest.skip('skip E2E')  # @UndefinedVariable
    scenario = []
    dc = domains_checker.DomainsChecker(
        log_events=True,
        log_transitions=True,
    )
    dc.add_state_changed_callback(
        cb=lambda oldstate, newstate, event, *args, **kwargs: scenario.append((
            oldstate,
            newstate,
            event,
        )),
    )
    dc.event('run', [])
    outputs = list(dc.outputs)
    del dc
    assert scenario == [
        ('AT_STARTUP', 'CHECK_MANY', 'run'),
        ('CHECK_MANY', 'FAILED', 'error'),
    ]
    assert len(outputs) == 1
    assert isinstance(outputs[0], zerrors.CommandInvalid)
예제 #8
0
파일: zmaster.py 프로젝트: vesellov/zenaida
def domain_read_info(domain,
                     auth_info=None,
                     raise_errors=False,
                     log_events=True,
                     log_transitions=True):
    """
    Request from back-end and returns actual info about the domain.
    """
    dc = domains_checker.DomainsChecker(
        skip_check=True,
        skip_info=False,
        verify_registrant=False,
        stop_on_error=True,
        log_events=log_events,
        log_transitions=log_transitions,
        raise_errors=raise_errors,
    )
    dc.event(
        'run',
        [
            domain,
        ],
        auth_info=auth_info,
    )
    outputs = list(dc.outputs)
    del dc
    logger.info('domains_checker(%r) finished with %d outputs', domain,
                len(outputs))

    if not outputs or not outputs[-1] or isinstance(outputs[-1], Exception):
        if outputs and isinstance(outputs[-1], Exception):
            logger.error('domains_checker(%r) failed with: %r', domain,
                         outputs[-1])
        else:
            logger.error('domains_checker(%r) unexpectedly failed with: %r',
                         domain, outputs)
        if raise_errors:
            if not outputs or not outputs[-1]:
                raise Exception('empty response')
            elif outputs and isinstance(outputs[-1], Exception):
                raise outputs[-1]
            else:
                raise Exception(outputs)
        return None

    if not outputs[-1].get(domain):
        logger.error('domains_checker(%r) failed because domain not exist',
                     domain)
        if raise_errors:
            raise zerrors.DomainNotExist()
        return None

    if len(outputs) < 2:
        logger.error('domains_checker(%r) failed with: %r', domain,
                     outputs[-1])
        if raise_errors:
            raise zerrors.UnexpectedEPPResponse(outputs)
        return None

    logger.info('domains_checker(%r) OK', domain)
    return outputs[-2]