Exemple #1
0
    def generic_check(self, obj, do_label=True, label_prefix=""):
        # Make sure all record types block
        c, _ = Domain.objects.get_or_create(name='foo22')
        self.assertFalse(c.purgeable)
        f_c, _ = Domain.objects.get_or_create(name='foo.foo22')
        s, _ = SOA.objects.get_or_create(primary="foo", contact="foo",
                                         comment="foo.foo22")
        f_c.soa = s
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.foo22"
        label, the_domain = ensure_label_domain(fqdn)
        if do_label:
            # NS records don't like labels
            label = label_prefix + label
            obj.label = label
        obj.domain = the_domain
        obj.save()

        fqdn = "bar.x.y.xx.foo.foo22"
        label, new_domain = ensure_label_domain(fqdn)
        obj.domain = new_domain
        obj.save()

        # The original domain should have been deleted.
        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo22"))
        # Make sure no objects were harmed.
        self.assertTrue(obj.__class__.objects.get(pk=obj.pk))
        obj.delete()
        # The new domain should now have been deleted.
        self.assertFalse(Domain.objects.filter(name="x.y.xx.foo.foo22"))
Exemple #2
0
    def generic_check(self, obj, do_label=True, label_prefix=""):
        # Make sure all record types block
        c, _ = Domain.objects.get_or_create(name='foo22')
        self.assertFalse(c.purgeable)
        f_c, _ = Domain.objects.get_or_create(name='foo.foo22')
        s, _ = SOA.objects.get_or_create(primary="foo",
                                         contact="foo",
                                         comment="foo.foo22")
        f_c.soa = s
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.foo22"
        label, the_domain = ensure_label_domain(fqdn)
        if do_label:
            # NS records don't like labels
            label = label_prefix + label
            obj.label = label
        obj.domain = the_domain
        obj.save()

        fqdn = "bar.x.y.xx.foo.foo22"
        label, new_domain = ensure_label_domain(fqdn)
        obj.domain = new_domain
        obj.save()

        # The original domain should have been deleted.
        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo22"))
        # Make sure no objects were harmed.
        self.assertTrue(obj.__class__.objects.get(pk=obj.pk))
        obj.delete()
        # The new domain should now have been deleted.
        self.assertFalse(Domain.objects.filter(name="x.y.xx.foo.foo22"))
Exemple #3
0
    def generic_check(self, obj, do_label=True, label_prefix=""):
        # Make sure all record types block
        f_c = create_zone('foo.foo22')
        self.ctnr.domains.add(f_c)
        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.foo22"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        if do_label:
            # NS records don't like labels
            label = label_prefix + label
            obj.label = label
        obj.domain = the_domain
        obj.save()

        fqdn = "bar.x.y.xx.foo.foo22"
        label, new_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(new_domain)
        obj.domain = new_domain
        obj.save()

        # The original domain should have been deleted.
        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo22"))
        # Make sure no objects were harmed.
        self.assertTrue(obj.__class__.objects.get(pk=obj.pk))
        obj.delete()
        # The new domain should now have been deleted.
        self.assertFalse(Domain.objects.filter(name="x.y.xx.foo.foo22"))
Exemple #4
0
    def test_basic_add_remove8(self):
        # Make sure a record's label is changed to '' when a domain with the
        # same name as it's fqdn is created.
        Domain.objects.create(name='foo3')
        f_c = create_zone('foo.foo3')
        self.assertFalse(f_c.purgeable)

        fqdn = "www.x.y.z.foo.foo3"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        self.assertEqual('www', label)
        self.assertEqual('x.y.z.foo.foo3', the_domain.name)
        self.assertTrue(the_domain.pk)

        cname = CNAME.objects.create(
            label=label, ctnr=self.ctnr, domain=the_domain, target="foo")
        fqdn = "*.www.x.y.z.foo.foo3"
        the_domain.save()
        label2, the_domain2 = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain2)
        cname = CNAME.objects.get(fqdn=cname.fqdn)
        self.assertEqual('', cname.label)
        self.assertEqual('www.x.y.z.foo.foo3', cname.domain.name)
        self.assertEqual('*', label2)
        self.assertEqual('www.x.y.z.foo.foo3', the_domain2.name)
Exemple #5
0
    def test_basic_add_remove8(self):
        # Make sure a record's label is changed to '' when a domain with the
        # same name as it's fqdn is created.
        Domain.objects.create(name='foo3')
        f_c = create_zone('foo.foo3')
        self.assertFalse(f_c.purgeable)

        fqdn = "www.x.y.z.foo.foo3"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        self.assertEqual('www', label)
        self.assertEqual('x.y.z.foo.foo3', the_domain.name)
        self.assertTrue(the_domain.pk)

        cname = CNAME.objects.create(
            label=label, ctnr=self.ctnr, domain=the_domain, target="foo")
        fqdn = "*.www.x.y.z.foo.foo3"
        the_domain.save()
        label2, the_domain2 = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain2)
        cname = CNAME.objects.get(fqdn=cname.fqdn)
        self.assertEqual('', cname.label)
        self.assertEqual('www.x.y.z.foo.foo3', cname.domain.name)
        self.assertEqual('*', label2)
        self.assertEqual('www.x.y.z.foo.foo3', the_domain2.name)
