Exemple #1
0
    def test_bad_delete(self):
        network = "129.0.0.0"
        prefixlen = "24"
        kwargs = {'network': network, 'prefixlen': prefixlen, 'ip_type': '4'}
        s = self.do_basic_add(**kwargs)
        s_pk = s.pk
        self.assertTrue(s)

        d = Domain(name="asdf")
        d.save()

        start_str = "129.0.0.1"
        end_str = "129.0.0.255"
        network = s

        r = Range(start_str=start_str, end_str=end_str, network=network)
        r.clean()
        r.save()

        self.assertEqual(r.network, s)
        self.assertTrue(len(s.range_set.all()) == 1)

        self.assertRaises(ValidationError, s.delete)
        self.assertTrue(Network.objects.get(pk=s_pk))

        r.delete()
        s.delete()
        self.assertEqual(len(Network.objects.filter(pk=s_pk)), 0)
Exemple #2
0
    def test_bad_delete(self):
        network = "129.0.0.0"
        prefixlen = "24"
        kwargs = {'network': network, 'prefixlen': prefixlen, 'ip_type': '4'}
        s = self.do_basic_add(**kwargs)
        s_pk = s.pk
        self.assertTrue(s)

        d = Domain(name="asdf")
        d.save()

        start_str = "129.0.0.1"
        end_str = "129.0.0.255"
        network = s

        r = Range(start_str=start_str, end_str=end_str, network=network)
        r.clean()
        r.save()

        self.assertEqual(r.network, s)
        self.assertTrue(len(s.range_set.all()) == 1)

        self.assertRaises(ValidationError, s.delete)
        self.assertTrue(Network.objects.get(pk=s_pk))

        r.delete()
        s.delete()
        self.assertEqual(len(Network.objects.filter(pk=s_pk)), 0)
Exemple #3
0
 def test_update_has_child_domain(self):
     Domain(name='com99').save()
     f_c = Domain(name='foo.com99')
     f_c.save()
     Domain(name='boo.foo.com99').save()
     f_c.name = 'foobar.com99'
     self.assertRaises(ValidationError, f_c.save)
class DeleteStaticStaticRegTests(TestCase):
    def create_domain(self, name, ip_type=None, delegated=False):
        if ip_type is None:
            ip_type = '4'
        if name in ('arpa', 'in-addr.arpa', 'ip6.arpa'):
            pass
        else:
            name = ip_to_domain_name(name, ip_type=ip_type)
        d = Domain(name=name, delegated=delegated)
        d.clean()
        self.assertTrue(d.is_reverse)
        return d

    def setUp(self):
        self.arpa = self.create_domain(name='arpa')
        self.arpa.save()
        self.i_arpa = self.create_domain(name='in-addr.arpa')
        self.i_arpa.save()

        self.c = Domain(name="ccc")
        self.c.save()
        self.f_c = Domain(name="foo.ccc")
        self.f_c.save()
        self.r1 = self.create_domain(name="10")
        self.r1.save()
        self.n = create_fake_host(hostname="foo.mozilla.com")
        self.n.clean()
        self.n.save()
        View.objects.get_or_create(name="private")

    def do_add(self, label, domain, ip_str, system, ip_type='4'):
        r = StaticReg(
            label=label, domain=domain, ip_str=ip_str,
            ip_type=ip_type, system=system
        )
        r.clean()
        r.save()
        return r

    def do_delete(self, r):
        ip_str = r.ip_str
        fqdn = r.fqdn
        r.delete()
        self.assertFalse(
            AddressRecord.objects.filter(ip_str=ip_str, fqdn=fqdn))

    def test1_delete_basic(self):
        # Does deleting a system delete it's interfaces?
        label = "foo"
        domain = self.f_c
        ip_str = "10.0.0.2"
        system = create_fake_host(hostname="foo")
        system.save()
        kwargs = {
            'label': label, 'domain': domain, 'ip_str': ip_str,
            'system': system}
        self.do_add(**kwargs)
        self.assertTrue(StaticReg.objects.filter(**kwargs))
        system.delete()
        self.assertFalse(StaticReg.objects.filter(**kwargs))
