def test_no_update_when_glue(self): """A record shouldn't update it's label or domain when it is a glue record""" label = 'ns99' glue = AddressRecord( label=label, domain = self.o_e, ip_str = '128.193.1.10', ip_type = '4' ) glue.save() server = "%s.%s" % (label, self.o_e) ns = Nameserver(domain = self.o_e, server = server) ns.save() self.assertTrue( ns.glue == glue ) # Shouldn't be able to edit label or domain. glue.label = "ns100" self.assertRaises(ValidationError, glue.save) glue.domain = self.m_o_e self.assertRaises(ValidationError, glue.save) glue = AddressRecord.objects.get(pk=glue.pk) glue.label = "ns101" glue.domain = self.e self.assertRaises(ValidationError, glue.save) # Ip can change. glue = AddressRecord.objects.get(pk=glue.pk) glue.ip_str = "192.192.12.12" glue.save()
def test_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': ['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_delegation(self): name = "boom" dom = Domain( name = name, delegated=True ) dom.save() # Creating objects in the domain should be locked. arec = AddressRecord(label="ns1", domain=dom, ip_str="128.193.99.9", ip_type='4') self.assertRaises(ValidationError, arec.save) ns = Nameserver(domain=dom, server="ns1."+dom.name) self.assertRaises(ValidationError, ns.save) cn = CNAME(label = "999asdf", domain = dom, data = "asdf.asdf") self.assertRaises(ValidationError, cn.full_clean) # Undelegate (unlock) the domain. dom.delegated = False dom.save() # Add glue and ns record. arec.save() ns.save() # Re delegate the domain. dom.delegated = True dom.save() # Creation should still be locked arec1 = AddressRecord(label="ns2", domain=dom, ip_str="128.193.99.9", ip_type='4') self.assertRaises(ValidationError, arec1.save) cn1 = CNAME(label = "1000asdf", domain = dom, data = "asdf.asdf") self.assertRaises(ValidationError, cn1.full_clean) # Editing should be allowed. arec = AddressRecord.objects.get(pk=arec.pk) arec.ip_str = "129.193.88.2" arec.save() # Adding new A records that have the same name as an NS should # be allows. arec1 = AddressRecord(label="ns1", domain=dom, ip_str="128.193.100.10", ip_type='4') arec1.save()
def do_add(self, domain, server): ns = Nameserver( domain = domain, server = server) ns.save() ns.save() self.assertTrue(ns.__repr__()) self.assertTrue(ns.details()) self.assertTrue(ns.get_absolute_url()) self.assertTrue(ns.get_edit_url()) self.assertTrue(ns.get_delete_url()) ret = Nameserver.objects.filter( domain = domain, server = server ) self.assertEqual( len(ret), 1 ) return ns