Exemple #6
0
    def generic_check(self, obj, do_label=True, label_prefix=""):
        # Make sure all record types block
        f_c = create_zone('foo.foo22')
        self.ctnr.domains.add(f_c)
        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.foo22"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        if do_label:
            # NS records don't like labels
            label = label_prefix + label
            obj.label = label
        obj.domain = the_domain
        obj.save()

        fqdn = "bar.x.y.xx.foo.foo22"
        label, new_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(new_domain)
        obj.domain = new_domain
        obj.save()

        # The original domain should have been deleted.
        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo22"))
        # Make sure no objects were harmed.
        self.assertTrue(obj.__class__.objects.get(pk=obj.pk))
        obj.delete()
        # The new domain should now have been deleted.
        self.assertFalse(Domain.objects.filter(name="x.y.xx.foo.foo22"))
Exemple #7
0
    def test_basic_add_remove5(self):
        # Make sure all record types block
        Domain.objects.create(name='foo22')
        f_c = create_zone('foo.foo22')
        self.assertFalse(f_c.purgeable)

        fqdn = "bar.x.y.z.foo.foo22"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)

        txt = TXT.objects.create(label=label,
                                 ctnr=self.ctnr,
                                 domain=the_domain,
                                 txt_data="Nothing")
        self.assertFalse(prune_tree(the_domain))
        txt.delete()

        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        addr = AddressRecord.objects.create(label=label,
                                            ctnr=self.ctnr,
                                            domain=the_domain,
                                            ip_type='4',
                                            ip_str="10.2.3.4")
        self.assertFalse(prune_tree(the_domain))
        addr.delete()

        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        mx = MX.objects.create(label=label,
                               ctnr=self.ctnr,
                               domain=the_domain,
                               server="foo",
                               priority=4)
        self.assertFalse(prune_tree(the_domain))
        mx.delete()

        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        ns = Nameserver.objects.create(domain=the_domain, server="asdfasffoo")
        self.assertFalse(prune_tree(the_domain))
        ns.delete()

        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        srv = SRV.objects.create(label='_' + label,
                                 ctnr=self.ctnr,
                                 domain=the_domain,
                                 target="foo",
                                 priority=4,
                                 weight=4,
                                 port=34)
        self.assertFalse(prune_tree(the_domain))
        srv.delete()
Exemple #8
0
    def test_basic_add_remove5(self):
        # Make sure all record types block
        c = Domain(name='foo22')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = Domain(name='foo.foo22')
        s, _ = SOA.objects.get_or_create(primary="foo",
                                         contact="foo",
                                         comment="foo.foo22")
        f_c.soa = s
        f_c.save()
        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()
Exemple #9
0
    def test_cleanup_cname(self):
        # Make sure CNAME record block
        c = Domain.objects.create(name='foo1')
        self.assertFalse(c.purgeable)
        f_c = create_zone('foo.foo1')
        self.ctnr.domains.add(f_c)
        self.assertEqual(f_c.name, 'foo.foo1')

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1").exists())
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1").exists())
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1").exists())
        self.assertTrue(Domain.objects.filter(name="foo.foo1").exists())

        self.assertFalse(f_c.purgeable)
        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)

        cname = CNAME.objects.create(
            label=label, ctnr=self.ctnr, domain=the_domain, target="foo")
        self.assertFalse(prune_tree(the_domain))
        cname.delete()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1").exists())
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1").exists())
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1").exists())
        fqdn = "bar.x.y.z.foo.poo"
        self.assertTrue(Domain.objects.filter(name="foo.foo1").exists())
Exemple #10
0
    def test_cleanup_cname(self):
        # Make sure CNAME record block
        c = Domain.objects.create(name='foo1')
        self.assertFalse(c.purgeable)
        f_c = create_zone('foo.foo1')
        self.ctnr.domains.add(f_c)
        self.assertEqual(f_c.name, 'foo.foo1')

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1").exists())
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1").exists())
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1").exists())
        self.assertTrue(Domain.objects.filter(name="foo.foo1").exists())

        self.assertFalse(f_c.purgeable)
        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)

        cname = CNAME.objects.create(label=label,
                                     ctnr=self.ctnr,
                                     domain=the_domain,
                                     target="foo")
        self.assertFalse(prune_tree(the_domain))
        cname.delete()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1").exists())
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1").exists())
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1").exists())
        fqdn = "bar.x.y.z.foo.poo"
        self.assertTrue(Domain.objects.filter(name="foo.foo1").exists())
Exemple #11
0
    def test_basic_add_remove3(self):
        # Make sure that if a domain is set to not purgeable the prune stops at
        # that domain when a record exists in a domain.
        Domain.objects.create(name='foo')
        f_c = create_zone('foo.foo')
        self.assertFalse(f_c.purgeable)

        fqdn = "bar.x.y.z.foo.foo"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)

        txt = TXT.objects.create(
            label=label, ctnr=self.ctnr, domain=the_domain, txt_data="Nothing")

        self.assertTrue(the_domain.purgeable)
        # txt makes the domain un-purgeable.
        self.assertFalse(prune_tree(the_domain))
        txt.delete()
        # The tree should have pruned itself.

        # Make sure stuff was deleted.
        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo"))
        self.assertTrue(Domain.objects.filter(name="foo.foo"))
Exemple #12
0
    def test_basic_add_remove3(self):
        # Make sure that if a domain is set to not purgeable the prune stops at
        # that domain when a record exists in a domain.
        Domain.objects.create(name='foo')
        f_c = create_zone('foo.foo')
        self.assertFalse(f_c.purgeable)

        fqdn = "bar.x.y.z.foo.foo"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)

        txt = TXT.objects.create(
            label=label, ctnr=self.ctnr, domain=the_domain, txt_data="Nothing")

        self.assertTrue(the_domain.purgeable)
        # txt makes the domain un-purgeable.
        self.assertFalse(prune_tree(the_domain))
        txt.delete()
        # The tree should have pruned itself.

        # Make sure stuff was deleted.
        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo"))
        self.assertTrue(Domain.objects.filter(name="foo.foo"))