class CNAMEStaticRegTests(TestCase):
    def create_domain(self, name, ip_type=None, delegated=False):
        if ip_type is None:
            ip_type = '4'
        if name in ('arpa', 'in-addr.arpa', 'ip6.arpa'):
            pass
        else:
            name = ip_to_domain_name(name, ip_type=ip_type)
        d = Domain(name=name, delegated=delegated)
        d.clean()
        self.assertTrue(d.is_reverse)
        return d

    def setUp(self):
        self.arpa = self.create_domain(name='arpa')
        self.arpa.save()
        self.i_arpa = self.create_domain(name='in-addr.arpa')
        self.i_arpa.save()

        self.c = Domain(name="ccc")
        self.c.save()
        self.f_c = Domain(name="foo.ccc")
        self.f_c.save()
        self.r1 = self.create_domain(name="10")
        self.r1.save()
        self.n = System()
        self.n.clean()
        self.n.save()

    def do_add_intr(self, mac, label, domain, ip_str, ip_type='4'):
        r = StaticInterface(mac=mac, label=label, domain=domain, ip_str=ip_str,
                            ip_type=ip_type, system=self.n)
        r.clean()
        r.save()
        repr(r)
        return r

    def test1_delete_cname(self):
        mac = "11:22:33:44:55:66"
        label = "foo4"
        domain = self.f_c
        ip_str = "10.0.0.2"
        kwargs = {'mac': mac, 'label': label, 'domain': domain,
                  'ip_str': ip_str}
        i = self.do_add_intr(**kwargs)
        cn, _ = CNAME.objects.get_or_create(label='foo', domain=domain,
                                            target=label + "." + domain.name)
        self.assertRaises(ValidationError, i.delete)

    def test1_delete_override(self):
        mac = "12:22:33:44:55:66"
        label = "foo6"
        domain = self.f_c
        ip_str = "10.0.0.2"
        kwargs = {'mac': mac, 'label': label, 'domain': domain,
                  'ip_str': ip_str}
        i = self.do_add_intr(**kwargs)
        cn, _ = CNAME.objects.get_or_create(label='food', domain=domain,
                                            target=label + "." + domain.name)
        i.delete(check_cname=False)
Exemple #6
0
 def setUp(self):
     Domain.objects.all().delete()
     self.c = Client()
     Domain(name="com").save()
     Domain(name="mozilla.com").save()
     self.private_view, _ = View.objects.get_or_create(name='private')
     self.public_view, _ = View.objects.get_or_create(name='public')
Exemple #7
0
    def test_cleanup_cname(self):
        # Make sure CNAME record block
        c = Domain(name='foo1')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = create_fake_zone('foo.foo1', suffix="")
        self.assertEqual(f_c.name, 'foo.foo1')

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))

        self.assertFalse(f_c.purgeable)
        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        fqdn = "bar.x.y.z.foo.poo"
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))
 def setUp(self):
     self.o = Domain(name="org")
     self.o.save()
     self.o_e = Domain(name="oregonstate.org")
     self.o_e.save()
     self.b_o_e = Domain(name="bar.oregonstate.org")
     self.b_o_e.save()
Exemple #9
0
    def test_delegation_add_domain(self):
        name = "boom1"
        dom = Domain(name=name, delegated=True)
        dom.save()

        name = "boom.boom1"
        dom = Domain(name=name, delegated=False)
        self.assertRaises(ValidationError, dom.save)
Exemple #10
0
class SSHFPTests(TestCase):
    def setUp(self):
        self.o = Domain(name="org")
        self.o.save()
        self.o_e = Domain(name="mozilla.org")
        self.o_e.save()

    def do_generic_add(self, data):
        sshfp = SSHFP(**data)
        sshfp.__repr__()
        sshfp.save()
        self.assertTrue(sshfp.details())
        self.assertTrue(sshfp.get_absolute_url())
        self.assertTrue(sshfp.get_edit_url())
        self.assertTrue(sshfp.get_delete_url())
        rsshfp = SSHFP.objects.filter(**data)
        self.assertEqual(len(rsshfp), 1)
        return sshfp

    def do_remove(self, data):
        sshfp = self.do_generic_add(data)
        sshfp.delete()
        rmx = SSHFP.objects.filter(**data)
        self.assertTrue(len(rmx) == 0)

    def test_add_remove_sshfp(self):
        label = "asdf"
        key = "eee85bca3608ec860fc290bea491ce35d1f0a094"
        s_type = 1
        a_type = 1
        data = {'label': label, 'key': key, 'domain': self.o_e,
                'algorithm_number': a_type, 'fingerprint_type': s_type}
        self.do_generic_add(data)

        label = "asdk"
        key = "eee85bca3608ac860fc290bea491ce35d1f0a094"
        s_type = 1
        a_type = 1
        data = {'label': label, 'key': key, 'domain': self.o_e,
                'algorithm_number': a_type, 'fingerprint_type': s_type}
        self.do_generic_add(data)

        label = "df"
        key = "eee85bca3608ec860fc290bea491ce35d1f0a094"
        s_type = 1
        a_type = 1
        data = {'label': label, 'key': key, 'domain': self.o_e,
                'algorithm_number': a_type, 'fingerprint_type': s_type}
        self.do_generic_add(data)

        label = "12314"
        key = "eee85bca3608ec860fc290bea491ce35d1f0a094"
        s_type = 1
        a_type = 1
        data = {'label': label, 'key': key, 'domain': self.o,
                'algorithm_number': a_type, 'fingerprint_type': s_type}
        self.do_generic_add(data)
