def test_no_update_when_glue(self): """A record shouldn't update it's label or domain when it is a glue record""" label = 'ns99' glue = AddressRecord(label=label, domain=self.o_e, ip_str='128.193.1.10', ip_type='4') glue.save() server = "%s.%s" % (label, self.o_e) ns = Nameserver(domain=self.o_e, server=server) ns.save() self.assertTrue(ns.glue == glue) # Shouldn't be able to edit label or domain. glue.label = "ns100" self.assertRaises(ValidationError, glue.save) glue.domain = self.m_o_e self.assertRaises(ValidationError, glue.save) glue = AddressRecord.objects.get(pk=glue.pk) glue.label = "ns101" glue.domain = self.e self.assertRaises(ValidationError, glue.save) # Ip can change. glue = AddressRecord.objects.get(pk=glue.pk) glue.ip_str = "192.192.12.12" glue.save()
def test_ns_exists(self): # Duplicate test? data = "wat" dom, _ = Domain.objects.get_or_create(name="cd") dom, _ = Domain.objects.get_or_create(name="what.cd") rec = Nameserver(domain=dom, server="asdf1") rec.save() cn = CNAME(label='', domain=dom, target=data) self.assertRaises(ValidationError, cn.clean)
def do_add(self, domain, server): ns = Nameserver(domain=domain, server=server) ns.save() self.assertTrue(ns.__repr__()) self.assertTrue(ns.details()) self.assertTrue(ns.get_absolute_url()) self.assertTrue(ns.get_edit_url()) self.assertTrue(ns.get_delete_url()) ret = Nameserver.objects.filter(domain=domain, server=server) self.assertEqual(len(ret), 1) return ns
def test_delegation(self): name = "boom" dom = Domain(name=name, delegated=True) dom.save() # Creating objects in the domain should be locked. arec = AddressRecord(label="ns1", domain=dom, ip_str="128.193.99.9", ip_type='4') self.assertRaises(ValidationError, arec.save) ns = Nameserver(domain=dom, server="ns1." + dom.name) self.assertRaises(ValidationError, ns.save) cn = CNAME(label="999asdf", domain=dom, target="asdf.asdf") self.assertRaises(ValidationError, cn.full_clean) # Undelegate (unlock) the domain. dom.delegated = False dom.save() # Add glue and ns record. arec.save() ns.save() # Re delegate the domain. dom.delegated = True dom.save() # Creation should still be locked arec1 = AddressRecord(label="ns2", domain=dom, ip_str="128.193.99.9", ip_type='4') self.assertRaises(ValidationError, arec1.save) cn1 = CNAME(label="1000asdf", domain=dom, target="asdf.asdf") self.assertRaises(ValidationError, cn1.full_clean) # Editing should be allowed. arec = AddressRecord.objects.get(pk=arec.pk) arec.ip_str = "129.193.88.2" arec.save() # Adding new A records that have the same name as an NS should # be allowed. arec1 = AddressRecord(label="ns1", domain=dom, ip_str="128.193.100.10", ip_type='4') arec1.save()
def test_ns_cleanup(self): self.assertFalse(Domain.objects.filter(name="x.y.z.foo.poo")) self.assertFalse(Domain.objects.filter(name="y.z.foo.poo")) self.assertFalse(Domain.objects.filter(name="z.foo.poo")) self.assertTrue(Domain.objects.filter(name="foo.poo")) fqdn = "bar.x.y.z.foo.poo" label, the_domain = ensure_label_domain(fqdn) ns = Nameserver(domain=the_domain, server="asdfasffoo") ns.save() self.assertFalse(prune_tree(the_domain)) ns.delete() self.assertFalse(Domain.objects.filter(name="x.y.z.foo.poo")) self.assertFalse(Domain.objects.filter(name="y.z.foo.poo")) self.assertFalse(Domain.objects.filter(name="z.foo.poo")) self.assertTrue(Domain.objects.filter(name="foo.poo"))
def test_delegation(self): name = "boom" dom = Domain(name=name, delegated=True) dom.save() # Creating objects in the domain should be locked. arec = AddressRecord(label="ns1", domain=dom, ip_str="128.193.99.9", ip_type='4') self.assertRaises(ValidationError, arec.save) ns = Nameserver(domain=dom, server="ns1." + dom.name) self.assertRaises(ValidationError, ns.save) cn = CNAME(label="999asdf", domain=dom, target="asdf.asdf") self.assertRaises(ValidationError, cn.full_clean) # Undelegate (unlock) the domain. dom.delegated = False dom.save() # Add glue and ns record. arec.save() ns.save() # Re delegate the domain. dom.delegated = True dom.save() # Creation should still be locked arec1 = AddressRecord( label="ns2", domain=dom, ip_str="128.193.99.9", ip_type='4') self.assertRaises(ValidationError, arec1.save) cn1 = CNAME(label="1000asdf", domain=dom, target="asdf.asdf") self.assertRaises(ValidationError, cn1.full_clean) # Editing should be allowed. arec = AddressRecord.objects.get(pk=arec.pk) arec.ip_str = "129.193.88.2" arec.save() # Adding new A records that have the same name as an NS should # be allowed. arec1 = AddressRecord(label="ns1", domain=dom, ip_str="128.193.100.10", ip_type='4') arec1.save()
def test_basic_add_remove5(self): # Make sure all record types block f_c = create_fake_zone("foo.foo22", suffix="") self.assertFalse(f_c.purgeable) fqdn = "bar.x.y.z.foo.foo22" label, the_domain = ensure_label_domain(fqdn) txt = TXT(label=label, domain=the_domain, txt_data="Nthing") txt.save() self.assertFalse(prune_tree(the_domain)) txt.delete() label, the_domain = ensure_label_domain(fqdn) addr = AddressRecord(label=label, domain=the_domain, ip_type='4', ip_str="10.2.3.4") addr.save() self.assertFalse(prune_tree(the_domain)) addr.delete() label, the_domain = ensure_label_domain(fqdn) mx = MX(label=label, domain=the_domain, server="foo", priority=4) mx.save() self.assertFalse(prune_tree(the_domain)) mx.delete() label, the_domain = ensure_label_domain(fqdn) ns = Nameserver(domain=the_domain, server="asdfasffoo") ns.save() self.assertFalse(prune_tree(the_domain)) ns.delete() label, the_domain = ensure_label_domain(fqdn) srv = SRV(label='_' + label, domain=the_domain, target="foo", priority=4, weight=4, port=34) srv.save() self.assertFalse(prune_tree(the_domain)) srv.delete()
def test_basic_add_remove5(self): # Make sure all record types block f_c = create_fake_zone("foo.foo22", suffix="") self.assertFalse(f_c.purgeable) fqdn = "bar.x.y.z.foo.foo22" label, the_domain = ensure_label_domain(fqdn) txt = TXT(label=label, domain=the_domain, txt_data="Nthing") txt.save() self.assertFalse(prune_tree(the_domain)) txt.delete() label, the_domain = ensure_label_domain(fqdn) addr = AddressRecord(label=label, domain=the_domain, ip_type='4', ip_str="10.2.3.4") addr.save() self.assertFalse(prune_tree(the_domain)) addr.delete() label, the_domain = ensure_label_domain(fqdn) mx = MX(label=label, domain=the_domain, server="foo", priority=4) mx.save() self.assertFalse(prune_tree(the_domain)) mx.delete() label, the_domain = ensure_label_domain(fqdn) ns = Nameserver(domain=the_domain, server="asdfasffoo") ns.save() self.assertFalse(prune_tree(the_domain)) ns.delete() label, the_domain = ensure_label_domain(fqdn) srv = SRV( label='_' + label, domain=the_domain, target="foo", priority=4, weight=4, port=34) srv.save() self.assertFalse(prune_tree(the_domain)) srv.delete()
def test_no_ns_views(self): root_domain = create_fake_zone("12.88.in-addr.arpa", suffix="") self.assertEqual(1, root_domain.nameserver_set.all().count()) ns = root_domain.nameserver_set.all()[0] self.assertTrue(self.private_view in ns.views.all()) self.assertTrue(self.public_view in ns.views.all()) ptr = PTR(ip_str="88.12.1.1", ip_type='4', name='foo.bar') ptr.full_clean() ptr.save() # At this point we have a zone with a NS in both private and public # views. There is a ptr in the zone but its not in a view. # Add the ptr to the public view ptr.views.add(self.public_view) ptr = PTR.objects.get(pk=ptr.pk) self.assertTrue(self.public_view in ptr.views.all()) ns_url = self.object_url.format( API_VERSION, str(self.test_type.__name__).lower(), ns.pk ) # The url for the nameserver in the zone # Try removing the NS from the public view, it should fail post_data = {'pk': ns.pk, 'views': ['no-public']} update_resp, post_data = self.generic_update( ns_url, post_data, assertResponse=self.assertHttpBadRequest ) ns = Nameserver.objects.get(pk=ns.pk) # Nothing should have changed self.assertTrue(self.private_view in ns.views.all()) self.assertTrue(self.public_view in ns.views.all()) # We should be allowed to remove the private view post_data = {'pk': ns.pk, 'views': ['no-private']} update_resp, post_data = self.generic_update(ns_url, post_data) ns = Nameserver.objects.get(pk=ns.pk) self.assertTrue(self.private_view not in ns.views.all()) self.assertTrue(self.public_view in ns.views.all()) # Re add all views to the NS ns = Nameserver.objects.get(pk=ns.pk) ns.views.add(self.public_view) ns.views.add(self.private_view) # Remove the ptr from the public view and add it to the private view ptr.views.remove(self.public_view) ptr.views.add(self.private_view) # Try removing the NS from the private view, it should fail post_data = {'pk': ns.pk, 'views': ['no-private']} update_resp, post_data = self.generic_update( ns_url, post_data, assertResponse=self.assertHttpBadRequest ) ns = Nameserver.objects.get(pk=ns.pk) self.assertTrue(self.private_view in ns.views.all()) self.assertTrue(self.public_view in ns.views.all()) # Create another NS record ns1 = Nameserver(domain=root_domain, server="foo.bar") ns1.save() ns1.views.add(self.private_view) # there is another NS there now, we should be able to remove the # private view post_data = {'pk': ns.pk, 'views': ['no-private']} update_resp, post_data = self.generic_update(ns_url, post_data) ns = Nameserver.objects.get(pk=ns.pk) self.assertTrue(self.private_view not in ns.views.all()) self.assertTrue(self.public_view in ns.views.all()) # The new ns (ns1) is the only ns enabled, it should not be allowed to # leave the private view. Try removing the NS from the private view, it # should fail post_data_ns1 = {'pk': ns1.pk, 'views': ['no-private']} ns1_url = self.object_url.format( API_VERSION, str(self.test_type.__name__).lower(), ns1.pk ) # The url for the nameserver in the zone update_resp, post_data_ns1 = self.generic_update( ns1_url, post_data_ns1, assertResponse=self.assertHttpBadRequest ) ns1 = Nameserver.objects.get(pk=ns1.pk) self.assertTrue(self.private_view in ns1.views.all()) self.assertTrue(self.public_view in ns.views.all()) # Re-add the original ns to the private view and then delete ns1 post_data = {'pk': ns.pk, 'views': ['private']} update_resp, post_data = self.generic_update(ns_url, post_data) ns = Nameserver.objects.get(pk=ns.pk) self.assertTrue(self.private_view in ns.views.all()) self.assertTrue(self.public_view in ns.views.all()) ns1.delete() # There is now one ns that is in the private and public view self.assertEqual(1, root_domain.nameserver_set.all().count()) self.assertTrue(self.private_view in ns.views.all()) self.assertTrue(self.public_view in ns.views.all()) # We should be allowed to remove the public view post_data = {'pk': ns.pk, 'views': ['no-public']} update_resp, post_data = self.generic_update(ns_url, post_data) self.assertHttpAccepted(update_resp) ns = Nameserver.objects.get(pk=ns.pk) self.assertTrue(self.private_view in ns.views.all()) self.assertTrue(self.public_view not in ns.views.all()) # Remove the ptr from all views ptr.views.remove(self.private_view) self.assertTrue(self.public_view not in ptr.views.all()) # We should now be able to remove the private view post_data = {'pk': ns.pk, 'views': ['no-private']} update_resp, post_data = self.generic_update(ns_url, post_data) ns = Nameserver.objects.get(pk=ns.pk) self.assertTrue(self.private_view not in ns.views.all()) self.assertTrue(self.public_view not in ns.views.all())
def test_no_ns_views(self): root_domain = create_fake_zone("12.88.in-addr.arpa", suffix="") self.assertEqual(1, root_domain.nameserver_set.all().count()) ns = root_domain.nameserver_set.all()[0] self.assertTrue(self.private_view in ns.views.all()) self.assertTrue(self.public_view in ns.views.all()) ptr = PTR(ip_str="88.12.1.1", ip_type='4', name='foo.bar') ptr.full_clean() ptr.save() # At this point we have a zone with a NS in both private and public # views. There is a ptr in the zone but its not in a view. # Add the ptr to the public view ptr.views.add(self.public_view) ptr = PTR.objects.get(pk=ptr.pk) self.assertTrue(self.public_view in ptr.views.all()) ns_url = self.object_url.format( API_VERSION, str(self.test_type.__name__).lower(), ns.pk) # The url for the nameserver in the zone # Try removing the NS from the public view, it should fail post_data = {'pk': ns.pk, 'views': ['no-public']} update_resp, post_data = self.generic_update( ns_url, post_data, assertResponse=self.assertHttpBadRequest) ns = Nameserver.objects.get(pk=ns.pk) # Nothing should have changed self.assertTrue(self.private_view in ns.views.all()) self.assertTrue(self.public_view in ns.views.all()) # We should be allowed to remove the private view post_data = {'pk': ns.pk, 'views': ['no-private']} update_resp, post_data = self.generic_update(ns_url, post_data) ns = Nameserver.objects.get(pk=ns.pk) self.assertTrue(self.private_view not in ns.views.all()) self.assertTrue(self.public_view in ns.views.all()) # Re add all views to the NS ns = Nameserver.objects.get(pk=ns.pk) ns.views.add(self.public_view) ns.views.add(self.private_view) # Remove the ptr from the public view and add it to the private view ptr.views.remove(self.public_view) ptr.views.add(self.private_view) # Try removing the NS from the private view, it should fail post_data = {'pk': ns.pk, 'views': ['no-private']} update_resp, post_data = self.generic_update( ns_url, post_data, assertResponse=self.assertHttpBadRequest) ns = Nameserver.objects.get(pk=ns.pk) self.assertTrue(self.private_view in ns.views.all()) self.assertTrue(self.public_view in ns.views.all()) # Create another NS record ns1 = Nameserver(domain=root_domain, server="foo.bar") ns1.save() ns1.views.add(self.private_view) # there is another NS there now, we should be able to remove the # private view post_data = {'pk': ns.pk, 'views': ['no-private']} update_resp, post_data = self.generic_update(ns_url, post_data) ns = Nameserver.objects.get(pk=ns.pk) self.assertTrue(self.private_view not in ns.views.all()) self.assertTrue(self.public_view in ns.views.all()) # The new ns (ns1) is the only ns enabled, it should not be allowed to # leave the private view. Try removing the NS from the private view, it # should fail post_data_ns1 = {'pk': ns1.pk, 'views': ['no-private']} ns1_url = self.object_url.format( API_VERSION, str(self.test_type.__name__).lower(), ns1.pk) # The url for the nameserver in the zone update_resp, post_data_ns1 = self.generic_update( ns1_url, post_data_ns1, assertResponse=self.assertHttpBadRequest) ns1 = Nameserver.objects.get(pk=ns1.pk) self.assertTrue(self.private_view in ns1.views.all()) self.assertTrue(self.public_view in ns.views.all()) # Re-add the original ns to the private view and then delete ns1 post_data = {'pk': ns.pk, 'views': ['private']} update_resp, post_data = self.generic_update(ns_url, post_data) ns = Nameserver.objects.get(pk=ns.pk) self.assertTrue(self.private_view in ns.views.all()) self.assertTrue(self.public_view in ns.views.all()) ns1.delete() # There is now one ns that is in the private and public view self.assertEqual(1, root_domain.nameserver_set.all().count()) self.assertTrue(self.private_view in ns.views.all()) self.assertTrue(self.public_view in ns.views.all()) # We should be allowed to remove the public view post_data = {'pk': ns.pk, 'views': ['no-public']} update_resp, post_data = self.generic_update(ns_url, post_data) self.assertHttpAccepted(update_resp) ns = Nameserver.objects.get(pk=ns.pk) self.assertTrue(self.private_view in ns.views.all()) self.assertTrue(self.public_view not in ns.views.all()) # Remove the ptr from all views ptr.views.remove(self.private_view) self.assertTrue(self.public_view not in ptr.views.all()) # We should now be able to remove the private view post_data = {'pk': ns.pk, 'views': ['no-private']} update_resp, post_data = self.generic_update(ns_url, post_data) ns = Nameserver.objects.get(pk=ns.pk) self.assertTrue(self.private_view not in ns.views.all()) self.assertTrue(self.public_view not in ns.views.all())