Ejemplo n.º 1
0
    def test_rdomain_records_perms(self):
        """
        Test common reverse domain record perms (ptr, reverse_ns)
        """
        self.setup_request()

        perm_table = {
            'cyder_admin': ['all'],
            'admin': ['all'],
            'user': ['all'],
            'guest': ['view'],
        }

        # initialize objs into ctnrs
        rdomain = ReverseDomain(id=None, name='128')
        rdomain.save()
        self.ctnr_admin.reverse_domains.add(rdomain)
        self.ctnr_user.reverse_domains.add(rdomain)
        self.ctnr_guest.reverse_domains.add(rdomain)
        self.save_all_ctnrs()
        rdomain_records = []
        rdomain_records.append(PTR(reverse_domain=rdomain))
        rdomain_records.append(ReverseNameserver(reverse_domain=rdomain))

        for obj in rdomain_records:
            self.check_perms_each_user(obj, perm_table)
Ejemplo n.º 2
0
    def test_creation(self):
        rd = ReverseDomain(name="130", ip_type="4")
        rd.save()
        try:
            ip = Ip(ip_str="130.193.1.2")  # Forget the ip_type
            ip.clean_ip()

        except ValidationError, e:
            pass
Ejemplo n.º 3
0
 def setUp(self):
     self.r = ReverseDomain( name = '129', ip_type= '4' )
     self.r.save()
     self.f_r =ReverseDomain( name = '129.123', ip_type= '4' )
     self.f_r.save()
     self.b_f_r = ReverseDomain( name = '129.123.123', ip_type= '4' )
     self.b_f_r.save()
     self._128 = ReverseDomain( name = '128', ip_type= '4' )
     self._128.save()
Ejemplo n.º 4
0
    def setUp(self):
        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 = ReverseDomain(name='128')
            self._128.save()
        except IntegrityError:
            self._128 = ReverseDomain.objects.filter( name = '128' )[0]
            pass

        try:
             self._128_193 = ReverseDomain( name = '128.193')
             self._128_193.save()
        except IntegrityError:
            self._128_193 = ReverseDomain.objects.filter( name = '128.193' )[0]
            pass
Ejemplo n.º 5
0
 def test_int_ip(self):
     rd = ReverseDomain(name="129", ip_type="4")
     rd.save()
     ip = Ip(ip_str="129.193.1.1", ip_type="4")
     ip.clean_ip()
     ip.__int__()
     ip.__repr__()
     rd = boot_strap_ipv6_reverse_domain("e")
     ip_str = "efff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
     ip = Ip(ip_str=ip_str, ip_type="6")
     ip.clean_ip()
     ip.__int__()
     ip.__repr__()
Ejemplo n.º 6
0
 def test_master_reverse_domain(self):
     rd1 = ReverseDomain(name = '128', ip_type='4')
     rd1.save()
     rd2 = ReverseDomain(name = '128.193', ip_type='4')
     rd2.save()
     rd3 = ReverseDomain(name = '128.193.8', ip_type='4')
     rd3.save()
     self.assertEqual(rd3.master_reverse_domain, rd2)
     self.assertEqual(rd2.master_reverse_domain, rd1)
     self.assertEqual(rd1.master_reverse_domain, None)
Ejemplo n.º 7
0
class ReverseDomainViewTests(TestCase):
    """
    Straight copy of domain view tests.
    TODO: use class inheritance and super to not reuse all the same code,
    only thing different from domain view tests is the url slug and name.
    """

    def setUp(self):
        self.url_slug = "reverse_domain"
        soa = SOA(primary=random_label(), contact=random_label(), comment=random_label())
        self.test_obj = ReverseDomain(name=random_byte())
        self.test_obj.save()
        self.test_obj.soa = soa
        self.test_obj.save()

    def test_base_app_reverse_domain(self):
        resp = self.client.get(CYDNS_BASE_URL + "/%s/" % (self.url_slug))
        self.assertEqual(resp.status_code, 200)

    def test_get_create_reverse_domain(self):
        resp = self.client.get(CYDNS_BASE_URL + "/%s/create/" % (self.url_slug))
        self.assertEqual(resp.status_code, 200)

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

    def test_get_object_update_reverse_domain(self):
        resp = self.client.get(CYDNS_BASE_URL + "/%s/%s/update/" % (self.url_slug, self.test_obj.pk))
        self.assertEqual(resp.status_code, 200)

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

    def test_post_object_update_reverse_domain(self):
        resp = self.client.post(CYDNS_BASE_URL + "/%s/%s/update/" % (self.url_slug, self.test_obj.pk), {"soa": ""})
        self.assertTrue(resp.status_code in (302, 200))

    def test_get_object_details_reverse_domain(self):
        resp = self.client.get(CYDNS_BASE_URL + "/%s/%s/" % (self.url_slug, self.test_obj.pk))
        self.assertEqual(resp.status_code, 200)

    def test_get_object_delete_reverse_domain(self):
        resp = self.client.get(CYDNS_BASE_URL + "/%s/%s/delete/" % (self.url_slug, self.test_obj.pk))
        self.assertEqual(resp.status_code, 200)

    def post_data(self):
        return {"name": str(random_byte()), "soa": "1", "ip_type": "4", "delegated": "on", "inherit_soa": "0"}
Ejemplo n.º 8
0
 def setUp(self):
     self.url_slug = "reverse_domain"
     soa = SOA(primary=random_label(), contact=random_label(), comment=random_label())
     self.test_obj = ReverseDomain(name=random_byte())
     self.test_obj.save()
     self.test_obj.soa = soa
     self.test_obj.save()