Exemple #11
0
 def setUp(self):
     self.url_slug = 'domain'
     soa = SOA(primary=random_label(),
               contact=random_label(),
               description=random_label())
     self.test_obj = Domain(name=random_label())
     self.test_obj.save()
     self.test_obj.soa = soa
     self.test_obj.save()
Exemple #12
0
class DomainViewTests(TestCase):
    def setUp(self):
        self.url_slug = 'domain'
        soa = SOA(primary=random_label(),
                  contact=random_label(),
                  description=random_label())
        self.test_obj = Domain(name=random_label())
        self.test_obj.save()
        self.test_obj.soa = soa
        self.test_obj.save()

    def test_base_mozdns_app_domain(self):
        resp = self.client.get(MOZDNS_BASE_URL + "/%s/" % (self.url_slug),
                               follow=True)
        self.assertEqual(resp.status_code, 200)

    def test_get_create_domain(self):
        resp = self.client.get(MOZDNS_BASE_URL + "/%s/create/" %
                               (self.url_slug),
                               follow=True)
        self.assertEqual(resp.status_code, 200)

    def test_post_create_domain(self):
        resp = self.client.post(MOZDNS_BASE_URL + "/%s/create/" %
                                (self.url_slug),
                                self.post_data(),
                                follow=True)
        self.assertTrue(resp.status_code in (302, 200))

    def test_get_object_update_domain(self):
        resp = self.client.get(MOZDNS_BASE_URL + "/%s/%s/update/" %
                               (self.url_slug, self.test_obj.pk),
                               follow=True)
        self.assertEqual(resp.status_code, 200)

    def test_post_object_update_domain(self):
        resp = self.client.post(MOZDNS_BASE_URL + "/%s/%s/update/" %
                                (self.url_slug, self.test_obj.pk),
                                self.post_data(),
                                follow=True)
        self.assertTrue(resp.status_code in (302, 200))

    def test_get_object_details_domain(self):
        resp = self.client.get(MOZDNS_BASE_URL + "/%s/%s/" %
                               (self.url_slug, self.test_obj.pk),
                               follow=True)
        self.assertEqual(resp.status_code, 200)

    def test_get_object_delete_domain(self):
        resp = self.client.get(MOZDNS_BASE_URL + "/%s/%s/delete/" %
                               (self.url_slug, self.test_obj.pk),
                               follow=True)
        self.assertEqual(resp.status_code, 200)

    def post_data(self):
        return {'name': random_label()}
    def test_remove_has_child_records(self):
        Domain(name='com').save()
        f_c = Domain(name='foo.com')
        f_c.save()

        cn = CNAME(domain=f_c, label="no", target="asdf")
        cn.full_clean()
        cn.save()

        self.assertRaises(ValidationError, f_c.delete)
Exemple #14
0
    def test_remove_has_child_records(self):
        Domain(name='com').save()
        f_c = Domain(name='foo.com')
        f_c.save()

        cn = CNAME(domain=f_c, label="no", target="asdf")
        cn.full_clean()
        cn.save()

        self.assertRaises(ValidationError, f_c.delete)
 def create_domain(self, name, ip_type=None, delegated=False):
     if ip_type is None:
         ip_type = '4'
     if name in ('arpa', 'in-addr.arpa', 'ip6.arpa'):
         pass
     else:
         name = ip_to_domain_name(name, ip_type=ip_type)
     d = Domain(name=name, delegated=delegated)
     d.clean()
     self.assertTrue(d.is_reverse)
     return d
Exemple #16
0
def build_sample_domain():
    domain_name = ''
    for i in range(2):
        domain_name = random_label()
        domain = Domain(name=domain_name)
    soa = SOA(
        primary=random_label(), contact="asf", description=random_label())
    soa.save()
    domain.soa = soa
    domain.save()
    return domain
Exemple #17
0
    def test_add_address_underscore_in_name_domain(self):
        d = Domain(name="_mssucks.edu")
        d.save()
        data = {'label': '*', 'domain': d, 'ip': "128.193.0.10"}
        self.do_add_record(data)
        data = {'label': 'foo', 'domain': d, 'ip': "128.193.0.10"}
        a = self.do_add_record(data)
        a.save()

        data = {'label': 'noop', 'domain': d, 'ip': "128.193.0.10"}
        self.do_add_record(data)
