2012-12-16 02:59:51 +00:00
|
|
|
from django.core.urlresolvers import reverse
|
2012-12-05 03:45:01 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
from django.test.client import Client
|
|
|
|
|
2015-06-13 10:05:42 +00:00
|
|
|
from binder import models
|
|
|
|
|
2012-12-05 03:45:01 +00:00
|
|
|
|
|
|
|
class Integration_Tests(TestCase):
|
2015-06-13 10:05:42 +00:00
|
|
|
fixtures = ["binder/fixtures/binder_test.json"]
|
2012-12-05 03:45:01 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.client = Client()
|
|
|
|
self.testserver = models.BindServer.objects.get(hostname="testserver1").hostname
|
|
|
|
|
|
|
|
def test_Integration_Add_Record(self):
|
|
|
|
"""Add forward and reverse record on domain1.local."""
|
2015-06-13 10:05:42 +00:00
|
|
|
add_dict = {"dns_server": self.testserver,
|
|
|
|
"record_name": "record1",
|
|
|
|
"record_type": "A",
|
|
|
|
"zone_name": "domain1.local",
|
|
|
|
"record_data": "10.254.1.101",
|
|
|
|
"ttl": 86400,
|
|
|
|
"create_reverse": True}
|
2012-12-16 02:59:51 +00:00
|
|
|
response = self.client.post(reverse("add_record_result"), add_dict)
|
2012-12-05 03:45:01 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
# Make sure that we get two responses (fwd/rev) back from the server.
|
|
|
|
self.assertEqual(len(response.context["response"]), 2)
|
|
|
|
|
|
|
|
for current_response in response.context["response"]:
|
|
|
|
dns_update_output = str(current_response["output"])
|
|
|
|
self.assertRegexpMatches(dns_update_output, "opcode UPDATE")
|
|
|
|
self.assertRegexpMatches(dns_update_output, "rcode NOERROR")
|
|
|
|
|
|
|
|
def test_Integration_Delete_Record(self):
|
|
|
|
"""Delete record1.domain1.local"""
|
2015-06-13 10:05:42 +00:00
|
|
|
delete_dict = {"dns_server": self.testserver,
|
|
|
|
"zone_name": "domain1.local",
|
|
|
|
"rr_list": '[u"record1.domain1.local", u"record2.domain1.local"]'}
|
2012-12-16 02:59:51 +00:00
|
|
|
response = self.client.post(reverse("delete_record_result"), delete_dict)
|
2012-12-05 03:45:01 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(len(response.context["response"]), 2)
|
|
|
|
for current_response in response.context["response"]:
|
|
|
|
dns_update_output = str(current_response["output"])
|
|
|
|
self.assertRegexpMatches(dns_update_output, "opcode UPDATE")
|
|
|
|
self.assertRegexpMatches(dns_update_output, "rcode NOERROR")
|
|
|
|
|
|
|
|
def test_Integration_Add_Cname(self):
|
2015-06-13 10:05:42 +00:00
|
|
|
"""Add CNAME cnametest1 after adding associated A record record1."""
|
|
|
|
add_dict = {"dns_server": self.testserver,
|
|
|
|
"record_name": "record1",
|
|
|
|
"record_type": "A",
|
|
|
|
"zone_name": "domain1.local",
|
|
|
|
"record_data": "10.254.1.101",
|
|
|
|
"ttl": 86400,
|
|
|
|
"create_reverse": False}
|
2012-12-16 02:59:51 +00:00
|
|
|
response = self.client.post(reverse("add_record_result"), add_dict)
|
2012-12-05 03:45:01 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
# Make sure that we get two responses (fwd/rev) back from the server.
|
|
|
|
self.assertEqual(len(response.context["response"]), 1)
|
|
|
|
|
|
|
|
for current_response in response.context["response"]:
|
|
|
|
dns_update_output = str(current_response["output"])
|
|
|
|
self.assertRegexpMatches(dns_update_output, "opcode UPDATE")
|
|
|
|
self.assertRegexpMatches(dns_update_output, "rcode NOERROR")
|
|
|
|
|
2015-06-13 10:05:42 +00:00
|
|
|
cname_dict = {"dns_server": self.testserver,
|
|
|
|
"originating_record": "record1.domain1.local",
|
|
|
|
"cname": "cnametest1",
|
|
|
|
"zone_name": "domain1.local",
|
|
|
|
"ttl": 86400}
|
2012-12-16 02:59:51 +00:00
|
|
|
response = self.client.post(reverse("add_cname_result"), cname_dict)
|
2012-12-05 03:45:01 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
for current_response in response.context["response"]:
|
|
|
|
dns_update_output = str(current_response["output"])
|
|
|
|
self.assertRegexpMatches(dns_update_output, "opcode UPDATE")
|
|
|
|
self.assertRegexpMatches(dns_update_output, "rcode NOERROR")
|
2012-12-07 02:46:10 +00:00
|
|
|
|
2012-12-07 12:46:18 +00:00
|
|
|
def test_Integration_ServerZoneList_ConnectionRefused(self):
|
2012-12-07 02:46:10 +00:00
|
|
|
"""Confirm connection refused on a server zone list."""
|
|
|
|
dns_server = models.BindServer.objects.get(hostname="testserver1")
|
|
|
|
original_statistics_port = dns_server.statistics_port
|
|
|
|
dns_server.statistics_port = 1234
|
2012-12-07 12:46:18 +00:00
|
|
|
dns_server.save()
|
2012-12-16 02:59:51 +00:00
|
|
|
response = self.client.get(reverse("server_zone_list", args=("testserver1",)))
|
2012-12-07 02:46:10 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(response.context["dns_server"], "testserver1")
|
|
|
|
self.assertEqual(response.context["zone_array"], {})
|
|
|
|
self.assertEqual(response.context["errors"], "Unable to list server zones. Error: <urlopen error [Errno 111] Connection refused>")
|
|
|
|
dns_server.statistics_port = original_statistics_port
|
2012-12-07 12:46:18 +00:00
|
|
|
dns_server.save()
|
2012-12-10 02:22:47 +00:00
|
|
|
|
|
|
|
def test_Integration_ZoneList_MissingTransferKey(self):
|
|
|
|
"""Attempt to list a zone's records with missing TSIG key.
|
2015-06-13 10:05:42 +00:00
|
|
|
|
2012-12-10 02:22:47 +00:00
|
|
|
domain3.local should be configured to require a TSIG key
|
2015-06-13 10:05:42 +00:00
|
|
|
for transfers.
|
|
|
|
"""
|
2012-12-10 02:22:47 +00:00
|
|
|
dns_server = models.BindServer.objects.get(hostname="testserver1")
|
2012-12-16 02:59:51 +00:00
|
|
|
response = self.client.get(reverse("zone_list", args=("testserver1", "domain3.local")))
|
2012-12-10 02:22:47 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(response.context["zone_name"], "domain3.local")
|
|
|
|
self.assertEqual(response.context["dns_server"], "testserver1")
|
2015-06-13 10:05:42 +00:00
|
|
|
self.assertRegexpMatches(str(response.context["errors"]),
|
|
|
|
"Unable to perform AXFR to list zone records. Did you forget to specify a default transfer key?")
|