Beispiel #1
0
    def do_generic_add(self, ip_str, fqdn, ip_type, domain=None):
        ret = PTR(name=fqdn, ip_str=ip_str, ip_type=ip_type)
        ret.full_clean()
        ret.save()

        self.assertTrue(ret.details())
        self.assertTrue(ret.get_absolute_url())
        self.assertTrue(ret.get_edit_url())
        self.assertTrue(ret.get_delete_url())

        ip = Ip(ip_str=ip_str, ip_type=ip_type)
        ip.clean_ip()
        ptr = PTR.objects.filter(name=fqdn,
                                 ip_upper=ip.ip_upper,
                                 ip_lower=ip.ip_lower)
        ptr.__repr__()
        self.assertTrue(ptr)
        ip_str = ip_str.lower()
        self.assertEqual(ptr[0].ip_str, ip_str)
        if domain:
            if ptr[0].name == "":
                self.assertEqual(fqdn, domain.name)
            else:
                self.assertEqual(fqdn, ptr[0].name + "." + domain.name)
        else:
            self.assertEqual(fqdn, ptr[0].name)
        return ret
    def test1(self):
        ip_start = "10.0.0.10"
        ip_end = "10.0.0.19"

        ptr = PTR(name="foo.mz", ip_str="10.0.0.15", ip_type='4')
        ptr.full_clean()
        ptr.save()

        a = AddressRecord(
            label="foo", domain=self.domain, ip_str="10.0.0.16", ip_type='4')
        a.full_clean()
        a.save()

        istart, iend, ipf_q = start_end_filter(ip_start, ip_end, '4')
        addrs = list(AddressRecord.objects.filter(ipf_q).
                     order_by('ip_lower').order_by('ip_upper'))
        ptrs = list(PTR.objects.filter(ipf_q).
                    order_by('ip_lower').order_by('ip_upper'))
        intrs = list(StaticInterface.objects.filter(ipf_q).
                     order_by('ip_lower').order_by('ip_upper'))
        self.assertEqual(a.pk, addrs[0].pk)
        self.assertEqual(ptr.pk, ptrs[0].pk)
        self.assertFalse(intrs)

        range_details = range_usage(ip_start, ip_end, '4')
        self.assertEqual(8, range_details['unused'])
        self.assertEqual(2, range_details['used'])
        self.assertEqual([(int(istart), int(istart) + 4),
                          (int(istart) + 7, int(istart) + 9)],
                         range_details['free_ranges'])
    def test_bad_nameserver_soa_state_case_3_2(self):
        # This is Case 3 ... with ptrs
        root_domain = create_fake_zone("32.in-addr.arpa", suffix="")
        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.

        ptr = PTR(name="asdf", ip_str="32.1.1.1", ip_type="4")
        ptr.save()

        s = SOA(primary="asdf.asdf", contact="asdf.asdf", description="asdf")
        s.save()
        root_domain.soa = s

        self.assertRaises(ValidationError, root_domain.save)
Beispiel #4
0
    def test2(self):
        ip_start = "10.0.1.0"
        ip_end = "10.0.1.99"
        ptr = PTR(name="foo.mz", ip_str="10.0.1.3", ip_type="4")
        ptr.full_clean()
        ptr.save()

        a = AddressRecord(label="foo", domain=self.domain, ip_str="10.0.1.3", ip_type="4")
        a.full_clean()
        a.save()

        s = create_fake_host(hostname="foo.mozilla.com")
        s.save()
        sreg = StaticReg.objects.create(label="foo", domain=self.domain, ip_str="10.0.1.4", ip_type="4", system=s)

        istart, iend, ipf_q = start_end_filter(ip_start, ip_end, "4")
        addrs = list(AddressRecord.objects.filter(ipf_q).order_by("ip_lower").order_by("ip_upper"))
        ptrs = list(PTR.objects.filter(ipf_q).order_by("ip_lower").order_by("ip_upper"))
        sregs = list(StaticReg.objects.filter(ipf_q).order_by("ip_lower").order_by("ip_upper"))
        self.assertEqual(a.pk, addrs[0].pk)
        self.assertEqual(ptr.pk, ptrs[0].pk)
        self.assertEqual(sreg.pk, sregs[0].pk)

        range_details = range_usage(ip_start, ip_end, "4")
        self.assertEqual(98, range_details["unused"])
        self.assertEqual(2, range_details["used"])
        self.assertEqual(
            [(int(istart) + 0, int(istart) + 2), (int(istart) + 5, int(istart) + 99)], range_details["free_ranges"]
        )