Exemple #18
0
    def test_add_address_underscore_in_name_domain(self):
        d = Domain(name="_mssucks.edu")
        d.save()
        data = {'label': '*', 'domain': d, 'ip': "128.193.0.10"}
        self.do_add_record(data)
        data = {'label': 'foo', 'domain': d, 'ip': "128.193.0.10"}
        a = self.do_add_record(data)
        a.save()

        data = {'label': 'noop', 'domain': d, 'ip': "128.193.0.10"}
        self.do_add_record(data)
    def test_basic_add_remove2(self):
        # MAke sure that if a domain is set to not purgeable the prune stops at
        # that domain.
        c = Domain(name='edu')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = Domain(name='foo.edu')
        s, _ = SOA.objects.get_or_create(primary="foo",
                                         contact="foo",
                                         description="foo.edu")
        f_c.soa = s
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.edu"
        label, the_domain = ensure_label_domain(fqdn)
        self.assertEqual(label, "bar")
        self.assertEqual(the_domain.name, "x.y.z.foo.edu")
        self.assertTrue(the_domain.purgeable)
        self.assertEqual(the_domain.master_domain.name, "y.z.foo.edu")
        self.assertTrue(the_domain.master_domain.purgeable)
        self.assertEqual(the_domain.master_domain.master_domain.name,
                         "z.foo.edu")
        self.assertTrue(the_domain.master_domain.master_domain.purgeable)
        self.assertEqual(
            the_domain.master_domain.master_domain.master_domain.name,
            "foo.edu")
        self.assertFalse(
            the_domain.master_domain.master_domain.master_domain.purgeable)

        # See if purgeable stops prune
        the_domain.purgeable = False
        the_domain.save()
        self.assertFalse(prune_tree(the_domain))
        the_domain.purgeable = True
        the_domain.save()
        # Ok, reset

        y_z = Domain.objects.get(name="y.z.foo.edu")
        y_z.purgeable = False
        y_z.save()

        # Refresh the domain
        the_domain = Domain.objects.get(pk=the_domain.pk)
        # This should delete up to and stop at the domain "y.z.foo.edu"
        self.assertTrue(prune_tree(the_domain))

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="y.z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="foo.edu"))

        # If we delete y.z.foo.com and then call prune on z.foo.com is should
        # delete z.foo.com
        Domain.objects.get(name="y.z.foo.edu").delete()

        self.assertTrue(prune_tree(Domain.objects.get(name="z.foo.edu")))
        self.assertFalse(Domain.objects.filter(name="z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="foo.edu"))
    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 allowed.
        arec1 = AddressRecord(label="ns1",
                              domain=dom,
                              ip_str="128.193.100.10",
                              ip_type='4')
        arec1.save()
Exemple #21
0
 def test2_add_domain(self):
     # Some domains have '_' in their name. Make sure validation allows
     # this.
     c = Domain(name='cz')
     c.save()
     c1 = Domain(name='_foo.cz')
     c1.save()
     c2 = Domain(name='moo_foo._foo.cz')
     c2.save()
class TXTTests(TestCase):
    def setUp(self):
        self.o = Domain(name="org")
        self.o.save()
        self.o_e = Domain(name="oregonstate.org")
        self.o_e.save()

    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 do_remove(self, data):
        txt = self.do_generic_add(data)
        txt.delete()
        rmx = TXT.objects.filter(**data)
        self.assertTrue(len(rmx) == 0)

    def test_add_remove_txt(self):
        label = "asdf"
        data = "asdf"
        data = {'label': label, 'txt_data': data, 'domain': self.o_e}
        self.do_generic_add(data)

        label = "asdf"
        data = "asdfasfd"
        data = {'label': label, 'txt_data': data, 'domain': self.o_e}
        self.do_generic_add(data)

        label = "df"
        data = "aasdf"
        data = {'label': label, 'txt_data': data, 'domain': self.o_e}
        self.do_generic_add(data)

        label = "12314"
        data = "dd"
        data = {'label': label, 'txt_data': data, 'domain': self.o}
        self.do_generic_add(data)

    def test_bad_data(self):
        label = "asdf"
        data = '"dfa f'
        data = {'label': label, 'txt_data': data, 'domain': self.o_e}
        self.assertRaises(ValidationError, self.do_generic_add, data)
 def test_delete_with_domains(self):
     data = {'primary': "ns1asfdadsf.foo.com", 'contact': "email.foo.com"}
     soa = SOA(**data)
     soa.save()
     d0 = Domain(name='com')
     d0.save()
     d1 = Domain(name='foo.com', soa=soa)
     d1.soa = soa
     d1.save()
     self.assertRaises(ValidationError, soa.delete)
Exemple #24
0
    def test_no_soa_block2(self):
        c = Domain(name='moo')
        c.save()
        f_c = Domain(name='foo.moo')
        f_c.save()
        s, _ = SOA.objects.get_or_create(primary="bar23", contact="Foo",
                                         description="bar")
        f_c.soa = s
        f_c.save()

        self.assertRaises(ValidationError, ensure_label_domain, "baz.moo")
    def setUp(self):
        self.o = Domain(name="org")
        self.o.save()
        self.f_o = Domain(name="foo.org")
        self.f_o.save()
        self.s = System()

        Domain.objects.get_or_create(name="arpa")
        Domain.objects.get_or_create(name="in-addr.arpa")
        Domain.objects.get_or_create(name="10.in-addr.arpa")
        Domain.objects.get_or_create(name="172.in-addr.arpa")
        Domain.objects.get_or_create(name="192.in-addr.arpa")

        self.public, _ = View.objects.get_or_create(name="public")
        self.private, _ = View.objects.get_or_create(name="private")
Exemple #26
0
    def setUp(self):
        self.o = Domain(name="org")
        self.o.save()
        self.f_o = Domain(name="foo.org")
        self.f_o.save()
        self.s = create_fake_host(hostname="foo.mozilla.com")

        Domain.objects.get_or_create(name="arpa")
        Domain.objects.get_or_create(name="in-addr.arpa")
        Domain.objects.get_or_create(name="10.in-addr.arpa")
        Domain.objects.get_or_create(name="172.in-addr.arpa")
        Domain.objects.get_or_create(name="192.in-addr.arpa")

        self.public, _ = View.objects.get_or_create(name="public")
        self.private, _ = View.objects.get_or_create(name="private")
    def setUp(self):
        self.arpa = self.create_domain(name='arpa')
        self.arpa.save()
        self.i_arpa = self.create_domain(name='in-addr.arpa')
        self.i_arpa.save()

        self.c = Domain(name="ccc")
        self.c.save()
        self.f_c = Domain(name="foo.ccc")
        self.f_c.save()
        self.r1 = self.create_domain(name="10")
        self.r1.save()
        self.n = create_fake_host(hostname="foo.mozilla.com")
        self.n.clean()
        self.n.save()
Exemple #28
0
    def test_delegation_block(self):
        s, _ = SOA.objects.get_or_create(primary="foo", contact="Foo",
                                         description="foo")
        c = Domain(name='com')
        c.soa = s
        c.save()
        self.assertFalse(c.purgeable)
        f_c = Domain(name='foo.com')
        f_c.delegated = True
        f_c.save()
        self.assertFalse(f_c.purgeable)
        self.assertTrue(f_c.delegated)

        fqdn = "z.baz.foo.com"
        self.assertRaises(ValidationError, ensure_label_domain, fqdn)
    def setUp(self):
        self.arpa = self.create_domain(name='arpa')
        self.arpa.save()
        self.i_arpa = self.create_domain(name='in-addr.arpa')
        self.i_arpa.save()

        self.c = Domain(name="ccc")
        self.c.save()
        self.f_c = Domain(name="foo.ccc")
        self.f_c.save()
        self.r1 = self.create_domain(name="10")
        self.r1.save()
        self.n = System()
        self.n.clean()
        self.n.save()
Exemple #30
0
    def setUp(self):
        self.arpa = self.create_domain(name='arpa')
        self.arpa.save()
        self.i_arpa = self.create_domain(name='in-addr.arpa')
        self.i_arpa.save()

        self.c = Domain(name="ccc")
        self.c.save()
        self.f_c = Domain(name="foo.ccc")
        self.f_c.save()
        self.r1 = self.create_domain(name="10")
        self.r1.save()
        self.n = create_fake_host(hostname="foo.mozilla.com")
        self.n.clean()
        self.n.save()
Exemple #31
0
 def setUp(self):
     self.url_slug = "domain"
     soa = SOA(primary=random_label(), contact=random_label(), description=random_label())
     self.test_obj = Domain(name=random_label())
     self.test_obj.save()
     self.test_obj.soa = soa
     self.test_obj.save()
    def setUp(self):
        self.arpa = self.create_domain(name='arpa')
        self.arpa.save()
        self.i_arpa = self.create_domain(name='in-addr.arpa')
        self.i_arpa.save()

        self.c = Domain(name="ccc")
        self.c.save()
        self.f_c = Domain(name="foo.ccc")
        self.f_c.save()
        self.r1 = self.create_domain(name="10")
        self.r1.save()
        self.n = System()
        self.n.clean()
        self.n.save()
        View.objects.get_or_create(name="private")
Exemple #33
0
    def setUp(self):
        self.arpa = self.create_domain(name='arpa')
        self.arpa.save()
        self.i_arpa = self.create_domain(name='ip6.arpa', ip_type='6')
        self.i_arpa.save()

        self.c = Domain(name="ccc")
        self.c.save()
        self.f_c = Domain(name="foo.ccc")
        self.f_c.save()
        self.r1 = self.create_domain(name="0", ip_type='6')
        self.r1.save()
        self.r2 = self.create_domain(name="1", ip_type='6')
        self.r2.save()
        self.n = create_fake_host(hostname="foo.mozilla.com")
        self.n.clean()
        self.n.save()
    def setUp(self):
        self.arpa = self.create_domain(name='arpa')
        self.arpa.save()
        self.i_arpa = self.create_domain(name='ip6.arpa', ip_type='6')
        self.i_arpa.save()

        self.c = Domain(name="ccc")
        self.c.save()
        self.f_c = Domain(name="foo.ccc")
        self.f_c.save()
        self.r1 = self.create_domain(name="0", ip_type='6')
        self.r1.save()
        self.r2 = self.create_domain(name="1", ip_type='6')
        self.r2.save()
        self.n = create_fake_host(hostname="foo.mozilla.com")
        self.n.clean()
        self.n.save()
    def setUp(self):
        self.arpa = self.create_domain(name='arpa')
        self.arpa.save()
        self.i_arpa = self.create_domain(name='ip6.arpa', ip_type='6')
        self.i_arpa.save()

        self.c = Domain(name="ccc")
        self.c.save()
        self.f_c = Domain(name="foo.ccc")
        self.f_c.save()
        self.r1 = self.create_domain(name="0", ip_type='6')
        self.r1.save()
        self.r2 = self.create_domain(name="1", ip_type='6')
        self.r2.save()
        self.n = System()
        self.n.clean()
        self.n.save()
 def test_update_has_child_domain(self):
     Domain(name='com99').save()
     f_c = Domain(name='foo.com99')
     f_c.save()
     Domain(name='boo.foo.com99').save()
     f_c.name = 'foobar.com99'
     self.assertRaises(ValidationError, f_c.save)
Exemple #37
0
    def test_bad_nameserver_soa_state_case_1_3(self):
        # This is Case 1 ... with ptr's
        root_domain = create_fake_zone("13.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.

        # Let's create a child domain and try to add a record there.
        cdomain = Domain(name="10.13.in-addr.arpa")
        cdomain.soa = root_domain.soa
        cdomain.save()

        # 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="13.10.1.1", ip_type="4")
        self.assertRaises(ValidationError, ptr.save)
    def test_bad_nameserver_soa_state_case_1_3(self):
        # This is Case 1 ... with ptr's
        root_domain = create_fake_zone("13.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.

        # Let's create a child domain and try to add a record there.
        cdomain = Domain(name="10.13.in-addr.arpa")
        cdomain.soa = root_domain.soa
        cdomain.save()

        # 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="13.10.1.1", ip_type="4")
        self.assertRaises(ValidationError, ptr.save)
Exemple #39
0
    def setUp(self):
        self.arpa = self.create_domain(name='arpa')
        self.arpa.save()
        self.i_arpa = self.create_domain(name='in-addr.arpa')
        self.i_arpa.save()
        self.i6_arpa = self.create_domain(name='ip6.arpa')
        self.i6_arpa.save()

        self._128 = self.create_domain(name='128', ip_type='4')
        self._128.save()
        boot_strap_ipv6_reverse_domain("8.6.2.0")
        self.osu_block = "8620:105:F000:"
        self.o = Domain(name="edu")
        self.o.save()
        self.o_e = Domain(name="oregonstate.edu")
        self.o_e.save()
        self.b_o_e = Domain(name="bar.oregonstate.edu")
        self.b_o_e.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)
Exemple #41
0
    def test_bad_nameserver_soa_state_case_2_1(self):
        # This is Case 2
        root_domain = create_fake_zone("asdf21")
        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()

        AddressRecord.objects.create(
            label='', domain=cdomain, ip_type="6", ip_str="1::")

        self.assertRaises(ValidationError, ns.delete)
Exemple #42
0
    def setUp(self):
        self.arpa = self.create_domain(name='arpa')
        self.arpa.save()
        self.i_arpa = self.create_domain(name='in-addr.arpa')
        self.i_arpa.save()

        self.c = Domain(name="ccc")
        self.c.save()
        self.f_c = Domain(name="foo.ccc")
        self.f_c.save()
        self.r1 = self.create_domain(name="10")
        self.r1.save()

        self.r2 = self.create_domain(name="128")
        self.r2.save()
        self.n = create_fake_host(hostname="foo.mozilla.com")
        self.n.clean()
        self.n.save()
        View.objects.get_or_create(name="private")
Exemple #43
0
    def test_basic_add_remove2(self):
        # MAke sure that if a domain is set to not purgeable the prune stops at
        # that domain.
        c = Domain(name='edu')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = Domain(name='foo.edu')
        s, _ = SOA.objects.get_or_create(primary="foo", contact="foo",
                                         description="foo.edu")
        f_c.soa = s
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.edu"
        label, the_domain = ensure_label_domain(fqdn)
        self.assertEqual(label, "bar")
        self.assertEqual(the_domain.name, "x.y.z.foo.edu")
        self.assertTrue(the_domain.purgeable)
        self.assertEqual(the_domain.master_domain.name, "y.z.foo.edu")
        self.assertTrue(the_domain.master_domain.purgeable)
        self.assertEqual(
            the_domain.master_domain.master_domain.name, "z.foo.edu")
        self.assertTrue(the_domain.master_domain.master_domain.purgeable)
        self.assertEqual(
            the_domain.master_domain.master_domain.master_domain.name,
            "foo.edu")
        self.assertFalse(
            the_domain.master_domain.master_domain.master_domain.purgeable)

        # See if purgeable stops prune
        the_domain.purgeable = False
        the_domain.save()
        self.assertFalse(prune_tree(the_domain))
        the_domain.purgeable = True
        the_domain.save()
        # Ok, reset

        y_z = Domain.objects.get(name="y.z.foo.edu")
        y_z.purgeable = False
        y_z.save()

        # Refresh the domain
        the_domain = Domain.objects.get(pk=the_domain.pk)
        # This should delete up to and stop at the domain "y.z.foo.edu"
        self.assertTrue(prune_tree(the_domain))

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="y.z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="foo.edu"))

        # If we delete y.z.foo.com and then call prune on z.foo.com is should
        # delete z.foo.com
        Domain.objects.get(name="y.z.foo.edu").delete()

        self.assertTrue(prune_tree(Domain.objects.get(name="z.foo.edu")))
        self.assertFalse(Domain.objects.filter(name="z.foo.edu"))
        self.assertTrue(Domain.objects.filter(name="foo.edu"))
Exemple #44
0
    def test_no_soa_block(self):
        fqdn = "baz.bar.foo.eu"
        self.assertRaises(ValidationError, ensure_label_domain, fqdn)
        c = Domain(name='eu')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = Domain(name='foo.eu')
        f_c.save()
        self.assertFalse(f_c.purgeable)

        # Even with domains there, they aren't part of a zone and should so
        # creation should fail.
        self.assertRaises(ValidationError, ensure_label_domain, fqdn)
Exemple #45
0
    def test_bad_nameserver_soa_state_case_1_1(self):
        # This is Case 1
        root_domain = create_fake_zone("asdf111")
        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.

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

        # Adding a record shouldn't be allowed because there is no NS record on
        # the zone's root domain.
        a = AddressRecord(label='', domain=cdomain, ip_type="6", ip_str="1::")
        self.assertRaises(ValidationError, a.save)
        cn = CNAME(label='', domain=cdomain, target="asdf")
        self.assertRaises(ValidationError, cn.save)
    def test_bad_nameserver_soa_state_case_1_1(self):
        # This is Case 1
        root_domain = create_fake_zone("asdf111")
        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.

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

        # Adding a record shouldn't be allowed because there is no NS record on
        # the zone's root domain.
        a = AddressRecord(label='', domain=cdomain, ip_type="6", ip_str="1::")
        self.assertRaises(ValidationError, a.save)
        cn = CNAME(label='', domain=cdomain, target="asdf")
        self.assertRaises(ValidationError, cn.save)
    def test_invalid_add(self):

        bad = "asfda.as df"
        dom = Domain(name=bad)
        self.assertRaises(ValidationError, dom.save)

        bad = "."
        dom = Domain(name=bad)
        self.assertRaises(ValidationError, dom.save)

        bad = "edu. "
        dom = Domain(name=bad)
        self.assertRaises(ValidationError, dom.save)

        bad = ""
        dom = Domain(name=bad)
        self.assertRaises(ValidationError, dom.save)

        bad = "!@#$"
        dom = Domain(name=bad)
        self.assertRaises(ValidationError, dom.save)
    def test_bad_nameserver_soa_state_case_2_1(self):
        # This is Case 2
        root_domain = create_fake_zone("asdf21")
        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()

        AddressRecord.objects.create(label='',
                                     domain=cdomain,
                                     ip_type="6",
                                     ip_str="1::")

        self.assertRaises(ValidationError, ns.delete)
Exemple #49
0
 def setUp(self):
     self.o = Domain(name="org")
     self.o.save()
     self.o_e = Domain(name="oregonstate.org")
     self.o_e.save()
     self.b_o_e = Domain(name="bar.oregonstate.org")
     self.b_o_e.save()
Exemple #50
0
    def test_bad_resize(self):
        network = "129.0.0.0"
        prefixlen = "24"
        kwargs = {'network': network, 'prefixlen': prefixlen, 'ip_type': '4'}
        s = self.do_basic_add(**kwargs)
        self.assertTrue(s)

        d = Domain(name="asdf")
        d.save()

        start_str = "129.0.0.1"
        end_str = "129.0.0.255"
        network = s

        r = Range(start_str=start_str, end_str=end_str, network=network)
        r.save()

        self.assertEqual(r.network, s)
        self.assertTrue(len(s.range_set.all()) == 1)

        s.network_str = "129.0.0.0/25"
        self.assertRaises(ValidationError, s.clean)
    def test_delegation_add_domain(self):
        name = "boom1"
        dom = Domain(name=name, delegated=True)
        dom.save()

        name = "boom.boom1"
        dom = Domain(name=name, delegated=False)
        self.assertRaises(ValidationError, dom.save)
    def test_existing_cname_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)

        cn = CNAME(domain=t_dom, label="no", target="asdf")
        cn.full_clean()
        cn.save()

        name = "no.to.bo"
        n_dom = Domain(name=name, delegated=False)
        self.assertRaises(ValidationError, n_dom.save)
    def test_basic_add_remove1(self):
        c = Domain(name='com')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = Domain(name='foo.com')
        s, _ = SOA.objects.get_or_create(primary="foo",
                                         contact="foo",
                                         description="foo.zfoo.comom")
        f_c.soa = s
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.com"
        label, the_domain = ensure_label_domain(fqdn)
        self.assertEqual(label, "bar")
        self.assertEqual(the_domain.name, "x.y.z.foo.com")
        self.assertTrue(the_domain.purgeable)
        self.assertEqual(the_domain.master_domain.name, "y.z.foo.com")
        self.assertTrue(the_domain.master_domain.purgeable)
        self.assertEqual(the_domain.master_domain.master_domain.name,
                         "z.foo.com")
        self.assertTrue(the_domain.master_domain.master_domain.purgeable)
        self.assertEqual(
            the_domain.master_domain.master_domain.master_domain.name,
            "foo.com")
        self.assertFalse(
            the_domain.master_domain.master_domain.master_domain.purgeable)

        # Now call prune tree one the_domain
        self.assertTrue(prune_tree(the_domain))

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.com"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.com"))
        self.assertFalse(Domain.objects.filter(name="z.foo.com"))
        self.assertTrue(Domain.objects.filter(name="foo.com"))

        # Make sure other domain's can't be pruned
        self.assertFalse(prune_tree(f_c))
        self.assertTrue(Domain.objects.filter(name="foo.com"))
        self.assertFalse(prune_tree(c))
        self.assertTrue(Domain.objects.filter(name="com"))
    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)
