add a test for dnserr api response

and also fix dnserr api response - should not contain additional info, but just "dnserr"
This commit is contained in:
Thomas Waldmann 2013-12-18 04:08:18 +01:00
parent b718b93453
commit b317837f58
2 changed files with 12 additions and 1 deletions

View File

@ -5,6 +5,7 @@ Tests for api package.
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from nsupdate.main.dnstools import query_ns from nsupdate.main.dnstools import query_ns
from nsupdate.main.models import Domain
TEST_HOST = "test.nsupdate.info" TEST_HOST = "test.nsupdate.info"
@ -80,6 +81,16 @@ def test_nic_update_authorized(client):
assert response.content.startswith('good ') or response.content.startswith('nochg ') assert response.content.startswith('good ') or response.content.startswith('nochg ')
def test_nic_update_authorized_ns_unavailable(client):
d = Domain.objects.get(domain=TEST_HOST)
d.available = False # simulate DNS unavailability
d.save()
response = client.get(reverse('nic_update'),
HTTP_AUTHORIZATION=make_basic_auth_header(TEST_HOST, TEST_SECRET))
assert response.status_code == 200
assert response.content == 'dnserr'
def test_nic_update_authorized_myip(client): def test_nic_update_authorized_myip(client):
response = client.get(reverse('nic_update') + '?myip=4.3.2.1', response = client.get(reverse('nic_update') + '?myip=4.3.2.1',
HTTP_AUTHORIZATION=make_basic_auth_header(TEST_HOST, TEST_SECRET)) HTTP_AUTHORIZATION=make_basic_auth_header(TEST_HOST, TEST_SECRET))

View File

@ -311,4 +311,4 @@ def _update(host, hostname, ipaddr, ssl=False, logger=None):
logger.error('%s - received update that resulted in a dns error [%s], ip: %s ssl: %r' % ( logger.error('%s - received update that resulted in a dns error [%s], ip: %s ssl: %r' % (
hostname, msg, ipaddr, ssl)) hostname, msg, ipaddr, ssl))
host.register_server_fault() host.register_server_fault()
return Response('dnserr %s' % msg) return Response('dnserr')