Beispiel #5
0
    def test_integration4_ip(self):
        create_fake_zone("wee3.wee.mozilla.com", "")
        create_fake_zone("1.2.ip6.arpa", "")
        res, error = compile_to_django("1.2.ip6.arpa")
        self.assertFalse(error)
        self.assertEqual(len(res['SOA']), 1)
        self.assertEqual(len(res['NS']), 1)
        self.assertEqual(len(res['DOMAIN']), 1)

        ptr = PTR(name="host1.wee2.wee.mozilla.com", ip_str="2111:0::",
                  ip_type="6")
        ptr.save()

        res, error = compile_to_django(ptr.ip_str)
        self.assertFalse(error)
        self.assertEqual(len(res['PTR']), 1)
        self.assertEqual(len(res['A']), 0)

        res, error = compile_to_django("2111:0:0::")
        self.assertFalse(error)
        self.assertEqual(len(res['PTR']), 0)
        self.assertEqual(len(res['A']), 0)

        res, error = compile_to_django("ip=:2111:0:0::")
        self.assertFalse(error)
        self.assertEqual(len(res['PTR']), 1)
        self.assertEqual(len(res['A']), 0)

        res, error = compile_to_django("ip=:2111:1:0::")
        self.assertFalse(error)
        self.assertEqual(len(res['PTR']), 0)
        self.assertEqual(len(res['A']), 0)