Exemple #55
0
    def setUp(self):
        self.d = Domain(name="com")
        self.s = Network(network_str="1234:1234:1234::/16", ip_type='6')
        self.s.update_network()
        self.s.save()

        self.s1 = Network(network_str="1234:1134:1234::/32", ip_type='6')
        self.s1.update_network()
        self.s1.save()

        self.s2 = Network(network_str="fff::/4", ip_type='6')
        self.s2.update_network()
        self.s2.save()

        self.s3 = Network(network_str="ffff::/4", ip_type='6')
        self.s3.update_network()
        self.s3.save()
Exemple #56
0
    def setUp(self):
        self.arpa = self.create_domain(name='arpa')
        self.i_arpa = self.create_domain(name='in-addr.arpa')
        self.i6_arpa = self.create_domain(name='ip6.arpa')

        self.osu_block = "633:105:F000:"
        boot_strap_ipv6_reverse_domain("0.6.3")
        try:
            self.e = Domain(name='edu')
            self.e.save()
        except IntegrityError:
            pass
        try:
            self.o_e = Domain(name='oregonstate.edu')
            self.o_e.save()
        except IntegrityError:
            self.o_e = Domain.objects.filter(name='oregonstate.edu')[0]
            pass

        try:
            self.f_o_e = Domain(name='foo.oregonstate.edu')
            self.f_o_e.save()
        except IntegrityError:
            self.f_o_e = Domain.objects.filter(name='foo.oregonstate.edu')[0]
            pass

        try:
            self.m_o_e = Domain(name='max.oregonstate.edu')
            self.m_o_e.save()
        except IntegrityError:
            self.m_o_e = Domain.objects.filter(name='max.oregonstate.edu')[0]
            pass

        try:
            self.z_o_e = Domain(name='zax.oregonstate.edu')
            self.z_o_e.save()
        except IntegrityError:
            self.z_o_e = Domain.objects.filter(name='zax.oregonstate.edu')[0]
            pass
        try:
            self.g_o_e = Domain(name='george.oregonstate.edu')
            self.g_o_e.save()
        except IntegrityError:
            self.g_o_e = Domain.objects.filter(
                name='george.oregonstate.edu')[0]
            pass

        try:
            self._128 = self.create_domain(name='128')
            self._128.save()
        except IntegrityError:
            raise Exception
            self._128 = self.create_domain.objects.filter(name='128')[0]
            pass

        try:
            self._128_193 = self.create_domain(name='128.193')
            self._128_193.save()
        except IntegrityError:
            raise Exception
            self._128_193 = Domain.objects.filter(name='128.193')[0]
            pass