def do_generic_add(self, data):
     txt = TXT(**data)
     txt.__repr__()
     txt.save()
     self.assertTrue(txt.details())
     self.assertTrue(txt.get_absolute_url())
     self.assertTrue(txt.get_edit_url())
     self.assertTrue(txt.get_delete_url())
     rtxt = TXT.objects.filter(**data)
     self.assertTrue(len(rtxt) == 1)
     return txt
Beispiel #2
0
def migrate_TXT(zone, root_domain, soa, views):
    for (name, ttl, rdata) in zone.iterate_rdatas('TXT'):
        name = name.to_text().strip('.')
        print str(name) + " TXT " + str(rdata)
        exists_domain = Domain.objects.filter(name=name)
        if exists_domain:
            label = ''
            domain = exists_domain[0]
        else:
            label = name.split('.')[0]
            domain_name = name.split('.')[1:]
            domain = ensure_domain('.'.join(domain_name), force=True)
        data = rdata.to_text().strip('"')

        if TXT.objects.filter(label=label, domain=domain,
                              txt_data=data).exists():
            txt = TXT.objects.get(label=label, domain=domain, txt_data=data)
        else:
            txt = TXT(label=label,
                      domain=domain,
                      txt_data=data,
                      description=rdata.comment,
                      ttl=ttl)
            txt.full_clean()
            txt.save()

        for view in views:
            txt.views.add(view)
            txt.save()
Beispiel #3
0
def migrate_TXT(zone, root_domain, soa, views):
    for (name, ttl, rdata) in zone.iterate_rdatas('TXT'):
        name = name.to_text().strip('.')
        print str(name) + " TXT " + str(rdata)
        exists_domain = Domain.objects.filter(name=name)
        if exists_domain:
            label = ''
            domain = exists_domain[0]
        else:
            label = name.split('.')[0]
            domain_name = name.split('.')[1:]
            domain = ensure_domain('.'.join(domain_name), force=True)
        data = rdata.to_text().strip('"')

        if TXT.objects.filter(label=label, domain=domain,
                txt_data=data).exists():
            txt = TXT.objects.get(
                label=label, domain=domain, txt_data=data
            )
        else:
            txt = TXT(
                label=label, domain=domain, txt_data=data,
                description=rdata.comment, ttl=ttl
            )
            txt.full_clean()
            txt.save()

        for view in views:
            txt.views.add(view)
            txt.save()
Beispiel #4
0
    def test_cleanup_txt(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"))

        self.assertFalse(self.f_c.purgeable)
        fqdn = "bar.x.y.z.foo.poo"
        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()

        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"))
Beispiel #5
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
        f_c = create_fake_zone("foo.foo", suffix="")
        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"))
Beispiel #6
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()
    def test_txt_cname_exists(self):
        label = "testyfoo"
        data = "wat"
        dom, _ = Domain.objects.get_or_create(name="cd")
        dom, _ = Domain.objects.get_or_create(name="what.cd")

        cn, _ = CNAME.objects.get_or_create(
            label=label, domain=dom, target=data)
        cn.full_clean()
        cn.save()

        rec = TXT(label=label, domain=dom, txt_data="asdf1")

        self.assertRaises(ValidationError, rec.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_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
        f_c = create_fake_zone("foo.foo", suffix="")
        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"))
Beispiel #10
0
    def test_basic_add_remove4(self):
        # Move a record down the tree testing prune's ability to not delete
        # stuff.
        f_c = create_fake_zone("foo.goo", suffix="")
        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))
 def test_txt_update(self):
     txt = TXT(txt_data="Nthing")
     self.generic_check(txt)
    def test_basic_add_remove4(self):
        # Move a record down the tree testing prune's ability to not delete
        # stuff.
        f_c = create_fake_zone("foo.goo", suffix="")
        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))
 class Meta:
     always_return_data = True
     queryset = TXT.objects.all()
     fields = TXT.get_api_fields() + ['views']
     authorization = Authorization()
     allowed_methods = allowed_methods