def test_update_AAAA_record(self): boot_strap_ipv6_reverse_domain("8.6.2.0") osu_block = "8620:105:F000:" rec0 = AddressRecord(label='', domain=self.z_o_e, ip_str=osu_block + ":1", ip_type='6') rec1 = AddressRecord(label='foo', domain=self.z_o_e, ip_str=osu_block + ":1", ip_type='6') rec2 = AddressRecord(label='bar', domain=self.z_o_e, ip_str=osu_block + ":1", ip_type='6') self.do_update_AAAA_record(rec0, "whoooooasfjsp1", osu_block + "0:0:123:321::") self.do_update_AAAA_record(rec1, "wasfasfsafdhooooop1", osu_block + "0:0:123:321::") self.do_update_AAAA_record(rec2, "whoooooasfdisafsap1", osu_block + "0:24:123:322:1") self.do_update_AAAA_record(rec0, "whooooop1", osu_block + "0:aaa::1") self.do_update_AAAA_record(rec0, "wasflasksdfhooooop1", osu_block + "0:dead::") self.do_update_AAAA_record(rec1, "whooooosf13fp1", osu_block + "0:0::") self.do_update_AAAA_record(rec1, "whooooodfijasf1", osu_block + "0:1:23::") self.do_update_AAAA_record(rec2, "lliasdflsafwhooooop1", osu_block + ":") self.do_update_AAAA_record(rec1, "whooooopsjafasf1", osu_block + "0::") self.do_update_AAAA_record(rec1, "", osu_block + "0:0:123:321::")
def test_private_view_case_3_addr(self): a = AddressRecord(label="asf3", domain=self.f_o, ip_str="10.0.0.1", ip_type="4") a.clean() a.save() a.views.add(self.private) a.save() # Object has to exist before views can be assigned. a.views.add(self.public) self.assertFalse(a.views.filter(name="public")) a = AddressRecord(label="asf3", domain=self.f_o, ip_str="172.30.0.1", ip_type="4") a.clean() a.save() a.views.add(self.private) a.save() # Object has to exist before views can be assigned. a.views.add(self.public) self.assertFalse(a.views.filter(name="public")) a = AddressRecord(label="asf3", domain=self.f_o, ip_str="192.168.0.1", ip_type="4") a.clean() a.save() a.views.add(self.private) a.save() # Object has to exist before views can be assigned. a.views.add(self.public) self.assertFalse(a.views.filter(name="public"))
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, target="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, target="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 test_no_type(self): data = {'label': 'uuu', 'domain': self.f_o_e, 'ip': '128.193.4.1'} rec = AddressRecord(label=data['label'], domain=data['domain'], ip_str=data['ip'], ip_type='x') self.assertRaises(ValidationError, rec.save) data = {'label': 'uuu', 'domain': self.f_o_e, 'ip': '128.193.4.1'} rec = AddressRecord(label=data['label'], domain=data['domain'], ip_str=data['ip']) self.assertRaises(ValidationError, rec.save)
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_bad_nameserver_soa_state_case_3_0(self): # This is Case 3 root_domain = create_fake_zone("asdf30") for ns in root_domain.nameserver_set.all(): ns.delete() soa = ns.domain.soa ns.domain.soa = None root_domain.soa = None # Shit's getting cached ns.domain.save() soa.delete() # At his point we should have a domain pointed at no SOA record with no # records attached to it. It also has no child domains. # Add a record to the domain. a = AddressRecord(label='', domain=root_domain, ip_type="6", ip_str="1::") a.save() s = SOA(primary="asdf.asdf", contact="asdf.asdf", description="asdf") s.save() root_domain.soa = s self.assertRaises(ValidationError, root_domain.save)
def test_integration5_ip(self): root_domain = create_fake_zone("wee5.wee.mozilla.com", "") create_fake_zone("10.in-addr.arpa", "") res, error = self.search("10.in-addr.arpa OR " "wee5.wee.mozilla.com") self.assertFalse(error) self.assertEqual(len(res['SOA']), 2) self.assertEqual(len(res['NS']), 2) self.assertEqual(len(res['DOMAIN']), 2) ptr = PTR(name="host1.wee2.wee.mozilla.com", ip_str="10.0.0.1", ip_type="4") ptr.save() addr = AddressRecord(label="host1", domain=root_domain, ip_str="10.0.0.1", ip_type="4") addr.save() res, error = self.search(ptr.ip_str) self.assertFalse(error) self.assertEqual(len(res['PTR']), 1) self.assertEqual(len(res['A']), 1) res, error = self.search("10.0.0.2") self.assertFalse(error) self.assertEqual(len(res['PTR']), 0) self.assertEqual(len(res['A']), 0)
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_add_A_address_glob_records(self): # Test the glob form: *.foo.com A 10.0.0.1 rec = AddressRecord(label='', domain=self.o_e, ip_str="128.193.0.1", ip_type='4') rec.clean() rec.save() self.assertEqual(rec.__str__(), "oregonstate.edu A 128.193.0.1") data = {'label': '*', 'domain': self.f_o_e, 'ip': "128.193.0.10"} self.do_add_record(data) data = { 'label': '*foob1ar', 'domain': self.f_o_e, 'ip': "128.193.0.10" } self.do_add_record(data) data = {'label': '*foob1ar', 'domain': self.o_e, 'ip': "128.193.0.5"} self.do_add_record(data) data = {'label': '*foo2', 'domain': self.f_o_e, 'ip': "128.193.0.7"} self.do_add_record(data) data = {'label': '*foo2', 'domain': self.o_e, 'ip': "128.193.0.2"} self.do_add_record(data) data = {'label': '*ba-r', 'domain': self.f_o_e, 'ip': "128.193.0.9"} self.do_add_record(data) data = {'label': '*ba-r', 'domain': self.o_e, 'ip': "128.193.0.4"} self.do_add_record(data)
def do_add_record6(self, data): rec = AddressRecord(label=data['label'], domain=data['domain'], ip_str=data['ip'], ip_type='6') rec.save() self.assertTrue(rec.__repr__()) self.assertTrue(rec.details())
def do_add_a(self, label, domain, ip_str, ip_type='4'): a = AddressRecord(label=label, domain=domain, ip_str=ip_str, ip_type=ip_type) a.clean() a.save() return a
def test_private_view_case_1_addr(self): a = AddressRecord(label="asf", domain=self.f_o, ip_str="10.0.0.1", ip_type="4") a.clean() a.save() # Object has to exist before views can be assigned. a.views.add(self.private) a.save()
def test_address_record_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 = AddressRecord(label=label, domain=dom, ip_str="128.193.1.1") self.assertRaises(ValidationError, rec.save)
def test_update_A_record(self): rec0 = AddressRecord(label='', domain=self.m_o_e, ip_str="128.193.0.1", ip_type='4') rec0.save() rec1 = AddressRecord(label='foo', domain=self.m_o_e, ip_str="128.193.0.1", ip_type='4') rec1.save() rec2 = AddressRecord(label='bar', domain=self.m_o_e, ip_str="128.193.0.1", ip_type='4') rec2.save() rec3 = AddressRecord( label= '0123456780123456780123456780123456780123456789999901234567891', domain=self.m_o_e, ip_str="128.193.0.1", ip_type='4') rec3.save() self.do_update_A_record(rec0, "whooooop1", "128.193.23.1") self.do_update_A_record(rec1, "whoooasfdasdflasdfjoop3", "128.193.23.2") self.do_update_A_record(rec2, "whsdflhjsafdohaosdfhsadooooop1", "128.193.23.4") self.do_update_A_record(rec3, "wasdflsadhfaoshfuoiwehfjsdkfavbhooooop1", "128.193.23.3") self.do_update_A_record(rec0, "liaslfdjsa8df09823hsdljf-whooooop1", "128.193.25.17") self.do_update_A_record(rec1, "w", "128.193.29.83") self.do_update_A_record(rec0, '', "128.193.23.1") self.do_update_A_record(rec1, "whoooasfdasdflasdfjoop3", None)
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)
def test_update_glue_to_no_glue(self): glue = AddressRecord(label='ns3', domain=self.r, ip_str='128.193.1.10', ip_type='4') glue.save() data = {'domain': self.r, 'server': 'ns3.ru'} ns = self.do_add(**data) self.assertTrue(ns.glue) ns.server = "ns4.wee" ns.save() self.assertTrue(ns.glue is None)
def test_delegation(self): boom = create_zone('boom') bleh = Domain.objects.create(name='bleh.boom', delegated=True) self.ctnr.domains.add(bleh) # Creating objects in the domain should be disallowed. arec = AddressRecord( label="ns1", ctnr=self.ctnr, domain=bleh, ip_str="128.193.99.9", ip_type='4') self.assertRaises(ValidationError, arec.save) ns = Nameserver(domain=bleh, server="ns1." + bleh.name) self.assertRaises(ValidationError, ns.save) cn = CNAME(label="999asdf", ctnr=self.ctnr, domain=bleh, target="asdf.asdf") self.assertRaises(ValidationError, cn.save) # Undelegate the domain. bleh.delegated = False bleh.save() # Add glue and NS record. arec.save() ns.save() # Re-delegate the domain. bleh.delegated = True bleh.save() # Creation should still be disallowed. self.assertRaises( ValidationError, AddressRecord.objects.create, label="ns2", ctnr=self.ctnr, domain=bleh, ip_str="128.193.99.9", ip_type='4') self.assertRaises( ValidationError, CNAME.objects.create, label="1000asdf", ctnr=self.ctnr, domain=bleh, target="asdf.asdf") # 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 allowed. AddressRecord.objects.create( label="ns1", ctnr=self.ctnr, domain=bleh, ip_str="128.193.100.10", ip_type='4')
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 testtest_add_ns_in_domain(self): # Use an A record as a glue record. glue = AddressRecord(label='ns2', domain=self.r, ip_str='128.193.1.10', ip_type='4') glue.clean() glue.save() data = {'domain': self.r, 'server': 'ns2.ru'} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.server, ns.glue.fqdn) self.assertRaises(ValidationError, glue.delete) glue = AddressRecord(label='ns3', domain=self.f_r, ip_str='128.193.1.10', ip_type='4') glue.save() data = {'domain': self.f_r, 'server': 'ns3.foo.ru'} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.server, ns.glue.fqdn)
def test_update_invalid_ip_AAAA_record(self): osu_block = "7620:105:F000:" boot_strap_ipv6_reverse_domain("7.6.2.0") rec0 = AddressRecord(label='foo', domain=self.z_o_e, ip_str=osu_block + ":1", ip_type='6') self.assertRaises( ValidationError, self.do_update_AAAA_record, **{ 'record': rec0, 'new_name': None, 'new_ip': 71134 }) self.assertRaises( ValidationError, self.do_update_AAAA_record, **{ 'record': rec0, 'new_name': None, 'new_ip': osu_block + ":::" }) self.assertRaises( ValidationError, self.do_update_AAAA_record, **{ 'record': rec0, 'new_name': "%asdfsaf", 'new_ip': osu_block }) self.assertRaises( ValidationError, self.do_update_AAAA_record, **{ 'record': rec0, 'new_name': "sdfsa", 'new_ip': 1239812472934623847 }) self.assertRaises( ValidationError, self.do_update_AAAA_record, **{ 'record': rec0, 'new_name': None, 'new_ip': "128.193.1.1" }) self.assertRaises( ValidationError, self.do_update_AAAA_record, **{ 'record': rec0, 'new_name': "%asdfsaf", 'new_ip': osu_block + ":1" }) self.assertRaises( ValidationError, self.do_update_AAAA_record, **{ 'record': rec0, 'new_name': " sdfsa ", 'new_ip': None })
def test_delete_ns(self): glue = AddressRecord(label='ns4', domain=self.f_r, ip_str='128.196.1.10', ip_type='4') glue.save() data = {'domain': self.f_r, 'server': 'ns4.foo.ru'} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.server, ns.glue.fqdn) ns.delete() nsret = Nameserver.objects.filter(server='ns2.foo.ru', domain=self.f_r) self.assertFalse(nsret)
def do_remove_AAAA_record(self, aname, domain, ip): aret = AddressRecord(label=aname, domain=domain, ip_str=ip, ip_type='6') aret.save() self.assertTrue(aret) aret.delete() nret = AddressRecord.objects.filter(label=aname, domain=domain, ip_str=ip) self.assertFalse(nret)
def test_disallow_name_update_of_glue_A(self): # Glue records should not be allowed to change their name. glue = AddressRecord(label='ns39', domain=self.f_r, ip_str='128.193.1.77', ip_type='4') glue.clean() glue.save() data = {'domain': self.f_r, 'server': 'ns39.foo.ru'} ns = self.do_add(**data) self.assertTrue(ns.glue) self.assertEqual(ns.glue, glue) glue.label = "ns22" self.assertRaises(ValidationError, glue.clean)
def test_delete_with_cname_pointing_to_a(self): label = 'foo100' a = AddressRecord(label=label, domain=self.o_e, ip_str='128.193.1.10', ip_type='4') a.clean() a.save() cn = CNAME(label="foomom", domain=self.o_e, target=label + "." + self.o_e.name) cn.clean() cn.save() self.assertRaises(ValidationError, a.delete) a.delete(check_cname=False)
def test_bad_nameserver_soa_state_case_2_0(self): # This is Case 2 root_domain = create_fake_zone("asdf20") self.assertEqual(root_domain.nameserver_set.count(), 1) ns = root_domain.nameserver_set.all()[0] # At his point we should have a domain at the root of a zone with one # ns record associated to the domain. a = AddressRecord(label='', domain=root_domain, ip_type="6", ip_str="1::") a.save() self.assertRaises(ValidationError, ns.delete)
def test_existing_record_new_domain(self): name = "bo" b_dom, _ = Domain.objects.get_or_create(name=name, delegated=False) name = "to.bo" t_dom, _ = Domain.objects.get_or_create(name=name, delegated=False) arec1 = AddressRecord(label="no", domain=t_dom, ip_str="128.193.99.9", ip_type='4') arec1.save() name = "no.to.bo" n_dom = Domain(name=name, delegated=False) self.assertRaises(ValidationError, n_dom.save)
def clean(self, *args, **kwargs): self.glue = None if self.instance.pk is None: domain = self.cleaned_data['domain'] glue_ip_str, glue_ctnr = (self.cleaned_data['glue_ip_str'], self.cleaned_data['glue_ctnr']) server = self.cleaned_data['server'].strip('.') if '.' in server: if server.lower() != domain.name.lower(): glue_label, glue_domain = tuple(server.split('.', 1)) glue_domain = glue_domain.strip('.').lower() else: glue_label, glue_domain = "", server.lower() else: raise ValidationError( "Please provide a fully qualified server name.") if domain.delegated: if glue_domain and glue_domain != domain.name.lower(): if glue_ip_str or glue_ctnr: raise ValidationError( "This record does not need glue, so " "please leave the glue fields blank.") else: if not (glue_ip_str and glue_ctnr): raise ValidationError( "This zone is delegated, so " "please provide information for glue.") gluekwargs = { 'domain': domain, 'label': glue_label, 'ip_str': glue_ip_str, 'ctnr': glue_ctnr } try: self.glue = AddressRecord.objects.get(**gluekwargs) except AddressRecord.DoesNotExist: self.glue = AddressRecord(**gluekwargs) self.glue.set_is_glue() self.glue.save() for v in View.objects.all(): self.glue.views.add(v) elif not domain.delegated and (glue_ip_str or glue_ctnr): raise ValidationError("This zone is not delegated, so please " "leave the glue fields blank.") cleaned_data = super(NameserverForm, self).clean(*args, **kwargs) return cleaned_data
def test1_bad_add_for_a_ptr(self): # Intr exists, then try ptr and A mac = "11:22:33:44:55:6e" label = "9988fooddfdf" domain = self.c ip_str = "111::" + mac kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} ip_type = '6' i = self.do_add(**kwargs) i.clean() i.save() a = AddressRecord(label=label, domain=domain, ip_str=ip_str, ip_type=ip_type) self.assertRaises(ValidationError, a.clean) ptr = PTR(ip_str=ip_str, ip_type=ip_type, name=i.fqdn) self.assertRaises(ValidationError, ptr.clean)
def test2_bad_add_for_a_ptr(self): # PTR and A exist, then try add intr mac = "11:22:33:44:55:66" label = "9988fdfood" domain = self.c ip_str = "1112::" + mac kwargs = {'mac': mac, 'label': label, 'domain': domain, 'ip_str': ip_str} ip_type = '6' a = AddressRecord(label=label, domain=domain, ip_str=ip_str, ip_type=ip_type) a.clean() a.save() ptr = PTR(ip_str=ip_str, ip_type=ip_type, name=a.fqdn) ptr.clean() ptr.save() self.assertRaises(ValidationError, self.do_add, **kwargs)
def test_invalid_create(self): glue = AddressRecord(label='ns2', domain=self.r, ip_str='128.193.1.10', ip_type='4') glue.save() data = {'domain': self.r, 'server': 'ns2 .ru'} self.assertRaises(ValidationError, self.do_add, **data) data = {'domain': self.r, 'server': 'ns2$.ru'} self.assertRaises(ValidationError, self.do_add, **data) data = {'domain': self.r, 'server': 'ns2..ru'} self.assertRaises(ValidationError, self.do_add, **data) data = {'domain': self.r, 'server': 'ns2.ru '} self.assertRaises(ValidationError, self.do_add, **data) data = {'domain': self.r, 'server': ''} self.assertRaises(ValidationError, self.do_add, **data)