Ejemplo n.º 9
0
    def test_ctnr_rdomain_records(self):
        """
        Test being in ctnr /w common domain records gives appropriate perms
        common domain records: cname, mx, txt, srv
        """
        request = HttpRequest()
        request.user = self.test_user
        request.session = SessionStore()
        request.session['ctnr'] = self.ctnr

        # create domain, add domain to ctnr
        rdomain = ReverseDomain(id=None, name='128')
        rdomain.save()

        self.ctnr.reverse_domains.add(rdomain)
        self.ctnr.save()

        self.ctnr_admin.reverse_domains.add(rdomain)
        self.ctnr_admin.save()

        rdomain_records = []
        rdomain_records.append(PTR(reverse_domain=rdomain))
        rdomain_records.append(ReverseNameserver(reverse_domain=rdomain))

        for record in rdomain_records:
            # checks where user is not admin
            request.session = {'ctnr': self.ctnr}
            has_perm = self.test_user.get_profile().has_perm(request, record, write=False)
            self.assertTrue(has_perm, 'user should have read access')
            has_perm = self.test_user.get_profile().has_perm(request, record, write=True)
            self.assertFalse(has_perm, 'user should not have write access')

            # checks where user is admin
            request.session = {'ctnr': self.ctnr_admin}
            has_perm = self.test_user.get_profile().has_perm(request, record, write=False)
            self.assertTrue(has_perm, 'user should have read access')
            has_perm = self.test_user.get_profile().has_perm(request, record, write=True)
            self.assertTrue(has_perm, 'user should have write access')

            # checks where obj not in ctnr
            request.session = {'ctnr': self.ctnr_empty}
            has_perm = self.test_user.get_profile().has_perm(request, record, write=False)
            self.assertFalse(has_perm, 'user should not have read access')
            has_perm = self.test_user.get_profile().has_perm(request, record, write=True)
            self.assertFalse(has_perm, 'user should not have write access')