Beispiel #6
0
    def test_integration5_ip(self):
        root_domain = create_fake_zone("wee5.wee.mozilla.com", "")
        create_fake_zone("10.in-addr.arpa", "")
        res, error = compile_to_django("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 = compile_to_django(ptr.ip_str)
        self.assertFalse(error)
        self.assertEqual(len(res['PTR']), 1)
        self.assertEqual(len(res['A']), 1)

        res, error = compile_to_django("10.0.0.2")
        self.assertFalse(error)
        self.assertEqual(len(res['PTR']), 0)
        self.assertEqual(len(res['A']), 0)

        res, error = compile_to_django("ip=:10.0.0.1")
        self.assertFalse(error)
        self.assertEqual(len(res['PTR']), 1)
        self.assertEqual(len(res['A']), 1)
Beispiel #7
0
    def do_generic_add(self, ip_str, fqdn, ip_type, domain=None):
        ret = PTR(name=fqdn, ip_str=ip_str, ip_type=ip_type)
        ret.full_clean()
        ret.save()

        self.assertTrue(ret.details())
        self.assertTrue(ret.get_absolute_url())
        self.assertTrue(ret.get_edit_url())
        self.assertTrue(ret.get_delete_url())

        ip = Ip(ip_str=ip_str, ip_type=ip_type)
        ip.clean_ip()
        ptr = PTR.objects.filter(
            name=fqdn, ip_upper=ip.ip_upper, ip_lower=ip.ip_lower)
        ptr.__repr__()
        self.assertTrue(ptr)
        ip_str = ip_str.lower()
        self.assertEqual(ptr[0].ip_str, ip_str)
        if domain:
            if ptr[0].name == "":
                self.assertEqual(fqdn, domain.name)
            else:
                self.assertEqual(fqdn, ptr[0].name + "." + domain.name)
        else:
            self.assertEqual(fqdn, ptr[0].name)
        return ret
    def test_bad_nameserver_soa_state_case_2_2(self):
        # This is Case 2 ... with ptrs
        root_domain = create_fake_zone("22.in-addr.arpa", suffix="")
        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.

        ptr = PTR(name="asdf", ip_str="22.1.1.1", ip_type="4")
        ptr.save()

        self.assertRaises(ValidationError, ns.delete)
Beispiel #9
0
 def test2_bad_add_for_a_ptr(self):
     # PTR and A exist, then try add sreg
     label = "9988fdfood"
     domain = self.c
     ip_str = "1112::11:22:33:44:55:66"
     kwargs = {'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_integration2(self):
        root_domain = create_fake_zone("wee2.wee.mozilla.com", "")
        res, error = compile_to_django("wee2.wee.mozilla.com")
        self.assertFalse(error)
        self.assertEqual(len(res['SOA']), 1)
        self.assertEqual(len(res['NS']), 1)
        self.assertEqual(len(res['DOMAIN']), 1)

        create_fake_zone("1.1.ip6.arpa", "")
        res, error = compile_to_django("1.1.ip6.arpa")
        self.assertFalse(error)
        self.assertEqual(len(res['SOA']), 1)
        self.assertEqual(len(res['NS']), 1)
        self.assertEqual(len(res['DOMAIN']), 1)

        ptr = PTR(name="host1.wee2.wee.mozilla.com",
                  ip_str="1111::",
                  ip_type="6")
        ptr.save()
        addr = AddressRecord(label="host1",
                             domain=root_domain,
                             ip_str="11::",
                             ip_type="6")
        addr.save()
        res, error = compile_to_django("host1.wee2.wee.mozilla.com")
        self.assertFalse(error)
        self.assertEqual(len(res['A']), 1)
        self.assertEqual(len(res['PTR']), 1)

        res, error = compile_to_django("host1.wee2.wee.mozilla.com type=:A")
        self.assertFalse(error)
        self.assertEqual(len(res['A']), 1)
        self.assertEqual(len(res['PTR']), 0)

        res, error = compile_to_django("host1.wee2.wee.mozilla.com type=:PTR")
        self.assertFalse(error)
        self.assertEqual(len(res['A']), 0)
        self.assertEqual(len(res['PTR']), 1)

        res, error = compile_to_django("host1.wee2.wee.mozilla.com type=:A "
                                       "type=:PTR")
        self.assertFalse(error)
        self.assertEqual(len(res['A']), 0)
        self.assertEqual(len(res['PTR']), 0)
 def test_private_view_case_1_ptr(self):
     ptr = PTR(name="asf", ip_str="10.0.0.1",
               ip_type="4")
     ptr.clean()
     ptr.save()
     # Object has to exist before views can be assigned.
     ptr.views.add(self.private)
     ptr.save()
    def test_bad_nameserver_soa_state_case_2_3(self):
        # This is Case 2 ... with ptrs
        root_domain = create_fake_zone("10.23.in-addr.arpa", suffix="")
        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.

        # Let's create a child domain and add a record there, then try to
        # delete the NS record
        cdomain = Domain(name="test." + root_domain.name)
        cdomain.soa = root_domain.soa
        cdomain.save()

        ptr = PTR(name="asdf", ip_str="23.10.1.1", ip_type="4")
        ptr.save()

        self.assertRaises(ValidationError, ns.delete)
def migrate_PTR(zone, root_domain, soa, views):
    for (name, ttl, rdata) in zone.iterate_rdatas('PTR'):
        fqdn = rdata.target.to_text().strip('.')
        if fqdn.find('unused') != -1:
            print "Skipping "+name.to_text()+" "+fqdn
            continue

        # 4.3.2.1.IN-ADDR.ARPA. --> 1.2.3.4
        name = name.to_text().lower().strip('.')
        if name.endswith('.in-addr.arpa'):
            ip_type = '4'
            ip_str = name.replace('.in-addr.arpa','')
            ip_str = '.'.join(list(reversed(ip_str.split('.'))))
            ip_upper, ip_lower = 0, ipaddr.IPv4Address(ip_str)
        elif name.endswith('.ip6.arpa'):
            ip_type = '6'
            ip_str = name.replace('.ip6.arpa','')
            chunks = [''.join(ip_str.split('.')[i:i+4]) for i in xrange(0, len(ip_str.split('.')), 4)]
            ip_str = ':'.join(chunks)[::-1]
            ip_upper, ip_lower = ipv6_to_longs(ip_str)
        else:
            print "We so f****d. Lol"
            pdb.set_trace()
            continue

        if ip_str == '10.2.171.IN':
            print "Skipping "+ip_str+" "+fqdn
            continue

        print str(name) + " PTR " + str(fqdn)
        ptr = PTR.objects.filter(name = fqdn, ip_upper=ip_upper,
                ip_lower=ip_lower, ip_type=ip_type)
        if ptr:
            ptr = ptr[0]
        else:
            ptr = PTR(name = fqdn, ip_str = ip_str, ip_type=ip_type)
            ptr.full_clean()
            ptr.save()

        if views:
            for view in views:
                ptr.views.add(view)
Beispiel #14
0
    def test0(self):
        ip_start = "10.0.0.0"
        ip_end = "10.0.0.9"
        ptr = PTR(name="foo.mz", ip_str="10.0.0.5", ip_type="4")
        ptr.full_clean()
        ptr.save()
        istart, iend, ipf_q = start_end_filter(ip_start, ip_end, "4")
        addrs = list(AddressRecord.objects.filter(ipf_q).order_by("ip_lower").order_by("ip_upper"))
        ptrs = list(PTR.objects.filter(ipf_q).order_by("ip_lower").order_by("ip_upper"))
        sregs = list(StaticReg.objects.filter(ipf_q).order_by("ip_lower").order_by("ip_upper"))
        self.assertFalse(addrs)
        self.assertEqual(ptr.pk, ptrs[0].pk)
        self.assertFalse(sregs)

        range_details = range_usage(ip_start, ip_end, "4")
        self.assertEqual(9, range_details["unused"])
        self.assertEqual(1, range_details["used"])
        self.assertEqual(
            [(int(istart) + 0, int(istart) + 4), (int(istart) + 6, int(istart) + 9)], range_details["free_ranges"]
        )
Beispiel #15
0
    def do_generic_remove(self, ip, fqdn, ip_type):
        ptr = PTR(ip_str=ip, name=fqdn, ip_type=ip_type)
        ptr.full_clean()
        ptr.save()

        ptr.delete()

        ip = Ip(ip_str=ip, ip_type=ip_type)
        ip.clean_ip()
        ptr = PTR.objects.filter(name=fqdn,
                                 ip_upper=ip.ip_upper,
                                 ip_lower=ip.ip_lower)
        self.assertFalse(ptr)
Beispiel #16
0
def migrate_PTR(zone, root_domain, soa, views):
    for (name, ttl, rdata) in zone.iterate_rdatas('PTR'):
        fqdn = rdata.target.to_text().strip('.')
        if fqdn.find('unused') != -1:
            print "Skipping " + name.to_text() + " " + fqdn
            continue

        # 4.3.2.1.IN-ADDR.ARPA. --> 1.2.3.4
        name = name.to_text().lower().strip('.')
        if name.endswith('.in-addr.arpa'):
            ip_type = '4'
            ip_str = name.replace('.in-addr.arpa', '')
            ip_str = '.'.join(list(reversed(ip_str.split('.'))))
            ip_upper, ip_lower = 0, ipaddr.IPv4Address(ip_str)
        elif name.endswith('.ip6.arpa'):
            ip_type = '6'
            ip_str = name.replace('.ip6.arpa', '')
            chunks = [
                ''.join(ip_str.split('.')[i:i + 4])
                for i in xrange(0, len(ip_str.split('.')), 4)
            ]
            ip_str = ':'.join(chunks)[::-1]
            ip_upper, ip_lower = ipv6_to_longs(ip_str)
        else:
            print "We so f****d. Lol"
            pdb.set_trace()
            continue

        if ip_str == '10.2.171.IN':
            print "Skipping " + ip_str + " " + fqdn
            continue

        print str(name) + " PTR " + str(fqdn)
        ptr = PTR.objects.filter(name=fqdn,
                                 ip_upper=ip_upper,
                                 ip_lower=ip_lower,
                                 ip_type=ip_type)
        if ptr:
            ptr = ptr[0]
        else:
            ptr = PTR(name=fqdn,
                      ip_str=ip_str,
                      ip_type=ip_type,
                      description=rdata.comment)
            ptr.full_clean()
            ptr.save()

        if views:
            for view in views:
                ptr.views.add(view)
            ptr.save()
Beispiel #17
0
    def test_integration2(self):
        root_domain = create_fake_zone("wee2.wee.mozilla.com", "")
        res, error = compile_to_django("wee2.wee.mozilla.com")
        self.assertFalse(error)
        self.assertEqual(len(res['SOA']), 1)
        self.assertEqual(len(res['NS']), 1)
        self.assertEqual(len(res['DOMAIN']), 1)

        create_fake_zone("1.1.ip6.arpa", "")
        res, error = compile_to_django("1.1.ip6.arpa")
        self.assertFalse(error)
        self.assertEqual(len(res['SOA']), 1)
        self.assertEqual(len(res['NS']), 1)
        self.assertEqual(len(res['DOMAIN']), 1)

        ptr = PTR(name="host1.wee2.wee.mozilla.com", ip_str="1111::",
                  ip_type="6")
        ptr.save()
        addr = AddressRecord(label="host1", domain=root_domain, ip_str="11::",
                             ip_type="6")
        addr.save()
        res, error = compile_to_django("host1.wee2.wee.mozilla.com")
        self.assertFalse(error)
        self.assertEqual(len(res['A']), 1)
        self.assertEqual(len(res['PTR']), 1)

        res, error = compile_to_django("host1.wee2.wee.mozilla.com type=:A")
        self.assertFalse(error)
        self.assertEqual(len(res['A']), 1)
        self.assertEqual(len(res['PTR']), 0)

        res, error = compile_to_django("host1.wee2.wee.mozilla.com type=:PTR")
        self.assertFalse(error)
        self.assertEqual(len(res['A']), 0)
        self.assertEqual(len(res['PTR']), 1)

        res, error = compile_to_django("host1.wee2.wee.mozilla.com type=:A "
                                       "type=:PTR")
        self.assertFalse(error)
        self.assertEqual(len(res['A']), 0)
        self.assertEqual(len(res['PTR']), 0)
    def test_ptr_cname_exists(self):
        print "see BUG https://bugzilla.mozilla.org/show_bug.cgi?id=810106"
        return
        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 = PTR(ip_str="10.193.1.1", ip_type='4', name='testyfoo.what.cd')

        self.assertRaises(ValidationError, rec.clean)
    def test0(self):
        ip_start = "10.0.0.0"
        ip_end = "10.0.0.9"
        ptr = PTR(name="foo.mz", ip_str="10.0.0.5", ip_type='4')
        ptr.full_clean()
        ptr.save()
        istart, iend, ipf_q = start_end_filter(ip_start, ip_end, '4')
        addrs = list(
            AddressRecord.objects.filter(ipf_q).order_by('ip_lower').order_by(
                'ip_upper'))
        ptrs = list(
            PTR.objects.filter(ipf_q).order_by('ip_lower').order_by(
                'ip_upper'))
        sregs = list(
            StaticReg.objects.filter(ipf_q).order_by('ip_lower').order_by(
                'ip_upper'))
        self.assertFalse(addrs)
        self.assertEqual(ptr.pk, ptrs[0].pk)
        self.assertFalse(sregs)

        range_details = range_usage(ip_start, ip_end, '4')
        self.assertEqual(9, range_details['unused'])
        self.assertEqual(1, range_details['used'])
        self.assertEqual([(int(istart) + 0, int(istart) + 4),
                          (int(istart) + 6, int(istart) + 9)],
                         range_details['free_ranges'])
    def test1(self):
        ip_start = "10.0.0.10"
        ip_end = "10.0.0.19"

        ptr = PTR(name="foo.mz", ip_str="10.0.0.15", ip_type='4')
        ptr.full_clean()
        ptr.save()

        a = AddressRecord(label="foo",
                          domain=self.domain,
                          ip_str="10.0.0.16",
                          ip_type='4')
        a.full_clean()
        a.save()

        istart, iend, ipf_q = start_end_filter(ip_start, ip_end, '4')
        addrs = list(
            AddressRecord.objects.filter(ipf_q).order_by('ip_lower').order_by(
                'ip_upper'))
        ptrs = list(
            PTR.objects.filter(ipf_q).order_by('ip_lower').order_by(
                'ip_upper'))
        sregs = list(
            StaticReg.objects.filter(ipf_q).order_by('ip_lower').order_by(
                'ip_upper'))
        self.assertEqual(a.pk, addrs[0].pk)
        self.assertEqual(ptr.pk, ptrs[0].pk)
        self.assertFalse(sregs)

        range_details = range_usage(ip_start, ip_end, '4')
        self.assertEqual(8, range_details['unused'])
        self.assertEqual(2, range_details['used'])
        self.assertEqual([(int(istart), int(istart) + 4),
                          (int(istart) + 7, int(istart) + 9)],
                         range_details['free_ranges'])
    def test_bad_nameserver_soa_state_case_1_2(self):
        # This is Case 1 ... with ptr's
        root_domain = create_fake_zone("12.in-addr.arpa", suffix="")
        for ns in root_domain.nameserver_set.all():
            ns.delete()

        # At his point we should have a domain at the root of a zone with no
        # other records in it.

        # Adding a record shouldn't be allowed because there is no NS record on
        # the zone's root domain.
        ptr = PTR(name="asdf", ip_str="12.10.1.1", ip_type="4")
        self.assertRaises(ValidationError, ptr.save)
    def test_bad_nameserver_soa_state_case_3_3(self):
        # This is Case 3 ... with ptrs
        root_domain = create_fake_zone("33.in-addr.arpa", suffix="")
        for ns in root_domain.nameserver_set.all():
            ns.delete()

        # At his point we should have a domain pointed at an SOA record with no
        # records attached to it (esspecially no ns recods). It also has no
        # child domains.
        # Try case 3 but add a record to a child domain of root_domain
        cdomain = Domain(name="10.33.in-addr.arpa")
        cdomain.save()

        # Add a record to the domain.
        ptr = PTR(name="asdf", ip_str="33.10.1.1", ip_type="4")
        ptr.save()

        # Now try to add the domain to the zone that has no NS records at it's
        # root
        cdomain.soa = root_domain.soa

        self.assertRaises(ValidationError, cdomain.save)
Beispiel #23
0
    def do_generic_remove(self, ip, fqdn, ip_type):
        ptr = PTR(ip_str=ip, name=fqdn, ip_type=ip_type)
        ptr.full_clean()
        ptr.save()

        ptr.delete()

        ip = Ip(ip_str=ip, ip_type=ip_type)
        ip.clean_ip()
        ptr = PTR.objects.filter(
            name=fqdn, ip_upper=ip.ip_upper, ip_lower=ip.ip_lower)
        self.assertFalse(ptr)
    def test0(self):
        ip_start = "10.0.0.0"
        ip_end = "10.0.0.9"
        ptr = PTR(name="foo.mz", ip_str="10.0.0.5", ip_type='4')
        ptr.full_clean()
        ptr.save()
        istart, iend, ipf_q = start_end_filter(ip_start, ip_end, '4')
        addrs = list(AddressRecord.objects.filter(ipf_q).
                     order_by('ip_lower').order_by('ip_upper'))
        ptrs = list(PTR.objects.filter(ipf_q).
                    order_by('ip_lower').order_by('ip_upper'))
        intrs = list(StaticInterface.objects.filter(ipf_q).
                     order_by('ip_lower').order_by('ip_upper'))
        self.assertFalse(addrs)
        self.assertEqual(ptr.pk, ptrs[0].pk)
        self.assertFalse(intrs)

        range_details = range_usage(ip_start, ip_end, '4')
        self.assertEqual(9, range_details['unused'])
        self.assertEqual(1, range_details['used'])
        self.assertEqual([(int(istart) + 0, int(istart) + 4),
                          (int(istart) + 6, int(istart) + 9)],
                         range_details['free_ranges'])
    def test2(self):
        ip_start = "10.0.1.0"
        ip_end = "10.0.1.99"
        ptr = PTR(name="foo.mz", ip_str="10.0.1.3", ip_type='4')
        ptr.full_clean()
        ptr.save()

        a = AddressRecord(label="foo", domain=self.domain, ip_str="10.0.1.3",
                          ip_type='4')
        a.full_clean()
        a.save()

        s = System()
        s.save()
        intr = StaticInterface(
            label="foo", domain=self.domain, ip_str="10.0.1.4",
            ip_type='4', system=s, mac="00:11:22:33:44:55")
        intr.full_clean()
        intr.save()

        istart, iend, ipf_q = start_end_filter(ip_start, ip_end, '4')
        addrs = list(AddressRecord.objects.filter(ipf_q).
                     order_by('ip_lower').order_by('ip_upper'))
        ptrs = list(PTR.objects.filter(ipf_q).
                    order_by('ip_lower').order_by('ip_upper'))
        intrs = list(StaticInterface.objects.filter(ipf_q).
                     order_by('ip_lower').order_by('ip_upper'))
        self.assertEqual(a.pk, addrs[0].pk)
        self.assertEqual(ptr.pk, ptrs[0].pk)
        self.assertEqual(intr.pk, intrs[0].pk)

        range_details = range_usage(ip_start, ip_end, '4')
        self.assertEqual(98, range_details['unused'])
        self.assertEqual(2, range_details['used'])
        self.assertEqual([(int(istart) + 0, int(istart) + 2),
                          (int(istart) + 5, int(istart) + 99)],
                         range_details['free_ranges'])
Beispiel #26
0
 def test1_bad_add_for_a_ptr(self):
     # sreg exists, then try ptr and A
     label = "9988food"
     domain = self.c
     ip_str = "10.0.0.1"
     kwargs = {
         'label': label, 'domain': domain, 'ip_str': ip_str,
     }
     ip_type = '4'
     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.save)
     ptr = PTR(ip_str=ip_str, ip_type=ip_type, name=i.fqdn)
     self.assertRaises(ValidationError, ptr.save)
 def test1_bad_add_for_a_ptr(self):
     # StaticReg exists, then try ptr and A
     label = "9988fooddfdf"
     domain = self.c
     ip_str = "111::11:22:33:44:55:6e"
     kwargs = {'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 test_ptr_exists(self):
        # No unittest.skip in 2.6
        print "see BUG https://bugzilla.mozilla.org/show_bug.cgi?id=810106"
        return
        label = "testyfoo"
        data = "wat"
        dom, _ = Domain.objects.get_or_create(name="cd")
        dom, _ = Domain.objects.get_or_create(name="what.cd")

        rec = PTR(ip_str="10.193.1.1", ip_type='4', name='testyfoo.what.cd')
        rec.full_clean()
        rec.save()

        cn = CNAME(label=label, domain=dom, target=data)
        self.assertRaises(ValidationError, cn.full_clean)
 def test2_bad_add_for_a_ptr(self):
     # PTR and A exist, then try add sreg
     label = "9988fdfood"
     domain = self.c
     ip_str = "1112::11:22:33:44:55:66"
     kwargs = {'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 test2(self):
        ip_start = "10.0.1.0"
        ip_end = "10.0.1.99"
        ptr = PTR(name="foo.mz", ip_str="10.0.1.3", ip_type='4')
        ptr.full_clean()
        ptr.save()

        a = AddressRecord(label="foo",
                          domain=self.domain,
                          ip_str="10.0.1.3",
                          ip_type='4')
        a.full_clean()
        a.save()

        s = create_fake_host(hostname="foo.mozilla.com")
        s.save()
        sreg = StaticReg.objects.create(label="foo",
                                        domain=self.domain,
                                        ip_str="10.0.1.4",
                                        ip_type='4',
                                        system=s)

        istart, iend, ipf_q = start_end_filter(ip_start, ip_end, '4')
        addrs = list(
            AddressRecord.objects.filter(ipf_q).order_by('ip_lower').order_by(
                'ip_upper'))
        ptrs = list(
            PTR.objects.filter(ipf_q).order_by('ip_lower').order_by(
                'ip_upper'))
        sregs = list(
            StaticReg.objects.filter(ipf_q).order_by('ip_lower').order_by(
                'ip_upper'))
        self.assertEqual(a.pk, addrs[0].pk)
        self.assertEqual(ptr.pk, ptrs[0].pk)
        self.assertEqual(sreg.pk, sregs[0].pk)

        range_details = range_usage(ip_start, ip_end, '4')
        self.assertEqual(98, range_details['unused'])
        self.assertEqual(2, range_details['used'])
        self.assertEqual([(int(istart) + 0, int(istart) + 2),
                          (int(istart) + 5, int(istart) + 99)],
                         range_details['free_ranges'])
Beispiel #31
0
    def test_no_ns_views(self):
        root_domain = create_fake_zone("12.88.in-addr.arpa", suffix="")
        self.assertEqual(1, root_domain.nameserver_set.all().count())
        ns = root_domain.nameserver_set.all()[0]
        self.assertTrue(self.private_view in ns.views.all())
        self.assertTrue(self.public_view in ns.views.all())

        ptr = PTR(ip_str="88.12.1.1", ip_type='4', name='foo.bar')
        ptr.full_clean()
        ptr.save()

        # At this point we have a zone with a NS in both private and public
        # views. There is a ptr in the zone but its not in a view.

        # Add the ptr to the public view
        ptr.views.add(self.public_view)
        ptr = PTR.objects.get(pk=ptr.pk)
        self.assertTrue(self.public_view in ptr.views.all())

        ns_url = self.object_url.format(
            API_VERSION,
            str(self.test_type.__name__).lower(),
            ns.pk)  # The url for the nameserver in the zone

        # Try removing the NS from the public view, it should fail
        post_data = {'pk': ns.pk, 'views': ['no-public']}
        update_resp, post_data = self.generic_update(
            ns_url, post_data, assertResponse=self.assertHttpBadRequest)
        ns = Nameserver.objects.get(pk=ns.pk)
        # Nothing should have changed
        self.assertTrue(self.private_view in ns.views.all())
        self.assertTrue(self.public_view in ns.views.all())

        # We should be allowed to remove the private view
        post_data = {'pk': ns.pk, 'views': ['no-private']}
        update_resp, post_data = self.generic_update(ns_url, post_data)
        ns = Nameserver.objects.get(pk=ns.pk)
        self.assertTrue(self.private_view not in ns.views.all())
        self.assertTrue(self.public_view in ns.views.all())

        # Re add all views to the NS
        ns = Nameserver.objects.get(pk=ns.pk)
        ns.views.add(self.public_view)
        ns.views.add(self.private_view)

        # Remove the ptr from the public view and add it to the private view
        ptr.views.remove(self.public_view)
        ptr.views.add(self.private_view)

        # Try removing the NS from the private view, it should fail
        post_data = {'pk': ns.pk, 'views': ['no-private']}
        update_resp, post_data = self.generic_update(
            ns_url, post_data, assertResponse=self.assertHttpBadRequest)
        ns = Nameserver.objects.get(pk=ns.pk)
        self.assertTrue(self.private_view in ns.views.all())
        self.assertTrue(self.public_view in ns.views.all())

        # Create another NS record
        ns1 = Nameserver(domain=root_domain, server="foo.bar")
        ns1.save()
        ns1.views.add(self.private_view)

        # there is another NS there now, we should be able to remove the
        # private view
        post_data = {'pk': ns.pk, 'views': ['no-private']}
        update_resp, post_data = self.generic_update(ns_url, post_data)
        ns = Nameserver.objects.get(pk=ns.pk)
        self.assertTrue(self.private_view not in ns.views.all())
        self.assertTrue(self.public_view in ns.views.all())

        # The new ns (ns1) is the only ns enabled, it should not be allowed to
        # leave the private view. Try removing the NS from the private view, it
        # should fail
        post_data_ns1 = {'pk': ns1.pk, 'views': ['no-private']}
        ns1_url = self.object_url.format(
            API_VERSION,
            str(self.test_type.__name__).lower(),
            ns1.pk)  # The url for the nameserver in the zone
        update_resp, post_data_ns1 = self.generic_update(
            ns1_url, post_data_ns1, assertResponse=self.assertHttpBadRequest)
        ns1 = Nameserver.objects.get(pk=ns1.pk)
        self.assertTrue(self.private_view in ns1.views.all())
        self.assertTrue(self.public_view in ns.views.all())

        # Re-add the original ns to the private view and then delete ns1
        post_data = {'pk': ns.pk, 'views': ['private']}
        update_resp, post_data = self.generic_update(ns_url, post_data)
        ns = Nameserver.objects.get(pk=ns.pk)
        self.assertTrue(self.private_view in ns.views.all())
        self.assertTrue(self.public_view in ns.views.all())

        ns1.delete()

        # There is now one ns that is in the private and public view
        self.assertEqual(1, root_domain.nameserver_set.all().count())
        self.assertTrue(self.private_view in ns.views.all())
        self.assertTrue(self.public_view in ns.views.all())

        # We should be allowed to remove the public view
        post_data = {'pk': ns.pk, 'views': ['no-public']}
        update_resp, post_data = self.generic_update(ns_url, post_data)
        self.assertHttpAccepted(update_resp)
        ns = Nameserver.objects.get(pk=ns.pk)
        self.assertTrue(self.private_view in ns.views.all())
        self.assertTrue(self.public_view not in ns.views.all())

        # Remove the ptr from all views
        ptr.views.remove(self.private_view)
        self.assertTrue(self.public_view not in ptr.views.all())

        # We should now be able to remove the private view
        post_data = {'pk': ns.pk, 'views': ['no-private']}
        update_resp, post_data = self.generic_update(ns_url, post_data)
        ns = Nameserver.objects.get(pk=ns.pk)
        self.assertTrue(self.private_view not in ns.views.all())
        self.assertTrue(self.public_view not in ns.views.all())
 class Meta:
     always_return_data = True
     queryset = PTR.objects.all()
     fields = PTR.get_api_fields() + ['views']
     authorization = Authorization()
     allowed_methods = allowed_methods
    def test_private_view_case_2_ptr(self):
        ptr = PTR(name="asf", ip_str="10.0.0.2", ip_type="4")
        ptr.clean()
        ptr.save()
        # Object has to exist before views can be assigned.
        ptr.views.add(self.public)
        self.assertFalse(ptr.views.filter(name="public"))

        ptr = PTR(name="asf", ip_str="172.16.0.1", ip_type="4")
        ptr.clean()
        ptr.save()
        # Object has to exist before views can be assigned.
        ptr.views.add(self.public)
        self.assertFalse(ptr.views.filter(name="public"))

        ptr = PTR(name="asf", ip_str="192.168.2.3", ip_type="4")
        ptr.clean()
        ptr.save()
        # Object has to exist before views can be assigned.
        ptr.views.add(self.public)
        self.assertFalse(ptr.views.filter(name="public"))
Beispiel #34
0
    def test_no_ns_views(self):
        root_domain = create_fake_zone("12.88.in-addr.arpa", suffix="")
        self.assertEqual(1, root_domain.nameserver_set.all().count())
        ns = root_domain.nameserver_set.all()[0]
        self.assertTrue(self.private_view in ns.views.all())
        self.assertTrue(self.public_view in ns.views.all())

        ptr = PTR(ip_str="88.12.1.1", ip_type='4', name='foo.bar')
        ptr.full_clean()
        ptr.save()

        # At this point we have a zone with a NS in both private and public
        # views. There is a ptr in the zone but its not in a view.

        # Add the ptr to the public view
        ptr.views.add(self.public_view)
        ptr = PTR.objects.get(pk=ptr.pk)
        self.assertTrue(self.public_view in ptr.views.all())

        ns_url = self.object_url.format(
            API_VERSION, str(self.test_type.__name__).lower(), ns.pk
        )  # The url for the nameserver in the zone

        # Try removing the NS from the public view, it should fail
        post_data = {'pk': ns.pk, 'views': ['no-public']}
        update_resp, post_data = self.generic_update(
            ns_url, post_data, assertResponse=self.assertHttpBadRequest
        )
        ns = Nameserver.objects.get(pk=ns.pk)
        # Nothing should have changed
        self.assertTrue(self.private_view in ns.views.all())
        self.assertTrue(self.public_view in ns.views.all())

        # We should be allowed to remove the private view
        post_data = {'pk': ns.pk, 'views': ['no-private']}
        update_resp, post_data = self.generic_update(ns_url, post_data)
        ns = Nameserver.objects.get(pk=ns.pk)
        self.assertTrue(self.private_view not in ns.views.all())
        self.assertTrue(self.public_view in ns.views.all())

        # Re add all views to the NS
        ns = Nameserver.objects.get(pk=ns.pk)
        ns.views.add(self.public_view)
        ns.views.add(self.private_view)

        # Remove the ptr from the public view and add it to the private view
        ptr.views.remove(self.public_view)
        ptr.views.add(self.private_view)

        # Try removing the NS from the private view, it should fail
        post_data = {'pk': ns.pk, 'views': ['no-private']}
        update_resp, post_data = self.generic_update(
            ns_url, post_data, assertResponse=self.assertHttpBadRequest
        )
        ns = Nameserver.objects.get(pk=ns.pk)
        self.assertTrue(self.private_view in ns.views.all())
        self.assertTrue(self.public_view in ns.views.all())

        # Create another NS record
        ns1 = Nameserver(domain=root_domain, server="foo.bar")
        ns1.save()
        ns1.views.add(self.private_view)

        # there is another NS there now, we should be able to remove the
        # private view
        post_data = {'pk': ns.pk, 'views': ['no-private']}
        update_resp, post_data = self.generic_update(ns_url, post_data)
        ns = Nameserver.objects.get(pk=ns.pk)
        self.assertTrue(self.private_view not in ns.views.all())
        self.assertTrue(self.public_view in ns.views.all())

        # The new ns (ns1) is the only ns enabled, it should not be allowed to
        # leave the private view. Try removing the NS from the private view, it
        # should fail
        post_data_ns1 = {'pk': ns1.pk, 'views': ['no-private']}
        ns1_url = self.object_url.format(
            API_VERSION, str(self.test_type.__name__).lower(), ns1.pk
        )  # The url for the nameserver in the zone
        update_resp, post_data_ns1 = self.generic_update(
            ns1_url, post_data_ns1, assertResponse=self.assertHttpBadRequest
        )
        ns1 = Nameserver.objects.get(pk=ns1.pk)
        self.assertTrue(self.private_view in ns1.views.all())
        self.assertTrue(self.public_view in ns.views.all())

        # Re-add the original ns to the private view and then delete ns1
        post_data = {'pk': ns.pk, 'views': ['private']}
        update_resp, post_data = self.generic_update(ns_url, post_data)
        ns = Nameserver.objects.get(pk=ns.pk)
        self.assertTrue(self.private_view in ns.views.all())
        self.assertTrue(self.public_view in ns.views.all())

        ns1.delete()

        # There is now one ns that is in the private and public view
        self.assertEqual(1, root_domain.nameserver_set.all().count())
        self.assertTrue(self.private_view in ns.views.all())
        self.assertTrue(self.public_view in ns.views.all())

        # We should be allowed to remove the public view
        post_data = {'pk': ns.pk, 'views': ['no-public']}
        update_resp, post_data = self.generic_update(ns_url, post_data)
        self.assertHttpAccepted(update_resp)
        ns = Nameserver.objects.get(pk=ns.pk)
        self.assertTrue(self.private_view in ns.views.all())
        self.assertTrue(self.public_view not in ns.views.all())

        # Remove the ptr from all views
        ptr.views.remove(self.private_view)
        self.assertTrue(self.public_view not in ptr.views.all())

        # We should now be able to remove the private view
        post_data = {'pk': ns.pk, 'views': ['no-private']}
        update_resp, post_data = self.generic_update(ns_url, post_data)
        ns = Nameserver.objects.get(pk=ns.pk)
        self.assertTrue(self.private_view not in ns.views.all())
        self.assertTrue(self.public_view not in ns.views.all())
 def do_add_ptr(self, label, domain, ip_str, ip_type='4'):
     ptr = PTR(name=label + '.' + domain.name, ip_str=ip_str,
               ip_type=ip_type)
     ptr.clean()
     ptr.save()
     return ptr
 def add_ptr_ipv6(self, ip):
     ptr = PTR(name=random_label(), ip_str=ip, ip_type="6")
     ptr.full_clean()
     ptr.save()
     return ptr