def test_name_unique(self): """Test that two SRVs cannot share a name""" srv1 = SRV(label='_foo', domain=self.o_e, target='bar.oregonstate.edu', priority=1, weight=100, port=9002, ctnr=self.ctnr) srv1.save() self.assertRaises( ValidationError, SRV.objects.create, label='_foo', domain=self.o_e, target='bleh.oregonstate.edu', priority=1, weight=100, port=9002)
def do_generic_add(self, data): srv = SRV(**data) srv.__repr__() srv.save() self.assertTrue(srv.details()) self.assertTrue(srv.get_detail_url()) self.assertTrue(srv.get_update_url()) self.assertTrue(srv.get_delete_url()) rsrv = SRV.objects.filter(**data) self.assertTrue(len(rsrv) == 1) return srv
def do_generic_add(self, data ): srv = SRV( **data ) srv.__repr__() srv.save() self.assertTrue(srv.details()) self.assertTrue(srv.get_absolute_url()) self.assertTrue(srv.get_edit_url()) self.assertTrue(srv.get_delete_url()) rsrv = SRV.objects.filter( **data ) self.assertTrue( len(rsrv) == 1 ) return srv
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 migrate_SRV(zone, root_domain, soa, views): for (name, ttl, rdata) in zone.iterate_rdatas('SRV'): target = rdata.target.to_text().strip('.') if target == "": target = "." port = rdata.port weight = rdata.weight prio = rdata.priority name = name.to_text().strip('.') print str(name) + " SRV " + 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) if not SRV.objects.filter(label=label, domain=domain, target=target, port=port, weight=weight, priority=prio).exists(): srv = SRV(label=label, domain=domain, target=target, port=port, weight=weight, priority=prio) srv.full_clean() srv.save() for view in views: srv.views.add(view) srv.save()
def test_name_unique(self): """Test that two SRVs cannot share a name""" srv1 = SRV(label='_foo', domain=self.o_e, target='bar.oregonstate.edu', priority=1, weight=100, port=9002, ctnr=self.ctnr) srv1.save() self.assertRaises(ValidationError, SRV.objects.create, label='_foo', domain=self.o_e, target='bleh.oregonstate.edu', priority=1, weight=100, port=9002)
def test_srv_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) 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() 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): srv = SRV(**data) srv.__repr__() srv.save() self.assertTrue(srv.details()) rsrv = SRV.objects.filter(**data) self.assertTrue(len(rsrv) == 1) return srv
def test_srv_cname_exists(self): label = "testyfoo" data = "wat" dom, _ = Domain.objects.get_or_create(name="cd") dom, _ = Domain.objects.get_or_create(name="what.cd") CNAME.objects.get_or_create(label=label, domain=dom, target=data) rec = SRV(label=label, domain=dom, target="asdf", port=2, priority=2, weight=4) 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 test_srv_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) 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() 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_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()
class Meta: always_return_data = True queryset = SRV.objects.all() fields = SRV.get_api_fields() + ['domain', 'views'] authorization = Authorization() allowed_methods = allowed_methods
name = name.to_text().strip('.') print str(name) + " SRV " + 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)) if not SRV.objects.filter(label=label, domain=domain, target=target, port=port, weight=weight, priority=prio).exists(): srv = SRV(label=label, domain=domain, target=target, port=port, weight=weight, priority=prio) srv.full_clean() srv.save() if views: for view in views: srv.views.add(view) srv.save() set_all_soas(base_domain, base_domain.soa) def ensure_domain(name): parts = list(reversed(name.split('.'))) domain_name = '' for i in range(len(parts)):
def test_srv_update(self): srv = SRV(target="foo", priority=4, weight=4, port=34, ctnr=self.ctnr) self.generic_check(srv, label_prefix="_")
label = '' domain = exists_domain[0] else: label = name.split('.')[0] domain_name = name.split('.')[1:] domain = ensure_domain('.'.join(domain_name)) if not SRV.objects.filter(label=label, domain=domain, target=target, port=port, weight=weight, priority=prio).exists(): srv = SRV(label=label, domain=domain, target=target, port=port, weight=weight, priority=prio) srv.full_clean() srv.save() if views: for view in views: srv.views.add(view) srv.save() set_all_soas(base_domain, base_domain.soa) def ensure_domain(name): parts = list(reversed(name.split('.'))) domain_name = ''