Ejemplo n.º 10
0
 def setUp(self):
     self._128 = ReverseDomain( 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()
Ejemplo n.º 11
0
    def test_add_remove_reverse_ipv6_domains(self):
        osu_block = "2620:105:F000"
        rd0 = boot_strap_ipv6_reverse_domain("2.6.2.0.0.1.0.5.f.0.0.0")

        ip1 = self.add_ptr_ipv6(osu_block+":8000::1")
        self.assertEqual(ip1.reverse_domain, rd0)
        ip2 = self.add_ptr_ipv6(osu_block+":8000::2")
        self.assertEqual(ip2.reverse_domain, rd0)
        ip3 = self.add_ptr_ipv6(osu_block+":8000::3")
        self.assertEqual(ip3.reverse_domain, rd0)
        ip4 = self.add_ptr_ipv6(osu_block+":8000::4")

        rd1 = ReverseDomain(name="2.6.2.0.0.1.0.5.f.0.0.0.8", ip_type='6')
        rd1.save()
        ip_upper, ip_lower = ipv6_to_longs(osu_block+":8000::1")
        ptr1 = PTR.objects.filter(ip_upper = ip_upper, ip_lower = ip_lower , ip_type = '6')[0]
        self.assertEqual(ptr1.reverse_domain, rd1)
        ip_upper, ip_lower = ipv6_to_longs(osu_block+":8000::2")
        ptr2 = PTR.objects.filter(ip_upper = ip_upper, ip_lower = ip_lower , ip_type = '6')[0]
        self.assertEqual(ptr2.reverse_domain, rd1)
        ip_upper, ip_lower = ipv6_to_longs(osu_block+":8000::3")
        ptr3 = PTR.objects.filter(ip_upper = ip_upper, ip_lower = ip_lower , ip_type = '6')[0]
        self.assertEqual(ptr3.reverse_domain, rd1)
        ip_upper, ip_lower = ipv6_to_longs(osu_block+":8000::4")
        ptr4 = PTR.objects.filter(ip_upper = ip_upper, ip_lower = ip_lower , ip_type = '6')[0]
        self.assertEqual(ptr4.reverse_domain, rd1)

        rd1.delete()

        ip_upper, ip_lower = ipv6_to_longs(osu_block+":8000::1")
        ptr1 = PTR.objects.filter(ip_upper = ip_upper, ip_lower = ip_lower , ip_type = '6')[0]
        self.assertEqual(ptr1.reverse_domain, rd0)
        ip_upper, ip_lower = ipv6_to_longs(osu_block+":8000::2")
        ptr2 = PTR.objects.filter(ip_upper = ip_upper, ip_lower = ip_lower , ip_type = '6')[0]
        self.assertEqual(ptr2.reverse_domain, rd0)
        ip_upper, ip_lower = ipv6_to_longs(osu_block+":8000::3")
        ptr3 = PTR.objects.filter(ip_upper = ip_upper, ip_lower = ip_lower , ip_type = '6')[0]
        self.assertEqual(ptr3.reverse_domain, rd0)
        ip_upper, ip_lower = ipv6_to_longs(osu_block+":8000::4")
        ptr4 = PTR.objects.filter(ip_upper = ip_upper, ip_lower = ip_lower , ip_type = '6')[0]
        self.assertEqual(ptr4.reverse_domain, rd0)
Ejemplo n.º 12
0
    def test_ctnr_reverse_domain(self):
        """
        Test being in ctnr /w rdomain gives appropriate perms
        Precondition: rdomain in ctnr
        Postcondition: full perm if admin, read only if not
        """
        request = HttpRequest()
        request.user = self.test_user
        request.session = SessionStore()
        request.session['ctnr'] = self.ctnr

        # create reverse domain, add reverse domain to ctnr
        rdomain = ReverseDomain(id=None, name='128')
        rdomain.save()

        self.ctnr.reverse_domains.add(rdomain)
        self.ctnr.save()

        self.ctnr_admin.reverse_domains.add(rdomain)
        self.ctnr_admin.save()

        # checks where user is not admin
        has_perm = self.test_user.get_profile().has_perm(request, rdomain, write=False)
        self.assertTrue(has_perm, 'user should have read access')
        has_perm = self.test_user.get_profile().has_perm(request, rdomain, write=True)
        self.assertFalse(has_perm, 'user should not have write access')

        # checks where user is admin
        request.session = {'ctnr': self.ctnr_admin}
        has_perm = self.test_user.get_profile().has_perm(request, rdomain, write=False)
        self.assertTrue(has_perm, 'user should have read access')
        has_perm = self.test_user.get_profile().has_perm(request, rdomain, write=True)
        self.assertTrue(has_perm, 'user should have write access')

        # checks where obj not in ctnr
        request.session = {'ctnr': self.ctnr_empty}
        has_perm = self.test_user.get_profile().has_perm(request, rdomain, write=False)
        self.assertFalse(has_perm, 'user should not have read access')
        has_perm = self.test_user.get_profile().has_perm(request, rdomain, write=True)
        self.assertFalse(has_perm, 'user should not have write access')
Ejemplo n.º 13
0
    def test_reverse_domain_perms(self):
        """
        Test reverse domain perms
        """
        self.setup_request()

        perm_table = {
            'cyder_admin': ['all'],
            'admin': ['all'],
            'user': ['all'],
            'guest': ['view'],
        }

        # initialize obj into ctnrs
        obj = ReverseDomain(id=None, name='128')
        obj.save()
        self.ctnr_admin.reverse_domains.add(obj)
        self.ctnr_user.reverse_domains.add(obj)
        self.ctnr_guest.reverse_domains.add(obj)
        self.save_all_ctnrs()

        self.check_perms_each_user(obj, perm_table)
Ejemplo n.º 14
0
    def setUp(self):
        self.r = Domain( name = "ru" )
        self.r.save()
        self.f_r = Domain( name = "foo.ru" )
        self.f_r.save()
        self.b_f_r = Domain( name = "bar.foo.ru" )
        self.b_f_r.save()

        self.f = Domain( name = "fam" )
        self.f.save()

        self._128 = ReverseDomain( name = '128', ip_type= '4' )
        self._128.save()
Ejemplo n.º 15
0
    def test_ipv4_str(self):
        rd = ReverseDomain(name="192", ip_type="4")
        rd.save()
        ip_str = "192.168.1.1"
        ip = ipaddr.IPv4Address(ip_str)
        Ip(ip_str=ip_str, ip_type="4").clean_ip()

        rd = ReverseDomain(name="128", ip_type="4")
        rd.save()
        ip_str = "128.168.1.1"
        ip = ipaddr.IPv4Address(ip_str)
        Ip(ip_str=ip_str, ip_type="4").clean_ip()
Ejemplo n.º 16
0
class RevNSTests(TestCase):
    def setUp(self):
        self.r = ReverseDomain( name = '129', ip_type= '4' )
        self.r.save()
        self.f_r =ReverseDomain( name = '129.123', ip_type= '4' )
        self.f_r.save()
        self.b_f_r = ReverseDomain( name = '129.123.123', ip_type= '4' )
        self.b_f_r.save()
        self._128 = ReverseDomain( name = '128', ip_type= '4' )
        self._128.save()

    def do_add(self, reverse_domain, server ):
        ns = ReverseNameserver( reverse_domain = reverse_domain, server = server)
        ns.save()
        ns.save()
        self.assertTrue(ns.__repr__())
        self.assertTrue(ns.details())
        self.assertTrue(ns.get_absolute_url())
        self.assertTrue(ns.get_edit_url())
        self.assertTrue(ns.get_delete_url())
        ret = ReverseNameserver.objects.filter( reverse_domain = reverse_domain, server = server )
        self.assertEqual( len(ret), 1 )
        return ns


    def test_add_ns(self):
        data = { 'reverse_domain':self.r , 'server':'ns2.moot.ru' }
        self.do_add( **data )

        data = { 'reverse_domain':self.r , 'server':u'ns3.moot.ru' }
        self.do_add( **data )

        data = { 'reverse_domain':self.b_f_r , 'server':'n1.moot.ru' }
        self.do_add( **data )

        data = { 'reverse_domain':self.b_f_r , 'server':'ns2.moot.ru' }
        self.do_add( **data )

        data = { 'reverse_domain':self.r , 'server':'asdf.asdf' }
        self.do_add( **data )



    def test_add_ns_outside_reverse_domain(self):
        data = { 'reverse_domain':self.f_r , 'server':'ns2.ru' }
        ns = self.do_add( **data )



    def test_invalid_create(self):
        data = { 'reverse_domain':self.r , 'server':'ns2 .ru', }
        self.assertRaises( ValidationError, self.do_add, **data )
        data = { 'reverse_domain':self.r , 'server':'ns2$.ru', }
        self.assertRaises( ValidationError, self.do_add, **data )
        data = { 'reverse_domain':self.r , 'server':'ns2..ru', }
        self.assertRaises( ValidationError, self.do_add, **data )
        data = { 'reverse_domain':self.r , 'server':'ns2.ru ', }
        self.assertRaises( ValidationError, self.do_add, **data )
        data = { 'reverse_domain':self.r , 'server':'', }
        self.assertRaises( ValidationError, self.do_add, **data )

    def test_add_dup(self):
        data = { 'reverse_domain':self.r , 'server':'ns2.moot.ru' }
        self.do_add( **data )

        self.assertRaises( ValidationError, self.do_add, **data)
Ejemplo n.º 17
0
class PTRTests(TestCase):
    def setUp(self):
        self._128 = ReverseDomain( 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 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_add_ipv4_ptr(self):
        ret = self.do_generic_add("128.193.1.1", "foo.bar.oregonstate.edu", '4')
        self.assertEqual( ret.data_domain, self.b_o_e )
        ret = self.do_generic_add("128.193.1.2", "foo.bar.oregonstate.edu", '4')
        self.assertEqual( ret.data_domain, self.b_o_e )
        ret = self.do_generic_add("128.193.1.1", "baasdfr.oregonstate.edu", '4')
        self.assertEqual( ret.data_domain, self.o_e )
        ret = self.do_generic_add("128.193.1.1", "fasdfasfdoo.bar.oregonstate.edu", '4')
        self.assertEqual( ret.data_domain, self.b_o_e )
        ret = self.do_generic_add("128.193.1.1", "lj21312bar.oregonstate.edu", '4')
        self.assertEqual( ret.data_domain, self.o_e )
        ret = self.do_generic_add("128.193.1.3", "baasdfr.oregonstate.edu", '4')
        self.assertEqual( ret.data_domain, self.o_e )
        ret = self.do_generic_add("128.193.1.7", "fasdfasfdoo.bar.oregonstate.edu", '4')
        self.assertEqual( ret.data_domain, self.b_o_e )
        ret = self.do_generic_add("128.193.16.1", "lj21312bar.oregonstate.edu", '4')
        self.assertEqual( ret.data_domain, self.o_e )
        ret = self.do_generic_add("128.193.16.1", "lj21312bar", '4')
        self.assertEqual( ret.data_domain, None )
        ret = self.do_generic_add("128.193.16.1", "ewr.rqewr.lj21312bar", '4')
        self.assertEqual( ret.data_domain, None )

    def test_add_ipv6_ptr(self):
        ret = self.do_generic_add(self.osu_block+":1", "foo.bar.oregonstate.edu", '6')
        self.assertEqual( ret.data_domain, self.b_o_e )
        ret = self.do_generic_add(self.osu_block+":8", "foo.bar.oregonstate.edu", '6')
        self.assertEqual( ret.data_domain, self.b_o_e )
        ret = self.do_generic_add(self.osu_block+":f", "asdflkhasidfgwhqiefuhgiasdf.foo.bar.oregonstate.edu", '6')
        self.assertEqual( ret.data_domain, self.b_o_e )
        ret = self.do_generic_add(self.osu_block+":d", "foo.bar.oregonstatesdfasdf.edu", '6')
        self.assertEqual( ret.data_domain, self.o )
        ret = self.do_generic_add(self.osu_block+":3", "foo.bar.oregonstate.eddfsafsadfu", '6')
        self.assertEqual( ret.data_domain, None )
        ret = self.do_generic_add(self.osu_block+":2", "foo.b213123123ar.oregonstate.edu", '6')
        self.assertEqual( ret.data_domain, self.o_e )
        ret = self.do_generic_add(self.osu_block+":5", "foo.bar.oregondfastate.com", '6')
        self.assertEqual( ret.data_domain, None)


    def do_generic_invalid_add( self, ip, fqdn, ip_type, exception, domain = None ):
        e = None
        try:
            self.do_generic_add(ip, fqdn, ip_type, domain)
        except exception, e:
            pass
        self.assertEqual(exception, type(e))
Ejemplo n.º 18
0
class AddressRecordTests(TestCase):
    def setUp(self):
        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 = ReverseDomain(name='128')
            self._128.save()
        except IntegrityError:
            self._128 = ReverseDomain.objects.filter( name = '128' )[0]
            pass

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

    ######################
    ### Updating Tests ###
    ######################
    def test_invalid_update_to_existing(self):


        rec1 = AddressRecord( label='bar', domain= self.z_o_e , ip_str="128.193.40.1", ip_type='4')
        rec2 = AddressRecord( label='bar', domain= self.z_o_e , ip_str="128.193.40.2", ip_type='4')
        rec3 = AddressRecord( label='foo', domain= self.z_o_e , ip_str="128.193.40.1", ip_type='4')
        rec3.save()
        rec2.save()
        rec1.save()

        rec1.label = "foo"
        self.assertRaises(ValidationError,rec1.save)

        rec3.label = "bar"
        self.assertRaises(ValidationError,rec3.save)


        osu_block = "633:105:F000:"
        rec1 = AddressRecord( label='bar', 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+":2", ip_type='6')
        rec3 = AddressRecord( label='foo', domain=self.z_o_e , ip_str = osu_block+":1", ip_type='6')
        rec1.save()
        rec2.save()
        rec3.save()

        rec2.ip_str = osu_block+":1"
        self.assertRaises(ValidationError,rec2.save)

        rec3.label = 'bar'
        self.assertRaises(ValidationError,rec3.save)

    """
    Things that could go wrong.
    1) Update to an invalid ip.
    2) Update to an invalid name.
    """
    def _do_generic_update_test( self, record, new_name, new_ip, ip_type ):
        if new_ip:
            if ip_type == '4':
                ip_upper, ip_lower = 0, ipaddr.IPv4Address(new_ip).__int__()
            else:
                ip_upper, ip_lower = ipv6_to_longs(new_ip)
        else:
            ip_upper, ip_lower = record.ip_upper, record.ip_lower

        if new_name is not None and new_ip is not None:
            aret  = AddressRecord.objects.filter( label = new_name, ip_upper = ip_upper,\
                                             ip_lower = ip_lower, ip_type = ip_type)[0]
        elif new_name is not None:
            # Just new_name
            aret  = AddressRecord.objects.filter( label = new_name, ip_upper = ip_upper,\
                                             ip_lower = ip_lower, ip_type = ip_type)[0]
        else:
            # Just new_ip
            aret  = AddressRecord.objects.filter( label = new_name, ip_upper = ip_upper,\
                                             ip_lower = ip_lower, ip_type = ip_type)[0]
        if new_name:
            self.assertEqual( aret.label, new_name )
        if new_ip:
            if ip_type == '4':
                self.assertEqual( aret.ip_str, ipaddr.IPv4Address(new_ip).__str__() )
            else:
                self.assertEqual( aret.ip_str, ipaddr.IPv6Address(new_ip).__str__() )

    def do_update_A_record( self, record, new_name, new_ip ):
        if new_name is not None:
            record.label = new_name
        if new_ip is not None:
            record.ip_str = new_ip
        record.save()
        self._do_generic_update_test( record, new_name, new_ip, '4' )

    def do_update_AAAA_record( self, record, new_name, new_ip ):
        if new_name is not None:
            record.label = new_name
        if new_ip is not None:
            record.ip_str = new_ip
        record.save()
        self._do_generic_update_test( record, new_name, new_ip, '6' )


    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 ='bazisgoingtobelasdfhklashflashfllk-324-123n2319rjn2ddasfdasfd-sa', 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_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_update_invalid_ip_A_record(self):
        rec0 = AddressRecord( label = '',domain= self.m_o_e ,  ip_str = "128.193.23.1", ip_type='4')

        rec1 = AddressRecord( label = 'foo',domain= self.m_o_e ,  ip_str = "128.193.26.7", ip_type='4')
        # BAD Names
        self.assertRaises( ValidationError,self.do_update_A_record,**{'record': rec1,'new_name': ".","new_ip": None})
        self.assertRaises( ValidationError,self.do_update_A_record,**{'record': rec0,'new_name': " sdfsa ","new_ip": None})
        self.assertRaises( ValidationError,self.do_update_A_record,**{'record': rec0,'new_name': "asdf.","new_ip": None})

        # BAD IPs
        self.assertRaises( ValidationError,self.do_update_A_record,**{'record': rec0,'new_name': None,"new_ip": 71134})
        self.assertRaises( ValidationError,self.do_update_A_record,**{'record': rec0,'new_name': None,"new_ip": "19.193.23.1.2"})
        self.assertRaises( ValidationError,self.do_update_A_record,**{'record': rec0,'new_name': None,"new_ip": 12314123})
        self.assertRaises( ValidationError,self.do_update_A_record,**{'record': rec0,'new_name': "narf","new_ip": 1214123})
        self.assertRaises( ValidationError,self.do_update_A_record,**{'record': rec0,'new_name': "%asdfsaf","new_ip": "1928.193.23.1"})
        self.assertRaises( ValidationError,self.do_update_A_record,**{'record': rec0,'new_name': None,"new_ip": "1928.193.23.1"})

    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})


    ######################
    ### Removing Tests ###
    ######################
    def do_remove_A_record(self, aname, domain, ip ):
        aret = AddressRecord( label = aname, domain=domain, ip_str=ip, ip_type='4')
        aret.save()
        self.assertTrue(aret)

        aret.delete()

        aret  = AddressRecord.objects.filter( label = aname, domain = domain, ip_str=ip)
        self.assertFalse(aret)

    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_remove_A_address_records(self):
        self.do_remove_A_record("", self.o_e, "128.193.10.1" )
        self.do_remove_A_record("far", self.o_e, "128.193.0.2" )
        self.do_remove_A_record("fetched", self.o_e, "128.193.1.1" )
        self.do_remove_A_record("drum", self.o_e, "128.193.2.1" )
        self.do_remove_A_record("and", self.o_e, "128.193.0.3" )
        self.do_remove_A_record("bass", self.o_e, "128.193.2.2" )
        self.do_remove_A_record("dude", self.o_e, "128.193.5.1" )
        self.do_remove_A_record("man", self.o_e, "128.193.1.4" )
        self.do_remove_A_record("right", self.o_e, "128.193.2.6" )
        self.do_remove_A_record("", self.f_o_e, "128.193.0.1" )
        self.do_remove_A_record("far", self.f_o_e, "128.193.0.2" )
        self.do_remove_A_record("fetched", self.f_o_e, "128.193.1.1" )
        self.do_remove_A_record("drum", self.f_o_e, "128.193.2.1" )
        self.do_remove_A_record("and", self.f_o_e, "128.193.0.3" )
        self.do_remove_A_record("bass", self.f_o_e, "128.193.2.2" )
        self.do_remove_A_record("dude", self.f_o_e, "128.193.5.1" )
        self.do_remove_A_record("man", self.f_o_e, "128.193.1.4" )
        self.do_remove_A_record("right", self.f_o_e, "128.193.2.6" )

    def test_remove_AAAA_address_records(self):
        osu_block = "4620:105:F000:"
        boot_strap_ipv6_reverse_domain("4.6.2.0")
        self.do_remove_AAAA_record("", self.o_e, osu_block+":1" )
        self.do_remove_AAAA_record("please", self.o_e, osu_block+":2" )
        self.do_remove_AAAA_record("visit", self.o_e, osu_block+":4" )
        self.do_remove_AAAA_record("from", self.o_e, osu_block+":2" )
        self.do_remove_AAAA_record("either", self.o_e, osu_block+":1" )
        self.do_remove_AAAA_record("webpages", self.o_e, osu_block+":1" )
        self.do_remove_AAAA_record("read", self.o_e, osu_block+":1" )
        self.do_remove_AAAA_record("", self.f_o_e, osu_block+":1" )
        self.do_remove_AAAA_record("please", self.f_o_e, osu_block+":2" )
        self.do_remove_AAAA_record("visit", self.f_o_e, osu_block+":4" )
        self.do_remove_AAAA_record("from", self.f_o_e, osu_block+":2" )
        self.do_remove_AAAA_record("either", self.f_o_e, osu_block+":1" )
        self.do_remove_AAAA_record("webpages", self.f_o_e, osu_block+":1" )
        self.do_remove_AAAA_record("read", self.f_o_e, osu_block+":1" )


    ####################
    ### Adding Tests ###
    ####################
    def do_add_record(self, data):
        rec = AddressRecord(label = data['label'], domain=data['domain'], ip_str=data['ip'], ip_type='4')
        rec.save()
        self.assertTrue(rec.__repr__())
        self.assertTrue(rec.get_absolute_url())
        self.assertTrue(rec.get_edit_url())
        self.assertTrue(rec.get_delete_url())
        self.assertTrue(rec.details())


        search = AddressRecord.objects.filter( label = data['label'], domain = data['domain'], ip_type='4', ip_str=data['ip'] )
        found = False
        for record in search:
            if record.ip_str == data['ip']:
                found = True
        self.assertTrue(found)

    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.get_absolute_url())
        self.assertTrue(rec.get_edit_url())
        self.assertTrue(rec.get_delete_url())
        self.assertTrue(rec.details())


    def test_add_A_address_records(self):
        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': '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 test_add_AAAA_address_records(self):
        osu_block = "2620:105:F000:"
        boot_strap_ipv6_reverse_domain("2.6.2.0")
        data = {'label': '','domain': self.f_o_e ,'ip': osu_block+":4"}
        self.do_add_record6( data )
        data = {'label': '','domain': self.o_e ,'ip': osu_block+":1"}
        self.do_add_record6( data )
        data = {'label': '6ba-r','domain': self.o_e ,'ip': osu_block+":6"}
        self.do_add_record6( data )
        data = {'label': '6ba-r','domain': self.f_o_e ,'ip': osu_block+":7"}
        self.do_add_record6( data )
        data = {'label': '6foo','domain': self.f_o_e ,'ip': osu_block+":5"}
        self.do_add_record6( data )
        data = {'label': '6foo','domain': self.o_e ,'ip': osu_block+":3"}
        self.do_add_record6( data )
        data = {'label': '6ba3z','domain': self.o_e ,'ip': osu_block+":4"}
        self.do_add_record6( data )
        data = {'label': '6ba3z','domain': self.f_o_e ,'ip': osu_block+":6"}
        self.do_add_record6( data )
        data = {'label': '6foob1ar','domain': self.o_e ,'ip': osu_block+":5"}
        self.do_add_record6( data )
        data = {'label': '6foob1ar','domain': self.f_o_e ,'ip': osu_block+":8"}
        self.do_add_record6( data )
        data = {'label': '23412341253254243','domain': self.f_o_e ,'ip': osu_block+":8"}
        self.do_add_record6( data )

    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_bad_A_ip(self):
        #IPv4 Tests
        osu_block = "2620:105:F000:"
        data = {'label': 'asdf0','domain': self.o_e ,'ip': osu_block+":1"}
        self.assertRaises(ValidationError ,self.do_add_record,data)

        data = {'label': 'asdf1','domain': self.o_e ,'ip': 123142314}
        self.assertRaises(ValidationError ,self.do_add_record,data)

        data = {'label': 'asdf1','domain': self.o_e ,'ip': "128.193.0.1.22"}
        self.assertRaises(ValidationError ,self.do_add_record,data)

        data = {'label': 'asdf2','domain': self.o_e ,'ip': "128.193.8"}
        self.assertRaises(ValidationError ,self.do_add_record,data)


    def test_bad_AAAA_ip(self):
        # IPv6 Tests
        osu_block = "2620:105:F000:"
        data = {'label': 'asdf5','domain': self.o_e ,'ip': "128.193.8.1"}
        self.assertRaises(ValidationError ,self.do_add_record6, data)
        data = {'label': 'asdf4','domain': self.o_e ,'ip': osu_block+":::"}
        self.assertRaises(ValidationError ,self.do_add_record6, data)

        data = {'label': 'asdf4','domain': self.o_e ,'ip': 123213487823762347612346}
        self.assertRaises(ValidationError ,self.do_add_record6,data)


    def test_add_A_records_exist(self):
        data = {'label': '','domain': self.f_o_e ,'ip':"128.193.0.2" }
        self.do_add_record(data)
        self.assertRaises(ValidationError ,self.do_add_record,data)


        data = {'label': 'new','domain': self.f_o_e ,'ip':"128.193.0.2" }
        self.do_add_record(data)
        self.assertRaises(ValidationError ,self.do_add_record,data)


    def test_add_AAAA_records_exist(self):
        osu_block = "9620:105:F000:"
        boot_strap_ipv6_reverse_domain("9.6.2.0")

        data = {'label': 'new','domain': self.f_o_e ,'ip':osu_block+":2"}
        self.do_add_record6(data)
        self.assertRaises(ValidationError ,self.do_add_record6,data)

        data = {'label': 'new','domain': self.f_o_e ,'ip':osu_block+":0:9"}
        self.do_add_record6(data)
        self.assertRaises(ValidationError ,self.do_add_record6,data)


        data = {'label': 'nope','domain': self.o_e ,'ip':osu_block+":4"}
        self.do_add_record6(data)
        self.assertRaises(ValidationError ,self.do_add_record6,data)

    def test_add_A_invalid_address_records(self):

        data = {'label': "oregonstate",'domain': self.e,'ip': "128.193.0.2"}
        self.assertRaises(ValidationError ,self.do_add_record, data)

        data = {'label': "foo",'domain': self.o_e,'ip': "128.193.0.2"}
        self.assertRaises(ValidationError ,self.do_add_record, data)

        data = {'label': 'foo.nas','domain': self.o_e ,'ip':"128.193.0.2" }
        self.assertRaises(ValidationError ,self.do_add_record, data)

        data = {'label': 'foo.bar.nas','domain': self.o_e ,'ip':"128.193.0.2" }
        self.assertRaises(ValidationError ,self.do_add_record, data)

        data = {'label': 'foo.baz.bar.nas','domain': self.o_e ,'ip':"128.193.0.2" }
        self.assertRaises(ValidationError ,self.do_add_record, data)

        data = {'label': 'n as','domain': self.o_e ,'ip':"128.193.0.2" }
        self.assertRaises(ValidationError ,self.do_add_record, data)

        data = {'label': 'n as','domain': self.o_e ,'ip':"128.193.0.2" }
        self.assertRaises(ValidationError ,self.do_add_record, data)

        data = {'label': 'n%as','domain': self.o_e ,'ip':"128.193.0.2" }
        self.assertRaises(ValidationError ,self.do_add_record, data)

        data = {'label': 'n+as','domain': self.o_e ,'ip':"128.193.0.2" }
        self.assertRaises(ValidationError ,self.do_add_record, data)

    def test_add_AAAA_invalid_address_records(self):
        osu_block = "3620:105:F000:"
        boot_strap_ipv6_reverse_domain("3.6.2.0")

        data = {'label': 'foo.nas','domain': self.o_e ,'ip': osu_block+":1"}
        self.assertRaises(ValidationError ,self.do_add_record6, data)

        data = {'label': 'foo.bar.nas','domain': self.o_e ,'ip':osu_block+":2"}
        self.assertRaises(ValidationError ,self.do_add_record6, data)

        data = {'label': 'foo.baz.bar.nas','domain': self.o_e ,'ip':osu_block+":3"}
        self.assertRaises(ValidationError ,self.do_add_record6, data)

        data = {'label': 'n as','domain': self.o_e ,'ip':osu_block+":4"}
        self.assertRaises(ValidationError ,self.do_add_record6, data)

        data = {'label': 'n!+/*&%$#@as','domain': self.o_e ,'ip':osu_block+":5"}
        self.assertRaises(ValidationError ,self.do_add_record6, data)

        data = {'label': 'n%as','domain': self.o_e ,'ip':osu_block+":6"}
        self.assertRaises(ValidationError ,self.do_add_record6, data)

        data = {'label': 'n+as','domain': self.o_e ,'ip':osu_block+":7"}
        self.assertRaises(ValidationError ,self.do_add_record6, data)

    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()
