コード例 #1
0
ファイル: auto_delete.py プロジェクト: Marlburo/inventory
    def test_ns_cleanup(self):
        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.poo"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.poo"))
        self.assertFalse(Domain.objects.filter(name="z.foo.poo"))
        self.assertTrue(Domain.objects.filter(name="foo.poo"))

        fqdn = "bar.x.y.z.foo.poo"
        label, the_domain = ensure_label_domain(fqdn)
        ns = Nameserver(domain=the_domain, server="asdfasffoo")
        ns.save()
        self.assertFalse(prune_tree(the_domain))
        ns.delete()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.poo"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.poo"))
        self.assertFalse(Domain.objects.filter(name="z.foo.poo"))
        self.assertTrue(Domain.objects.filter(name="foo.poo"))
    def test_basic_add_remove5(self):
        # Make sure all record types block
        f_c = create_fake_zone("foo.foo22", suffix="")
        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.foo22"
        label, the_domain = ensure_label_domain(fqdn)

        txt = TXT(label=label, domain=the_domain, txt_data="Nthing")
        txt.save()
        self.assertFalse(prune_tree(the_domain))
        txt.delete()

        label, the_domain = ensure_label_domain(fqdn)
        addr = AddressRecord(label=label,
                             domain=the_domain,
                             ip_type='4',
                             ip_str="10.2.3.4")
        addr.save()
        self.assertFalse(prune_tree(the_domain))
        addr.delete()

        label, the_domain = ensure_label_domain(fqdn)
        mx = MX(label=label, domain=the_domain, server="foo", priority=4)
        mx.save()
        self.assertFalse(prune_tree(the_domain))
        mx.delete()

        label, the_domain = ensure_label_domain(fqdn)
        ns = Nameserver(domain=the_domain, server="asdfasffoo")
        ns.save()
        self.assertFalse(prune_tree(the_domain))
        ns.delete()

        label, the_domain = ensure_label_domain(fqdn)
        srv = SRV(label='_' + label,
                  domain=the_domain,
                  target="foo",
                  priority=4,
                  weight=4,
                  port=34)
        srv.save()
        self.assertFalse(prune_tree(the_domain))
        srv.delete()
コード例 #3
0
ファイル: full_name.py プロジェクト: Marlburo/inventory
    def test_basic_add_remove5(self):
        # Make sure all record types block
        f_c = create_fake_zone("foo.foo22", suffix="")
        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.foo22"
        label, the_domain = ensure_label_domain(fqdn)

        txt = TXT(label=label, domain=the_domain, txt_data="Nthing")
        txt.save()
        self.assertFalse(prune_tree(the_domain))
        txt.delete()

        label, the_domain = ensure_label_domain(fqdn)
        addr = AddressRecord(label=label, domain=the_domain,
                             ip_type='4', ip_str="10.2.3.4")
        addr.save()
        self.assertFalse(prune_tree(the_domain))
        addr.delete()

        label, the_domain = ensure_label_domain(fqdn)
        mx = MX(label=label, domain=the_domain, server="foo", priority=4)
        mx.save()
        self.assertFalse(prune_tree(the_domain))
        mx.delete()

        label, the_domain = ensure_label_domain(fqdn)
        ns = Nameserver(domain=the_domain, server="asdfasffoo")
        ns.save()
        self.assertFalse(prune_tree(the_domain))
        ns.delete()

        label, the_domain = ensure_label_domain(fqdn)
        srv = SRV(
            label='_' + label, domain=the_domain, target="foo", priority=4,
            weight=4, port=34)
        srv.save()
        self.assertFalse(prune_tree(the_domain))
        srv.delete()
コード例 #4
0
ファイル: basic.py プロジェクト: caseybecking/inventory
    def test_no_ns_views(self):
        root_domain = create_fake_zone("12.88.in-addr.arpa", suffix="")
        self.assertEqual(1, root_domain.nameserver_set.all().count())
        ns = root_domain.nameserver_set.all()[0]
        self.assertTrue(self.private_view in ns.views.all())
        self.assertTrue(self.public_view in ns.views.all())

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

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

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

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

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

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

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

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

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

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

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

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

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

        ns1.delete()

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

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

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

        # We should now be able to remove the private view
        post_data = {'pk': ns.pk, 'views': ['no-private']}
        update_resp, post_data = self.generic_update(ns_url, post_data)
        ns = Nameserver.objects.get(pk=ns.pk)
        self.assertTrue(self.private_view not in ns.views.all())
        self.assertTrue(self.public_view not in ns.views.all())
コード例 #5
0
    def test_no_ns_views(self):
        root_domain = create_fake_zone("12.88.in-addr.arpa", suffix="")
        self.assertEqual(1, root_domain.nameserver_set.all().count())
        ns = root_domain.nameserver_set.all()[0]
        self.assertTrue(self.private_view in ns.views.all())
        self.assertTrue(self.public_view in ns.views.all())

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

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

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

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

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

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

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

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

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

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

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

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

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

        ns1.delete()

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

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

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

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