示例#1
0
def ddns_hostname():
    """
    get a random hostname for tests and make sure it is removed from dns
    after the test
    """
    hostname = "test%d" % randint(1000000000, 2000000000)
    yield hostname
    fqdn = FQDN(hostname, TESTDOMAIN)
    update_ns(fqdn, 'A', action='del')
    update_ns(fqdn, 'AAAA', action='del')
示例#2
0
def check_dns(domain):
    """
    checks if the nameserver is reachable and answers queries for the domain.

    note: we can't reasonably check for dynamic updates as the dns admin might
    have put restrictions on which hosts are allowed to be updated.

    :param domain: domain name
    :return: available status
    """
    fqdn = FQDN(host=None, domain=domain)
    try:
        query_ns(fqdn, 'SOA', prefer_primary=True)
        queries_ok = True
    except (dns.resolver.Timeout, dns.resolver.NoNameservers,
            dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, NameServerNotAvailable, dns.message.UnknownTSIGKey):
        # note: currently the domain is also set to unavailable as a
        # side effect in query_ns()
        queries_ok = False
    return queries_ok
示例#3
0
import base64
from netaddr import IPSet, IPAddress, IPNetwork

from django.core.urlresolvers import reverse

from nsupdate.main.dnstools import query_ns, FQDN
from nsupdate.main.models import Domain
from nsupdate.api.views import basic_authenticate

from conftest import TESTDOMAIN, TEST_HOST, TEST_HOST_RELATED, TEST_HOST2, TEST_SECRET, TEST_SECRET2

USERNAME = '******'
PASSWORD = '******'

BASEDOMAIN = "nsupdate.info"
TEST_HOST_OTHER = FQDN('nsupdate-ddns-client-unittest', BASEDOMAIN)


def test_myip(client):
    response = client.get(reverse('myip'))
    assert response.status_code == 200
    assert response.content in [b'127.0.0.1', b'::1']


def test_nic_update_noauth(client):
    response = client.get(reverse('nic_update'))
    assert response.status_code == 401
    assert response.content == b'badauth'


def make_basic_auth_header(username, password):
示例#4
0
def ddns_fqdn(ddns_hostname):
    yield FQDN(ddns_hostname, TESTDOMAIN)
示例#5
0
"""
configuration for the (py.test based) tests
"""

import pytest

from random import randint

from nsupdate.main.dnstools import FQDN

from django.conf import settings

# this is to create a Domain entries in the database, so they can be used for unit tests:
BASEDOMAIN = "nsupdate.info"
TESTDOMAIN = "tests." + BASEDOMAIN
TEST_HOST = FQDN('test%da' % randint(1, 1000000), TESTDOMAIN)  # unit tests can update this host ONLY
TEST_SECRET = "secret"
TEST_HOST2 = FQDN('test%db' % randint(1, 1000000), TESTDOMAIN)
TEST_SECRET2 = "somethingelse"
RELATED_HOST_NAME = 'rh'
TEST_HOST_RELATED = FQDN(RELATED_HOST_NAME + '.' + TEST_HOST.host, TEST_HOST.domain)
NAMESERVER_IP = "85.10.192.104"
NAMESERVER2_IP = NAMESERVER_IP  # use same server as tests query shortly after update, too quick for secondary
NAMESERVER_UPDATE_ALGORITHM = "HMAC_SHA512"
# no problem, you can ONLY update the TESTDOMAIN with this secret, nothing else:
NAMESERVER_UPDATE_SECRET = "YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ=="
NAMESERVER_PUBLIC = True

USERNAME = '******'
USERNAME2 = 'test2'
PASSWORD = '******'