Ejemplo n.º 19
0
class NSTestsModels(TestCase):
    def setUp(self):
        self.r = Domain( name = "ru" )
        self.r.save()
        self.f_r = Domain( name = "foo.ru" )
        self.f_r.save()
        self.b_f_r = Domain( name = "bar.foo.ru" )
        self.b_f_r.save()

        self.f = Domain( name = "fam" )
        self.f.save()

        self._128 = ReverseDomain( name = '128', ip_type= '4' )
        self._128.save()

    def do_add(self, domain, server):
        ns = Nameserver( domain = domain, server = server)
        ns.save()
        ns.save()
        self.assertTrue(ns.__repr__())
        self.assertTrue(ns.details())
        self.assertTrue(ns.get_absolute_url())
        self.assertTrue(ns.get_edit_url())
        self.assertTrue(ns.get_delete_url())
        ret = Nameserver.objects.filter( domain = domain, server = server )
        self.assertEqual( len(ret), 1 )
        return ns

    def test_add_TLD(self):
        data = { 'domain':self.r , 'server':'bar.foo.ru' }
        self.assertRaises( ValidationError, self.do_add, **data )

    def test_add_ns(self):
        data = { 'domain':self.r , 'server':'ns2.moot.ru' }
        self.do_add( **data )

        data = { 'domain':self.r , 'server':'ns5.moot.ru' }
        self.do_add( **data )

        data = { 'domain':self.r , 'server':u'ns3.moot.ru' }
        self.do_add( **data )

        data = { 'domain':self.b_f_r , 'server':'n1.moot.ru' }
        self.do_add( **data )

        data = { 'domain':self.b_f_r , 'server':'ns2.moot.ru' }
        self.do_add( **data )

        data = { 'domain':self.r , 'server':'asdf.asdf' }
        self.do_add( **data )

    def test_add_invalid(self):
        data = { 'domain':self.f_r , 'server':'ns3.foo.ru' }
        self.assertRaises( ValidationError, self.do_add, **data  )

    def testtest_add_ns_in_domain(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' }
        ns = self.do_add( **data )
        self.assertTrue( ns.glue )
        self.assertEqual( ns.server, ns.glue.fqdn )

        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_add_ns_outside_domain(self):
        data = { 'domain':self.f_r , 'server':'ns2.ru' }
        ns = self.do_add( **data )
        self.assertFalse( ns.glue )

    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 == 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 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 )

    def test_add_dup(self):
        data = { 'domain':self.r , 'server':'ns2.moot.ru' }
        self.do_add( **data )

        self.assertRaises( ValidationError, self.do_add, **data)