Exemple #13
0
    def test_cleanup_cname(self):
        # Make sure CNAME record block
        c = Domain(name='foo1')
        c.save()
        self.assertFalse(c.purgeable)
        s, _ = SOA.objects.get_or_create(primary="foo", contact="Foo",
                                         comment="dddfoo")
        f_c = Domain(name='foo.foo1')
        f_c.soa = s
        f_c.save()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))

        self.assertFalse(f_c.purgeable)
        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        fqdn = "bar.x.y.z.foo.poo"
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))
Exemple #14
0
    def test_cleanup_intr(self):
        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.poo").exists())
        self.assertFalse(Domain.objects.filter(name="y.z.foo.poo").exists())
        self.assertFalse(Domain.objects.filter(name="z.foo.poo").exists())
        self.assertTrue(Domain.objects.filter(name="foo.poo").exists())

        create_zone('10.in-addr.arpa')

        fqdn = "bar.x.y.z.foo.poo"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        self.ctnr.ranges.add(self.sr)
        system = System.objects.create(name='foobar', ctnr=self.ctnr)
        addr = StaticInterface.objects.create(label=label,
                                              domain=the_domain,
                                              ip_type='4',
                                              ip_str="10.2.3.4",
                                              mac="00:11:22:33:44:55",
                                              system=system)
        self.assertFalse(prune_tree(the_domain))
        addr.delete(**{'delete_system': False})

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.poo").exists())
        self.assertFalse(Domain.objects.filter(name="y.z.foo.poo").exists())
        self.assertFalse(Domain.objects.filter(name="z.foo.poo").exists())
        self.assertTrue(Domain.objects.filter(name="foo.poo").exists())
Exemple #15
0
    def test_cleanup_cname(self):
        # Make sure CNAME record block
        c = Domain(name='foo1')
        c.save()
        self.assertFalse(c.purgeable)
        s, _ = SOA.objects.get_or_create(primary="foo",
                                         contact="Foo",
                                         comment="dddfoo")
        f_c = Domain(name='foo.foo1')
        f_c.soa = s
        f_c.save()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))

        self.assertFalse(f_c.purgeable)
        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        fqdn = "bar.x.y.z.foo.poo"
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))
Exemple #16
0
    def test_basic_add_remove3(self):
        # MAke sure that if a domain is set to not purgeable the prune stops at
        # that domain when a record exists in a domain
        c = Domain(name='foo')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = Domain(name='foo.foo')
        s, _ = SOA.objects.get_or_create(primary="foo", contact="foo",
                                         comment="foo.foo")
        f_c.soa = s
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.foo"
        label, the_domain = ensure_label_domain(fqdn)
        txt = TXT(label=label, domain=the_domain, txt_data="Nthing")
        txt.save()

        self.assertTrue(the_domain.purgeable)
        # txt makes the domain un-purgeable.
        self.assertFalse(prune_tree(the_domain))
        txt.delete()
        # The tree should have pruned itself

        # Make sure stuff was deleted.
        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo"))
        self.assertTrue(Domain.objects.filter(name="foo.foo"))
Exemple #17
0
    def test_basic_add_remove3(self):
        # MAke sure that if a domain is set to not purgeable the prune stops at
        # that domain when a record exists in a domain
        c = Domain(name='foo')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = Domain(name='foo.foo')
        s, _ = SOA.objects.get_or_create(primary="foo",
                                         contact="foo",
                                         comment="foo.foo")
        f_c.soa = s
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.foo"
        label, the_domain = ensure_label_domain(fqdn)
        txt = TXT(label=label, domain=the_domain, txt_data="Nthing")
        txt.save()

        self.assertTrue(the_domain.purgeable)
        # txt makes the domain un-purgeable.
        self.assertFalse(prune_tree(the_domain))
        txt.delete()
        # The tree should have pruned itself

        # Make sure stuff was deleted.
        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo"))
        self.assertTrue(Domain.objects.filter(name="foo.foo"))
Exemple #18
0
    def test_cleanup_cname(self):
        # Make sure CNAME record block
        c = Domain(name='foo1')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = create_fake_zone('foo.foo1', suffix="")
        self.assertEqual(f_c.name, 'foo.foo1')

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))

        self.assertFalse(f_c.purgeable)
        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        fqdn = "bar.x.y.z.foo.poo"
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))
Exemple #19
0
def table_update(request, pk, obj_type=None):
    """
    Called from editableGrid tables when updating a field. Try to update
    an object specified by pk with the post data.
    """
    # Infer obj_type from URL, saves trouble of having to specify
    # kwargs everywhere in the dispatchers.
    obj_type = obj_type or request.path.split('/')[2]

    Klass, FormKlass = get_klasses(obj_type)
    obj = get_object_or_404(Klass, pk=pk)

    if not perm_soft(request, ACTION_UPDATE, obj=obj):
        return HttpResponse(json.dumps({'error': 'You do not have appropriate'
                                                 ' permissions.'}))

    # DNS specific.
    qd = request.POST.copy()
    if 'fqdn' in qd and obj_type != "ptr":
        fqdn = qd.pop('fqdn')[0]
        try:
            # Call prune tree later if error, else domain leak.
            label, domain = ensure_label_domain(fqdn)
        except ValidationError, e:
            return HttpResponse(json.dumps({'error': e.messages}))
        qd['label'], qd['domain'] = label, str(domain.pk)
