def test_search_dns():
    user = User(default_username, default_password, 2)
    mockserver.users = [user]
    mockserver.dns_records = [
        {
            'host': 'a.com',
            'type': 'a',
            'value': '1.1.1.1'
        },
    ] * 100
    client = DnsDBClient()
    client.login(default_username, default_password)
    results = client.search_dns(domain='a.com',
                                ip='1.1.0.0',
                                dns_type='a',
                                host='c.a.com')
    assert_equal(len(results), 30)
    assert_equal(user.remaining_request, 1)
    results = client.search_dns(domain='a.com', start=99)
    assert_equal(len(results), 1)
    assert_equal(user.remaining_request, 0)
    for record in results:
        assert_equal(record['host'], record.host)
        assert_equal(record['type'], record.type)
        assert_equal(record['value'], record.value)
        data = json.loads(str(record))
        assert_equal(data['host'], record.host)
        assert_equal(data['type'], record.type)
        assert_equal(data['value'], record.value)
Пример #2
0
def search_cmd(args):
    APIClient.API_BASE_URL = args.api_url
    username = args.username
    password = args.password
    domain = args.domain
    host = args.host
    dns_type = args.type
    ip = args.ip
    start = args.start
    get_all = args.all
    check_search_params(domain, host, ip)
    if not username:
        username = read_line("Username:"******"Password:")
    proxies = None
    if args.proxy:
        proxies = {'http': args.proxy, 'https': args.proxy}
    client = DnsDBClient(proxies=proxies)
    login(client, username, password)
    output = get_output_file(args.output)
    start_time = datetime.datetime.now()
    try:
        if get_all:
            result = client.retrieve_dns(domain=domain,
                                         host=host,
                                         dns_type=dns_type,
                                         ip=ip)
        else:
            result = client.search_dns(domain=domain,
                                       host=host,
                                       dns_type=dns_type,
                                       ip=ip,
                                       start=start)
        process_output(result, output,
                       OutputFormatter(args.json, args.csv, args.format),
                       args.max)
    except Exception as e:
        if isinstance(e, AuthenticationError):
            os.remove(CACHE_PATH)
        if args.debug:
            traceback.print_exc()
        show_error(str(e) + '\n')
    finally:
        output.flush()
        if args.verbose:
            print('Running time: %s' % (datetime.datetime.now() - start_time))
        output.close()
def test_search_dns_without_remaining_request():
    mockserver.users = [User(default_username, default_password, 0)]
    client = DnsDBClient()
    client.login(default_username, default_password)
    client.search_dns(domain='a.com')
def test_search_dns_without_params():
    client = DnsDBClient()
    client.login(default_username, default_password)
    client.search_dns()
def test_search_dns_without_login():
    client = DnsDBClient()
    client.search_dns(domain='a.com')
def test_search_dns_return_504():
    client = DnsDBClient()
    client.login(default_username, default_password)
    mockserver.return_error_response = GatewayTimeoutError
    client.search_dns(domain='a.com')
def test_search_dns_return_500():
    client = DnsDBClient()
    client.login(default_username, default_password)
    mockserver.return_error_response = InternalServerError
    client.search_dns(domain='a.com')