Ejemplo n.º 20
0
    def test_soa_validators(self):
        m = ReverseDomain( name = '8')
        m.save()

        f_m = ReverseDomain( name = '8.2')
        f_m.save()

        n_f_m = ReverseDomain( name = '8.2.3')
        n_f_m.save()

        b_m = ReverseDomain( name = '8.3')
        b_m.save()

        s = SOA( primary="ns1.foo.com", contact="asdf", comment="test")
        s.save()

        f_m.soa = s
        f_m.save()

        b_m.soa = s
        self.assertRaises(ValidationError, b_m.save)

        n_f_m = ReverseDomain.objects.get(pk=n_f_m.pk) # Refresh object
        n_f_m.soa = s
        n_f_m.save()

        m.soa = s
        m.save()

        b_m = ReverseDomain.objects.get(pk=b_m.pk) # Refresh object
        b_m.soa = s
        b_m.save()

        m.soa = None
        self.assertRaises(ValidationError, m.save)

        s2 = SOA( primary="ns1.foo.com", contact="asdf", comment="test2")
        s2.save()

        m.soa = s2
        self.assertRaises(ValidationError, m.save)
Ejemplo n.º 21
0
    def test_delegation_add_domain(self):
        dom = ReverseDomain( name = '3', delegated=True )
        dom.save()

        dom = ReverseDomain( name = '3.4', delegated=False )
        self.assertRaises(ValidationError, dom.save)
