move test settings to test_settings.py, add FIXME for resolver search list
make SECRET_KEY obviously non-secret and non-random + document it should be secret/random
This commit is contained in:
parent
14209ae25f
commit
724f35225e
37
conftest.py
37
conftest.py
@ -1,5 +1,30 @@
|
|||||||
|
"""
|
||||||
|
configuration for the tests
|
||||||
|
"""
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
# put test_settings.py into the toplevel dir and invoke py.test from there
|
||||||
|
# needs to look like (just with YOUR domain, IP, algo, key, hostnames, IPs):
|
||||||
|
"""
|
||||||
|
# this is to create a Domain entry in the database, so it can be used for unit tests:
|
||||||
|
BASEDOMAIN = "nsupdate.info"
|
||||||
|
NAMESERVER_IP = "85.10.192.104"
|
||||||
|
NAMESERVER_UPDATE_ALGORITHM = "HMAC_SHA512"
|
||||||
|
NAMESERVER_UPDATE_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=="
|
||||||
|
NAMESERVER_PUBLIC = True
|
||||||
|
|
||||||
|
# for some unittests
|
||||||
|
WWW_HOST = BASEDOMAIN
|
||||||
|
NONEXISTING_HOST = 'nonexisting.' + BASEDOMAIN
|
||||||
|
WWW_IPV4_HOST = 'ipv4.' + BASEDOMAIN
|
||||||
|
WWW_IPV6_HOST = 'ipv6.' + BASEDOMAIN
|
||||||
|
WWW_IPV4_IP = '85.10.192.104'
|
||||||
|
WWW_IPV6_IP = '2a01:4f8:a0:2ffe:0:ff:fe00:8000'
|
||||||
|
"""
|
||||||
|
|
||||||
|
import test_settings
|
||||||
|
|
||||||
from django.utils.translation import activate
|
from django.utils.translation import activate
|
||||||
|
|
||||||
|
|
||||||
@ -10,11 +35,13 @@ def db_init(db):
|
|||||||
Init the database contents for testing, so we have a service domain, ...
|
Init the database contents for testing, so we have a service domain, ...
|
||||||
"""
|
"""
|
||||||
from nsupdate.main.models import Domain
|
from nsupdate.main.models import Domain
|
||||||
Domain.objects.create(domain='nsupdate.info',
|
Domain.objects.create(
|
||||||
nameserver_ip='85.10.192.104',
|
domain=test_settings.BASEDOMAIN,
|
||||||
nameserver_update_algorithm='HMAC_SHA512',
|
nameserver_ip=test_settings.NAMESERVER_IP,
|
||||||
nameserver_update_key='YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==',
|
nameserver_update_algorithm=test_settings.NAMESERVER_UPDATE_ALGORITHM,
|
||||||
public=True)
|
nameserver_update_key=test_settings.NAMESERVER_UPDATE_KEY,
|
||||||
|
public=test_settings.NAMESERVER_PUBLIC,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def pytest_runtest_setup(item):
|
def pytest_runtest_setup(item):
|
||||||
|
@ -3,20 +3,18 @@ Tests for dnstools module.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from test_settings import *
|
||||||
|
|
||||||
pytestmark = pytest.mark.django_db
|
pytestmark = pytest.mark.django_db
|
||||||
|
|
||||||
from dns.resolver import NXDOMAIN
|
from dns.resolver import NXDOMAIN
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
from ..dnstools import add, delete, update, query_ns, parse_name, update_ns, SameIpError
|
from ..dnstools import add, delete, update, query_ns, parse_name, update_ns, SameIpError
|
||||||
|
|
||||||
BASEDOMAIN = settings.BASEDOMAIN
|
|
||||||
|
|
||||||
|
|
||||||
class TestIntelligentUpdater(object):
|
class TestIntelligentUpdater(object):
|
||||||
def test_double_update(self):
|
def test_double_update(self):
|
||||||
host, ip = 'test0.' + settings.BASEDOMAIN, '1.2.3.4'
|
host, ip = 'test0.' + BASEDOMAIN, '1.2.3.4'
|
||||||
# make sure the host is not there
|
# make sure the host is not there
|
||||||
try:
|
try:
|
||||||
update_ns(host, 'A', action='del')
|
update_ns(host, 'A', action='del')
|
||||||
@ -33,7 +31,7 @@ class TestIntelligentUpdater(object):
|
|||||||
|
|
||||||
class TestIntelligentAdder(object):
|
class TestIntelligentAdder(object):
|
||||||
def test_double_add_same(self):
|
def test_double_add_same(self):
|
||||||
host, ip = 'test0.' + settings.BASEDOMAIN, '1.2.3.4'
|
host, ip = 'test0.' + BASEDOMAIN, '1.2.3.4'
|
||||||
# make sure the host is not there
|
# make sure the host is not there
|
||||||
try:
|
try:
|
||||||
update_ns(host, 'A', action='del')
|
update_ns(host, 'A', action='del')
|
||||||
@ -48,7 +46,7 @@ class TestIntelligentAdder(object):
|
|||||||
add(host, ip)
|
add(host, ip)
|
||||||
|
|
||||||
def test_double_add_different(self):
|
def test_double_add_different(self):
|
||||||
host, ip = 'test0.' + settings.BASEDOMAIN, '1.2.3.4'
|
host, ip = 'test0.' + BASEDOMAIN, '1.2.3.4'
|
||||||
# make sure the host is not there
|
# make sure the host is not there
|
||||||
try:
|
try:
|
||||||
update_ns(host, 'A', action='del')
|
update_ns(host, 'A', action='del')
|
||||||
@ -66,7 +64,7 @@ class TestIntelligentAdder(object):
|
|||||||
|
|
||||||
class TestIntelligentDeleter(object):
|
class TestIntelligentDeleter(object):
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
host, ip = 'test0.' + settings.BASEDOMAIN, '1.2.3.4'
|
host, ip = 'test0.' + BASEDOMAIN, '1.2.3.4'
|
||||||
# make sure the host is there
|
# make sure the host is there
|
||||||
update_ns(host, 'A', ip, action='add')
|
update_ns(host, 'A', ip, action='add')
|
||||||
delete(host)
|
delete(host)
|
||||||
@ -75,7 +73,7 @@ class TestIntelligentDeleter(object):
|
|||||||
query_ns(host, 'A')
|
query_ns(host, 'A')
|
||||||
|
|
||||||
def test_double_delete(self):
|
def test_double_delete(self):
|
||||||
host = 'test0.' + settings.BASEDOMAIN
|
host = 'test0.' + BASEDOMAIN
|
||||||
# make sure the host is not there
|
# make sure the host is not there
|
||||||
try:
|
try:
|
||||||
update_ns(host, 'A', action='del')
|
update_ns(host, 'A', action='del')
|
||||||
@ -87,16 +85,16 @@ class TestIntelligentDeleter(object):
|
|||||||
|
|
||||||
class TestQuery(object):
|
class TestQuery(object):
|
||||||
def test_queries_ok(self):
|
def test_queries_ok(self):
|
||||||
assert query_ns(settings.WWW_IPV4_HOST, 'A') == settings.WWW_IPV4_IP # v4 ONLY
|
assert query_ns(WWW_IPV4_HOST, 'A') == WWW_IPV4_IP # v4 ONLY
|
||||||
assert query_ns(settings.WWW_IPV6_HOST, 'AAAA') == settings.WWW_IPV6_IP # v6 ONLY
|
assert query_ns(WWW_IPV6_HOST, 'AAAA') == WWW_IPV6_IP # v6 ONLY
|
||||||
assert query_ns(settings.WWW_HOST, 'A') == settings.WWW_IPV4_IP # v4 and v6, query v4
|
assert query_ns(WWW_HOST, 'A') == WWW_IPV4_IP # v4 and v6, query v4
|
||||||
assert query_ns(settings.WWW_HOST, 'AAAA') == settings.WWW_IPV6_IP # v4 and v6, query v6
|
assert query_ns(WWW_HOST, 'AAAA') == WWW_IPV6_IP # v4 and v6, query v6
|
||||||
|
|
||||||
def test_queries_failing(self):
|
def test_queries_failing(self):
|
||||||
with pytest.raises(NXDOMAIN):
|
with pytest.raises(NXDOMAIN):
|
||||||
query_ns(settings.NONEXISTING_HOST, 'A')
|
query_ns(NONEXISTING_HOST, 'A')
|
||||||
with pytest.raises(NXDOMAIN):
|
with pytest.raises(NXDOMAIN):
|
||||||
query_ns(settings.NONEXISTING_HOST, 'AAAA')
|
query_ns(NONEXISTING_HOST, 'AAAA')
|
||||||
|
|
||||||
|
|
||||||
class TestUpdate(object):
|
class TestUpdate(object):
|
||||||
|
@ -157,7 +157,7 @@ def query_ns(qname, rdtype, origin=None):
|
|||||||
# we do not configure it from resolv.conf, but patch in the values we
|
# we do not configure it from resolv.conf, but patch in the values we
|
||||||
# want into the documented attributes:
|
# want into the documented attributes:
|
||||||
resolver.nameservers = [nameserver, ]
|
resolver.nameservers = [nameserver, ]
|
||||||
resolver.search = [dns.name.from_text(settings.BASEDOMAIN), ]
|
resolver.search = [dns.name.from_text('nsupdate.info'), ] # FIXME: should work with empty list
|
||||||
resolver.lifetime = RESOLVER_TIMEOUT
|
resolver.lifetime = RESOLVER_TIMEOUT
|
||||||
try:
|
try:
|
||||||
answer = resolver.query(qname, rdtype)
|
answer = resolver.query(qname, rdtype)
|
||||||
|
@ -6,6 +6,9 @@ import os
|
|||||||
import dns.tsig
|
import dns.tsig
|
||||||
import django.conf.global_settings as DEFAULT_SETTINGS
|
import django.conf.global_settings as DEFAULT_SETTINGS
|
||||||
|
|
||||||
|
# Use a unique, long, random, secret string here.
|
||||||
|
SECRET_KEY = 'this is for sure not secret, but good enough for running the unit tests'
|
||||||
|
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
TEMPLATE_DEBUG = DEBUG
|
TEMPLATE_DEBUG = DEBUG
|
||||||
|
|
||||||
@ -28,13 +31,9 @@ DATABASES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BASEDOMAIN = 'nsupdate.info'
|
BASEDOMAIN = 'nsupdate.info'
|
||||||
|
|
||||||
NONEXISTING_HOST = 'nonexisting.' + BASEDOMAIN
|
|
||||||
WWW_HOST = BASEDOMAIN
|
WWW_HOST = BASEDOMAIN
|
||||||
WWW_IPV4_HOST = 'ipv4.' + BASEDOMAIN
|
WWW_IPV4_HOST = 'ipv4.' + BASEDOMAIN
|
||||||
WWW_IPV6_HOST = 'ipv6.' + BASEDOMAIN
|
WWW_IPV6_HOST = 'ipv6.' + BASEDOMAIN
|
||||||
WWW_IPV4_IP = '178.32.221.14'
|
|
||||||
WWW_IPV6_IP = '2001:41d0:8:e00e::1'
|
|
||||||
|
|
||||||
BAD_AGENTS = set() # useragent blacklist for /nic/update service
|
BAD_AGENTS = set() # useragent blacklist for /nic/update service
|
||||||
|
|
||||||
@ -101,9 +100,6 @@ STATICFILES_FINDERS = (
|
|||||||
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
|
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Make this unique, and don't share it with anybody.
|
|
||||||
SECRET_KEY = 'iwlqlh4mrwe6j+f(e8qb)^muiq2^=!v+h#_s9**6wghpd_&bg8'
|
|
||||||
|
|
||||||
# List of callables that know how to import templates from various sources.
|
# List of callables that know how to import templates from various sources.
|
||||||
TEMPLATE_LOADERS = (
|
TEMPLATE_LOADERS = (
|
||||||
'django.template.loaders.filesystem.Loader',
|
'django.template.loaders.filesystem.Loader',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user