Exemple #20
0
    def test_cleanup_intr(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"))

        Domain.objects.get_or_create(name="arpa")
        Domain.objects.get_or_create(name="in-addr.arpa")
        Domain.objects.get_or_create(name="10.in-addr.arpa")

        fqdn = "bar.x.y.z.foo.poo"
        label, the_domain = ensure_label_domain(fqdn)
        system = System()
        addr = StaticInterface(label=label,
                               domain=the_domain,
                               ip_type='4',
                               ip_str="10.2.3.4",
                               mac="00:11:22:33:44:55",
                               system=system)
        addr.save()
        self.assertFalse(prune_tree(the_domain))
        addr.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"))
Exemple #21
0
    def test_cleanup_intr(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"))

        Domain.objects.get_or_create(name="arpa")
        Domain.objects.get_or_create(name="in-addr.arpa")
        Domain.objects.get_or_create(name="10.in-addr.arpa")

        fqdn = "bar.x.y.z.foo.poo"
        label, the_domain = ensure_label_domain(fqdn)
        system = System()
        addr = StaticInterface(
            label=label, domain=the_domain, ip_type='4', ip_str="10.2.3.4",
            mac="00:11:22:33:44:55", system=system
        )
        addr.save()
        self.assertFalse(prune_tree(the_domain))
        addr.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"))
Exemple #22
0
    def test_cleanup_cname(self):
        # Make sure CNAME record block
        c = Domain(name='foo1')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = create_fake_zone('foo.foo1', suffix="")
        self.assertEqual(f_c.name, 'foo.foo1')

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))

        self.assertFalse(f_c.purgeable)
        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        fqdn = "bar.x.y.z.foo.poo"
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))
Exemple #23
0
def table_update(request, pk, obj_type=None):
    """
    Called from editableGrid tables when updating a field. Try to update
    an object specified by pk with the post data.
    """
    # Infer obj_type from URL, saves trouble of having to specify
    # kwargs everywhere in the dispatchers.
    obj_type = obj_type or request.path.split('/')[2]

    Klass, FormKlass = get_klasses(obj_type)
    obj = get_object_or_404(Klass, pk=pk)

    if not perm_soft(request, ACTION_UPDATE, obj=obj):
        return HttpResponse(json.dumps({'error': 'You do not have appropriate'
                                                 ' permissions.'}))

    # DNS specific.
    qd = request.POST.copy()
    if 'fqdn' in qd and obj_type != "ptr":
        fqdn = qd.pop('fqdn')[0]
        try:
            # Call prune tree later if error, else domain leak.
            label, domain = ensure_label_domain(fqdn)
        except ValidationError, e:
            return HttpResponse(json.dumps({'error': e.messages}))
        qd['label'], qd['domain'] = label, str(domain.pk)