Ejemplo n.º 22
0
    def test_master_reverse_ipv6_domains(self):
        rds = []
        rd = ReverseDomain(name='1', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6.5', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6.5.6', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6.5.6.7', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6.5.6.7.0', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6.5.6.7.0.0', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6.5.6.7.0.0.0', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6.5.6.7.0.0.0.0', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6.5.6.7.0.0.0.0.0', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6.5.6.7.0.0.0.0.0.0', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6.5.6.7.0.0.0.0.0.0.0', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6.5.6.7.0.0.0.0.0.0.0.0', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6.5.6.7.0.0.0.0.0.0.0.0.0', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6.5.6.7.0.0.0.0.0.0.0.0.0.0', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6.5.6.7.0.0.0.0.0.0.0.0.0.0.0', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6.5.6.7.0.0.0.0.0.0.0.0.0.0.0.0', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6.5.6.7.0.0.0.0.0.0.0.0.0.0.0.0.3', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6.5.6.7.0.0.0.0.0.0.0.0.0.0.0.0.3.2', ip_type='6')
        rd.save()
        rds.append(rd)

        rd = ReverseDomain(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6.5.6.7.0.0.0.0.0.0.0.0.0.0.0.0.3.2.1', ip_type='6')
        rd.save()
        rds.append(rd)

        for rd in list(enumerate(rds)):
            if rd[0] == 0:
                self.assertEqual(rd[1].master_reverse_domain, None)
            else:
                self.assertEqual(rd[1].master_reverse_domain, rds[rd[0]-1])
            self.assertTrue(rd[1].get_absolute_url())
            self.assertTrue(rd[1].get_edit_url())
            self.assertTrue(rd[1].get_delete_url())

        try:
            ReverseDomain.objects.filter(name='1.2.8.3.0.0.0.0.4.3.4.5.6.6.5.6.7.0.0', ip_type='6')[0].delete()
        except ValidationError, e:
            pass
Ejemplo n.º 23
0
        rd3 = ReverseDomain(name = '128.193.8', ip_type='4')
        rd3.save()
        self.assertEqual(rd3.master_reverse_domain, rd2)
        self.assertEqual(rd2.master_reverse_domain, rd1)
        self.assertEqual(rd1.master_reverse_domain, None)



    def test_add_reverse_domains(self):
        try:
            ReverseDomain(name='192.168',ip_type='4').save()
        except ValidationError, e:
            pass
        self.assertEqual(ValidationError, type(e))
        e = None
        rdx = ReverseDomain(name='192', ip_type='4')
        rdx.save()
        rdy = ReverseDomain(name='192.168',ip_type='4')
        rdy.save()
        try:
            ReverseDomain(name='192.168', ip_type='4').save()
        except ValidationError, e:
            pass
        self.assertEqual(ValidationError, type(e))
        e = None

        rd = ReverseDomain(name = '128', ip_type='4').save()
        rd0 = ReverseDomain(name = '128.193', ip_type='4')
        rd0.save()
        ip1 = self.add_ptr_ipv4('128.193.8.1')
        self.assertEqual(ip1.reverse_domain, rd0)
Ejemplo n.º 24
0
 def setUp(self):
     rd = ReverseDomain(name="66", ip_type="4")
     rd.save()
Ejemplo n.º 25
0
 def test_remove_invalid_reverse_domain(self):
     rd1 = ReverseDomain(name = '130', ip_type='4')
     rd1.save()
     rd2 = ReverseDomain(name = '130.193', ip_type='4')
     rd2.save()
     rd3 = ReverseDomain(name = '130.193.8', ip_type='4')
     rd3.save()
     try:
         rd1.delete()
     except ValidationError, e:
         pass
Ejemplo n.º 26
0
 def test_remove_reverse_domain(self):
     ReverseDomain(name='127',ip_type='4').save()
     rd1 = ReverseDomain(name = '127.193', ip_type='4')
     rd1.save()
     rd1.__repr__()
     rd1.__str__()
     rd2 = ReverseDomain(name = '127.193.8', ip_type='4')
     rd2.save()
     rd2.__repr__()
     rd2.__str__()
     ip1 = self.add_ptr_ipv4('127.193.8.1')
     self.assertEqual(ip1.reverse_domain, rd2)
     ip2 = self.add_ptr_ipv4('127.193.8.2')
     self.assertEqual(ip2.reverse_domain, rd2)
     ip3 = self.add_ptr_ipv4('127.193.8.3')
     self.assertEqual(ip3.reverse_domain, rd2)
     ip4 = self.add_ptr_ipv4('127.193.8.4')
     self.assertEqual(ip4.reverse_domain, rd2)
     rd2.delete()
     ptr1 = PTR.objects.filter(ip_lower = ipaddr.IPv4Address('127.193.8.1').__int__(), ip_type = '4')[0]
     self.assertEqual(ptr1.reverse_domain, rd1)
     ptr2 = PTR.objects.filter(ip_lower = ipaddr.IPv4Address('127.193.8.2').__int__(), ip_type = '4')[0]
     self.assertEqual(ptr2.reverse_domain, rd1)
     ptr3 = PTR.objects.filter(ip_lower = ipaddr.IPv4Address('127.193.8.2').__int__(), ip_type = '4')[0]
     self.assertEqual(ptr3.reverse_domain, rd1)
     ptr4 = PTR.objects.filter(ip_lower = ipaddr.IPv4Address('127.193.8.3').__int__(), ip_type = '4')[0]
     self.assertEqual(ptr4.reverse_domain, rd1)