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"))
def do_generic_add(self, data): txt = TXT(**data) txt.__repr__() txt.save() self.assertTrue(txt.details()) self.assertTrue(txt.get_detail_url()) self.assertTrue(txt.get_update_url()) self.assertTrue(txt.get_delete_url()) rtxt = TXT.objects.filter(**data) self.assertTrue(len(rtxt) == 1) return txt
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
def test_domain_records_perms(self): """ Test common domain record perms (cname, mx, txt, srv, ns) """ self.setup_request() perm_table = { 'cyder_admin': ['all'], 'admin': ['all'], 'user': ['all'], 'guest': [cy.ACTION_VIEW], } # Initialize objs into ctnrs. domain = Domain(id=None, name='foo') domain.save() self.ctnr_admin.domains.add(domain) self.ctnr_user.domains.add(domain) self.ctnr_guest.domains.add(domain) self.save_all_ctnrs() domain_records = [] domain_records.append(AddressRecord(domain=domain)) domain_records.append(CNAME(domain=domain)) domain_records.append(MX(domain=domain)) domain_records.append(SRV(domain=domain)) domain_records.append(TXT(domain=domain)) domain_records.append(Nameserver(domain=domain)) for obj in domain_records: self.check_perms_each_user(obj, perm_table)
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()
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"))
def do_generic_add(self, data): txt = TXT(**data) txt.__repr__() txt.save() rtxt = TXT.objects.filter(**data) self.assertTrue(len(rtxt) == 1) return txt
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 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()
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 not TXT.objects.filter(label=label, domain=domain, txt_data=data).exists(): txt = TXT(label=label, domain=domain, txt_data=data) txt.full_clean() txt.save() for view in views: txt.views.add(view) txt.save()
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"))
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()
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)) data = rdata.to_text().strip('"') if not TXT.objects.filter(label=label, domain=domain, txt_data=data).exists(): txt = TXT(label=label, domain=domain, txt_data=data) txt.full_clean() txt.save() if views: for view in views: txt.views.add(view) txt.save() for (name, ttl, rdata) in zone.iterate_rdatas('SSHFP'): name = name.to_text().strip('.') pdb.set_trace() print str(name) + " SSHFP " + str(rdata) for (name, ttl, rdata) in zone.iterate_rdatas('SRV'): target = rdata.target.to_text().strip('.') if target == "":
class Meta: always_return_data = True queryset = TXT.objects.all() fields = TXT.get_api_fields() + ['domain', 'views'] authorization = Authorization() allowed_methods = allowed_methods
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", ctnr=self.ctnr) self.generic_check(txt)
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))