Exemple #24
0
    def test_basic_add_remove2(self):
        # Make sure that if a domain is set to not purgeable the prune stops at
        # that domain.
        c = Domain.objects.create(name='edu')
        self.assertFalse(c.purgeable)
        f_c = Domain.objects.create(name='foo.edu')
        s = SOA.objects.create(
            primary="foo", contact="foo", root_domain=f_c,
            description="foo.edu")
        f_c = f_c.reload()

        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.edu"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        self.assertEqual(label, "bar")
        self.assertEqual(the_domain.name, "x.y.z.foo.edu")
        self.assertTrue(the_domain.purgeable)
        self.assertEqual(the_domain.master_domain.name, "y.z.foo.edu")
        self.assertTrue(the_domain.master_domain.purgeable)
        self.assertEqual(
            the_domain.master_domain.master_domain.name, "z.foo.edu")
        self.assertTrue(the_domain.master_domain.master_domain.purgeable)
        self.assertEqual(
            the_domain.master_domain.master_domain.master_domain.name,
            "foo.edu"
        )
        self.assertFalse(
            the_domain.master_domain.master_domain.master_domain.purgeable)

        # See if purgeable stops prune.
        the_domain.purgeable = False
        the_domain.save()
        self.assertFalse(prune_tree(the_domain))
        the_domain.purgeable = True
        the_domain.save()
        # OK, reset.

        y_z = Domain.objects.get(name="y.z.foo.edu")
        y_z.purgeable = False
        y_z.save()

        # Reload the domain.
        the_domain = the_domain.reload()
        # This should delete up to and stop at the domain "y.z.foo.edu".
        self.assertTrue(prune_tree(the_domain))

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="y.z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="foo.edu"))

        # If we delete y.z.foo.com and then call prune on z.foo.com is should
        # delete z.foo.com.
        Domain.objects.get(name="y.z.foo.edu").delete()

        self.assertTrue(prune_tree(Domain.objects.get(name="z.foo.edu")))
        self.assertFalse(Domain.objects.filter(name="z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="foo.edu"))
Exemple #25
0
    def test_basic_add_remove2(self):
        # Make sure that if a domain is set to not purgeable the prune stops at
        # that domain.
        c = Domain.objects.create(name='edu')
        self.assertFalse(c.purgeable)
        f_c = Domain.objects.create(name='foo.edu')
        s = SOA.objects.create(
            primary="foo", contact="foo", root_domain=f_c,
            description="foo.edu")
        f_c = f_c.reload()

        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.edu"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        self.assertEqual(label, "bar")
        self.assertEqual(the_domain.name, "x.y.z.foo.edu")
        self.assertTrue(the_domain.purgeable)
        self.assertEqual(the_domain.master_domain.name, "y.z.foo.edu")
        self.assertTrue(the_domain.master_domain.purgeable)
        self.assertEqual(
            the_domain.master_domain.master_domain.name, "z.foo.edu")
        self.assertTrue(the_domain.master_domain.master_domain.purgeable)
        self.assertEqual(
            the_domain.master_domain.master_domain.master_domain.name,
            "foo.edu"
        )
        self.assertFalse(
            the_domain.master_domain.master_domain.master_domain.purgeable)

        # See if purgeable stops prune.
        the_domain.purgeable = False
        the_domain.save()
        self.assertFalse(prune_tree(the_domain))
        the_domain.purgeable = True
        the_domain.save()
        # OK, reset.

        y_z = Domain.objects.get(name="y.z.foo.edu")
        y_z.purgeable = False
        y_z.save()

        # Reload the domain.
        the_domain = the_domain.reload()
        # This should delete up to and stop at the domain "y.z.foo.edu".
        self.assertTrue(prune_tree(the_domain))

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="y.z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="foo.edu"))

        # If we delete y.z.foo.com and then call prune on z.foo.com is should
        # delete z.foo.com.
        Domain.objects.get(name="y.z.foo.edu").delete()

        self.assertTrue(prune_tree(Domain.objects.get(name="z.foo.edu")))
        self.assertFalse(Domain.objects.filter(name="z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="foo.edu"))
Exemple #26
0
    def test_basic_add_remove2(self):
        # MAke sure that if a domain is set to not purgeable the prune stops at
        # that domain.
        c = Domain(name='edu')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = Domain(name='foo.edu')
        s, _ = SOA.objects.get_or_create(primary="foo", contact="foo",
                                         description="foo.edu")
        f_c.soa = s
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.edu"
        label, the_domain = ensure_label_domain(fqdn)
        self.assertEqual(label, "bar")
        self.assertEqual(the_domain.name, "x.y.z.foo.edu")
        self.assertTrue(the_domain.purgeable)
        self.assertEqual(the_domain.master_domain.name, "y.z.foo.edu")
        self.assertTrue(the_domain.master_domain.purgeable)
        self.assertEqual(
            the_domain.master_domain.master_domain.name, "z.foo.edu")
        self.assertTrue(the_domain.master_domain.master_domain.purgeable)
        self.assertEqual(
            the_domain.master_domain.master_domain.master_domain.name,
            "foo.edu"
        )
        self.assertFalse(
            the_domain.master_domain.master_domain.master_domain.purgeable)

        # See if purgeable stops prune
        the_domain.purgeable = False
        the_domain.save()
        self.assertFalse(prune_tree(the_domain))
        the_domain.purgeable = True
        the_domain.save()
        # Ok, reset

        y_z = Domain.objects.get(name="y.z.foo.edu")
        y_z.purgeable = False
        y_z.save()

        # Refresh the domain
        the_domain = Domain.objects.get(pk=the_domain.pk)
        # This should delete up to and stop at the domain "y.z.foo.edu"
        self.assertTrue(prune_tree(the_domain))

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="y.z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="foo.edu"))

        # If we delete y.z.foo.com and then call prune on z.foo.com is should
        # delete z.foo.com
        Domain.objects.get(name="y.z.foo.edu").delete()

        self.assertTrue(prune_tree(Domain.objects.get(name="z.foo.edu")))
        self.assertFalse(Domain.objects.filter(name="z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="foo.edu"))
Exemple #27
0
    def test_basic_add_remove5(self):
        # Make sure all record types block
        Domain.objects.create(name='foo22')
        f_c = create_zone('foo.foo22')
        self.assertFalse(f_c.purgeable)

        fqdn = "bar.x.y.z.foo.foo22"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)

        txt = TXT.objects.create(
            label=label, ctnr=self.ctnr, domain=the_domain, txt_data="Nothing")
        self.assertFalse(prune_tree(the_domain))
        txt.delete()

        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        addr = AddressRecord.objects.create(
            label=label, ctnr=self.ctnr, domain=the_domain, ip_type='4',
            ip_str="10.2.3.4")
        self.assertFalse(prune_tree(the_domain))
        addr.delete()

        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        mx = MX.objects.create(
            label=label, ctnr=self.ctnr, domain=the_domain, server="foo",
            priority=4)
        self.assertFalse(prune_tree(the_domain))
        mx.delete()

        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        ns = Nameserver.objects.create(
            domain=the_domain, server="asdfasffoo")
        self.assertFalse(prune_tree(the_domain))
        ns.delete()

        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        srv = SRV.objects.create(
            label='_' + label, ctnr=self.ctnr, domain=the_domain, target="foo",
            priority=4, weight=4, port=34)
        self.assertFalse(prune_tree(the_domain))
        srv.delete()
Exemple #28
0
    def test_basic_add_remove5(self):
        # Make sure all record types block
        c = Domain(name='foo22')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = Domain(name='foo.foo22')
        s, _ = SOA.objects.get_or_create(primary="foo", contact="foo",
                                         comment="foo.foo22")
        f_c.soa = s
        f_c.save()
        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()
Exemple #29
0
 def hydrate(self, bundle):
     """Hydrate handles the conversion of fqdn to a label or domain."""
     if 'fqdn' in bundle.data:
         try:
             label_domain = ensure_label_domain(bundle.data['fqdn'])
             bundle.data['label'], bundle.data['domain'] = label_domain
         except ValidationError, e:
             errors = {}
             errors['fqdn'] = e.messages
             bundle.errors['error_messages'] = json.dumps(errors)
Exemple #30
0
 def hydrate(self, bundle):
     """Hydrate handles the conversion of fqdn to a label or domain."""
     if 'fqdn' in bundle.data:
         try:
             label_domain = ensure_label_domain(bundle.data['fqdn'])
             bundle.data['label'], bundle.data['domain'] = label_domain
         except ValidationError, e:
             errors = {}
             errors['fqdn'] = e.messages
             bundle.errors['error_messages'] = json.dumps(errors)
Exemple #31
0
    def test_basic_add_remove6(self):
        # Make sure CNAME record block
        f_c = create_fake_zone("foo.foo1", suffix="")
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()
Exemple #32
0
def _fqdn_to_domain(qd):
    """Resolve FQDN to domain and attach to record object. """
    domain = None
    if 'fqdn' in qd:
        fqdn = qd.pop('fqdn')[0]
        try:
            # Call prune tree later if error, else domain leak.
            label, domain = ensure_label_domain(fqdn)
        except ValidationError, e:
            return None, None, e.messages

        qd['label'], qd['domain'] = label, str(domain.pk)
Exemple #33
0
def _fqdn_to_domain(qd):
    """Resolve FQDN to domain and attach to record object. """
    domain = None
    if 'fqdn' in qd:
        fqdn = qd.pop('fqdn')[0]
        try:
            # Call prune tree later if error, else domain leak.
            label, domain = ensure_label_domain(fqdn)
        except ValidationError, e:
            return None, None, e.messages

        qd['label'], qd['domain'] = label, str(domain.pk)
Exemple #34
0
    def test_basic_add_remove9(self):
        # Make sure all record types block
        f_c = create_fake_zone("foo.foo22", suffix="")
        self.assertFalse(f_c.purgeable)
        fqdn = "y.z.foo.foo22"
        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))

        f_c = create_fake_zone("y.z.foo.foo22", suffix="")
        self.assertFalse(f_c.purgeable)
Exemple #35
0
    def test_basic_add_remove7(self):
        # try a star record
        f_c = create_fake_zone("foo.foo2", suffix="")
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "*.x.y.z.foo.foo2"
        label, the_domain = ensure_label_domain(fqdn)
        self.assertEqual('*', label)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()
Exemple #36
0
    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()
Exemple #37
0
    def test_basic_add_remove4(self):
        # Move a record down the tree testing prune's ability to not delete
        # stuff.
        Domain.objects.create(name='goo')
        f_c = create_zone('foo.goo')
        self.assertFalse(f_c.purgeable)

        fqdn = "bar.x.y.z.foo.goo"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        txt = TXT.objects.create(label=label,
                                 ctnr=self.ctnr,
                                 domain=the_domain,
                                 txt_data="Nothing")

        self.assertTrue(the_domain.purgeable)

        # txt makes the domain un-purgeable.
        self.assertFalse(prune_tree(the_domain))
        the_next_domain = the_domain.master_domain
        txt.domain = the_next_domain
        self.ctnr.domains.add(the_next_domain)
        txt.save()
        self.assertFalse(Domain.objects.filter(pk=the_domain.pk).exists())
        # We should be able to delete now.
        self.assertTrue(prune_tree(the_domain))
        the_domain = the_next_domain

        # txt makes the domain un-purgeable. y.z.foo.com
        self.assertFalse(prune_tree(the_domain))
        the_next_domain = the_domain.master_domain
        txt.domain = the_next_domain
        self.ctnr.domains.add(the_next_domain)
        txt.save()
        self.assertFalse(Domain.objects.filter(pk=the_domain.pk))
        # We should be able to delete now.
        the_domain = the_next_domain

        # txt makes the domain un-purgeable. z.foo.com
        self.assertFalse(prune_tree(the_domain))
        the_next_domain = the_domain.master_domain
        txt.domain = the_next_domain
        self.ctnr.domains.add(the_next_domain)
        txt.save()
        self.assertFalse(Domain.objects.filter(pk=the_domain.pk).exists())
        # We should be able to delete now.
        the_domain = the_next_domain

        # txt makes the domain un-purgeable. foo.com
        self.assertFalse(prune_tree(the_domain))
Exemple #38
0
    def test_basic_add_remove4(self):
        # Move a record down the tree testing prune's ability to not delete
        # stuff.
        c = Domain(name='goo')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = Domain(name='foo.goo')
        s, _ = SOA.objects.get_or_create(primary="foo",
                                         contact="foo",
                                         comment="foo.goo")
        f_c.soa = s
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.goo"
        label, the_domain = ensure_label_domain(fqdn)
        txt = TXT(label=label, domain=the_domain, txt_data="Nthing")
        txt.save()

        self.assertTrue(the_domain.purgeable)

        # txt makes the domain un-purgeable.
        self.assertFalse(prune_tree(the_domain))
        txt.domain = the_domain.master_domain
        the_next_domain = the_domain.master_domain
        txt.save()
        self.assertFalse(Domain.objects.filter(pk=the_domain.pk))
        # We should be able to delete now.
        self.assertTrue(prune_tree(the_domain))
        the_domain = the_next_domain

        # txt makes the domain un-purgeable. y.z.foo.com
        self.assertFalse(prune_tree(the_domain))
        txt.domain = the_domain.master_domain
        the_next_domain = the_domain.master_domain
        txt.save()
        self.assertFalse(Domain.objects.filter(pk=the_domain.pk))
        # We should be able to delete now.
        the_domain = the_next_domain

        # txt makes the domain un-purgeable. z.foo.com
        self.assertFalse(prune_tree(the_domain))
        txt.domain = the_domain.master_domain
        the_next_domain = the_domain.master_domain
        txt.save()
        self.assertFalse(Domain.objects.filter(pk=the_domain.pk))
        # We should be able to delete now.
        the_domain = the_next_domain

        # txt makes the domain un-purgeable. foo.com
        self.assertFalse(prune_tree(the_domain))
Exemple #39
0
    def test_basic_add_remove4(self):
        # Move a record down the tree testing prune's ability to not delete
        # stuff.
        c = Domain(name='goo')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = Domain(name='foo.goo')
        s, _ = SOA.objects.get_or_create(primary="foo", contact="foo",
                                         comment="foo.goo")
        f_c.soa = s
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.goo"
        label, the_domain = ensure_label_domain(fqdn)
        txt = TXT(label=label, domain=the_domain, txt_data="Nthing")
        txt.save()

        self.assertTrue(the_domain.purgeable)

        # txt makes the domain un-purgeable.
        self.assertFalse(prune_tree(the_domain))
        txt.domain = the_domain.master_domain
        the_next_domain = the_domain.master_domain
        txt.save()
        self.assertFalse(Domain.objects.filter(pk=the_domain.pk))
        # We should be able to delete now.
        self.assertTrue(prune_tree(the_domain))
        the_domain = the_next_domain

        # txt makes the domain un-purgeable. y.z.foo.com
        self.assertFalse(prune_tree(the_domain))
        txt.domain = the_domain.master_domain
        the_next_domain = the_domain.master_domain
        txt.save()
        self.assertFalse(Domain.objects.filter(pk=the_domain.pk))
        # We should be able to delete now.
        the_domain = the_next_domain

        # txt makes the domain un-purgeable. z.foo.com
        self.assertFalse(prune_tree(the_domain))
        txt.domain = the_domain.master_domain
        the_next_domain = the_domain.master_domain
        txt.save()
        self.assertFalse(Domain.objects.filter(pk=the_domain.pk))
        # We should be able to delete now.
        the_domain = the_next_domain

        # txt makes the domain un-purgeable. foo.com
        self.assertFalse(prune_tree(the_domain))
Exemple #40
0
class CommonDNSResource(ModelResource):
    domain = fields.CharField()
    # User passes string, in hydrate we find a
    # domain
    views = fields.ListField(null=True, blank=True)

    # User passes list of view names, in hydrate we
    # make these the actual view objects

    def obj_delete_list(self, request=None, **kwargs):
        # We dont' want this method being used
        raise NotImplemented

    def dehydrate(self, bundle):
        # Every DNS Resource should have a domain
        bundle.data['views'] = [view.name for view in bundle.obj.views.all()]
        if 'domain' in bundle.data:
            bundle.data['domain'] = bundle.obj.domain.name
        return bundle

    def hydrate(self, bundle):
        """Hydrate handles the conversion of fqdn to a label or domain.
            This function handles two cases:
                1) Label and domain are in bundle
                2) Label and domain are *not* in bundle and fqdn is in bundle.
            All other cases cause hydration errors to be raised and
            bundle.errors will be set.
        """
        # Every DNS Resource should have a domain
        if ('fqdn' not in bundle.data and 'domain' in bundle.data
                and 'label' in bundle.data):
            domain_name = bundle.data.get('domain')
            try:
                domain = Domain.objects.get(name=domain_name)
                bundle.data['domain'] = domain
            except ObjectDoesNotExist, e:
                errors = {}
                errors['domain'] = "Couldn't find domain {0}".format(
                    domain_name)
                bundle.errors['error_messages'] = json.dumps(errors)
        elif ('fqdn' in bundle.data
              and not ('domain' in bundle.data or 'label' in bundle.data)):
            try:
                label_domain = ensure_label_domain(bundle.data['fqdn'])
                bundle.data['label'], bundle.data['domain'] = label_domain
            except ValidationError, e:
                errors = {}
                errors['fqdn'] = e.messages
                bundle.errors['error_messages'] = json.dumps(errors)
Exemple #41
0
    def test_basic_add_remove7(self):
        # try a star record
        Domain.objects.create(name='foo2')
        f_c = create_zone('foo.foo2')
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "*.x.y.z.foo.foo2"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        self.assertEqual('*', label)

        cname = CNAME.objects.create(
            label=label, ctnr=self.ctnr, domain=the_domain, target="foo")
        self.assertFalse(prune_tree(the_domain))
        cname.delete()
Exemple #42
0
    def test_basic_add_remove6(self):
        # Make sure CNAME record block
        Domain.objects.create(name='foo1')
        f_c = create_zone('foo.foo1')
        f_c.save()
        self.assertFalse(f_c.purgeable)

        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)

        cname = CNAME.objects.create(
            label=label, ctnr=self.ctnr, domain=the_domain, target="foo")
        self.assertFalse(prune_tree(the_domain))
        cname.delete()
Exemple #43
0
    def test_basic_add_remove7(self):
        # try a star record
        Domain.objects.create(name='foo2')
        f_c = create_zone('foo.foo2')
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "*.x.y.z.foo.foo2"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        self.assertEqual('*', label)

        cname = CNAME.objects.create(
            label=label, ctnr=self.ctnr, domain=the_domain, target="foo")
        self.assertFalse(prune_tree(the_domain))
        cname.delete()
Exemple #44
0
    def test_basic_add_remove6(self):
        # Make sure CNAME record block
        Domain.objects.create(name='foo1')
        f_c = create_zone('foo.foo1')
        f_c.save()
        self.assertFalse(f_c.purgeable)

        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)

        cname = CNAME.objects.create(
            label=label, ctnr=self.ctnr, domain=the_domain, target="foo")
        self.assertFalse(prune_tree(the_domain))
        cname.delete()
Exemple #45
0
    def test_basic_add_remove4(self):
        # Move a record down the tree testing prune's ability to not delete
        # stuff.
        Domain.objects.create(name='goo')
        f_c = create_zone('foo.goo')
        self.assertFalse(f_c.purgeable)

        fqdn = "bar.x.y.z.foo.goo"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        txt = TXT.objects.create(
            label=label, ctnr=self.ctnr, domain=the_domain, txt_data="Nothing")

        self.assertTrue(the_domain.purgeable)

        # txt makes the domain un-purgeable.
        self.assertFalse(prune_tree(the_domain))
        the_next_domain = the_domain.master_domain
        txt.domain = the_next_domain
        self.ctnr.domains.add(the_next_domain)
        txt.save()
        self.assertFalse(Domain.objects.filter(pk=the_domain.pk).exists())
        # We should be able to delete now.
        self.assertTrue(prune_tree(the_domain))
        the_domain = the_next_domain

        # txt makes the domain un-purgeable. y.z.foo.com
        self.assertFalse(prune_tree(the_domain))
        the_next_domain = the_domain.master_domain
        txt.domain = the_next_domain
        self.ctnr.domains.add(the_next_domain)
        txt.save()
        self.assertFalse(Domain.objects.filter(pk=the_domain.pk))
        # We should be able to delete now.
        the_domain = the_next_domain

        # txt makes the domain un-purgeable. z.foo.com
        self.assertFalse(prune_tree(the_domain))
        the_next_domain = the_domain.master_domain
        txt.domain = the_next_domain
        self.ctnr.domains.add(the_next_domain)
        txt.save()
        self.assertFalse(Domain.objects.filter(pk=the_domain.pk).exists())
        # We should be able to delete now.
        the_domain = the_next_domain

        # txt makes the domain un-purgeable. foo.com
        self.assertFalse(prune_tree(the_domain))
Exemple #46
0
    def test_basic_add_remove9(self):
        # Make sure all record types block.
        Domain.objects.create(name='foo22')
        f_c = create_zone('foo.foo22')
        self.assertFalse(f_c.purgeable)

        fqdn = "y.z.foo.foo22"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        addr = AddressRecord.objects.create(
            label=label, ctnr=self.ctnr, domain=the_domain, ip_type='4',
            ip_str="10.2.3.4")
        self.assertFalse(prune_tree(the_domain))

        new_domain = ensure_domain('y.z.foo.foo22')
        self.assertFalse(new_domain.purgeable)
Exemple #47
0
    def test_basic_add_remove9(self):
        # Make sure all record types block.
        Domain.objects.create(name='foo22')
        f_c = create_zone('foo.foo22')
        self.assertFalse(f_c.purgeable)

        fqdn = "y.z.foo.foo22"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        addr = AddressRecord.objects.create(
            label=label, ctnr=self.ctnr, domain=the_domain, ip_type='4',
            ip_str="10.2.3.4")
        self.assertFalse(prune_tree(the_domain))

        new_domain = ensure_domain('y.z.foo.foo22')
        self.assertFalse(new_domain.purgeable)
Exemple #48
0
    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"))
Exemple #49
0
    def test_cleanup_mx(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)
        mx = MX(label=label, domain=the_domain, server="foo", priority=4)
        mx.save()
        self.assertFalse(prune_tree(the_domain))
        mx.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"))
Exemple #50
0
    def test_cleanup_mx(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)
        mx = MX(label=label, domain=the_domain, server="foo", priority=4)
        mx.save()
        self.assertFalse(prune_tree(the_domain))
        mx.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"))
Exemple #51
0
    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"))
Exemple #52
0
    def test_ns_cleanup(self):
        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.poo").exists())
        self.assertFalse(Domain.objects.filter(name="y.z.foo.poo").exists())
        self.assertFalse(Domain.objects.filter(name="z.foo.poo").exists())
        self.assertTrue(Domain.objects.filter(name="foo.poo").exists())

        fqdn = "bar.x.y.z.foo.poo"
        label, the_domain = ensure_label_domain(fqdn)
        self.ctnr.domains.add(the_domain)
        ns = Nameserver.objects.create(
            ctnr=self.ctnr, domain=the_domain, server="asdfasffoo")
        self.assertFalse(prune_tree(the_domain))
        ns.delete()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.poo").exists())
        self.assertFalse(Domain.objects.filter(name="y.z.foo.poo").exists())
        self.assertFalse(Domain.objects.filter(name="z.foo.poo").exists())
        self.assertTrue(Domain.objects.filter(name="foo.poo").exists())
Exemple #53
0
    def test_cleanup_address(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)
        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()

        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"))
Exemple #54
0
    def test_basic_add_remove6(self):
        # Make sure CNAME record block
        c = Domain(name='foo1')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = Domain(name='foo.foo1')
        s, _ = SOA.objects.get_or_create(primary="foo", contact="foo",
                                         comment="foo.foo1")
        f_c.soa = s
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()