예제 #1
0
파일: tests.py 프로젝트: Ziaunys/chili
    def test_soa_perms(self):
        """
        Test SOA perms
        """
        self.setup_request()

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

        # initialize obj into ctnrs
        obj = SOA()
        obj.primary = '192.168.1.1'
        obj.contact = '192.168.1.1'
        obj.save()
        domain = Domain(id=None, name='foo')
        domain.soa = obj
        domain.save()
        self.ctnr_admin.domains.add(domain)
        self.ctnr_user.domains.add(domain)
        self.ctnr_guest.domains.add(domain)
        self.save_all_ctnrs()

        self.check_perms_each_user(obj, perm_table)
예제 #2
0
파일: test_perms.py 프로젝트: jirwin/cyder
    def test_soa_perms(self):
        """
        Test SOA perms
        """
        self.setup_request()

        perm_table = {
            'cyder_admin': ['all'],
            'admin': [cy.ACTION_VIEW],
            'user': [cy.ACTION_VIEW],
            'guest': [cy.ACTION_VIEW],
        }

        # initialize obj into ctnrs
        obj = SOA()
        obj.primary = '192.168.1.1'
        obj.contact = '192.168.1.1'
        obj.save()
        domain = Domain(id=None, name='foo')
        domain.soa = obj
        domain.save()
        self.ctnr_admin.domains.add(domain)
        self.ctnr_user.domains.add(domain)
        self.ctnr_guest.domains.add(domain)
        self.save_all_ctnrs()

        self.check_perms_each_user(obj, perm_table)
예제 #3
0
파일: tests.py 프로젝트: osunws/cyder
    def test_ctnr_soa(self):
        """
        Test being in ctnr /w soa record gives appropriate perms
        """
        request = HttpRequest()
        request.user = self.test_user
        request.session = SessionStore()
        request.session['ctnr'] = self.ctnr

        # create domain with soa, add domain to ctnr
        soa = SOA()
        soa.primary = '192.168.1.1'
        soa.contact = '192.168.1.1'
        soa.save()

        domain = Domain(id=None, name='foo')
        domain.soa = soa
        domain.save()

        self.ctnr.domains.add(domain)
        self.ctnr.save()

        self.ctnr_admin.domains.add(domain)
        self.ctnr_admin.save()

        # checks where user is not admin
        has_perm = self.test_user.get_profile().has_perm(request, soa, write=False)
        self.assertTrue(has_perm, 'user should have read access')
        has_perm = self.test_user.get_profile().has_perm(request, soa, 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, soa, write=False)
        self.assertTrue(has_perm, 'user should have read access')
        has_perm = self.test_user.get_profile().has_perm(request, soa, 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, soa, write=False)
        self.assertFalse(has_perm, 'user should not have read access')
        has_perm = self.test_user.get_profile().has_perm(request, soa, write=True)
        self.assertFalse(has_perm, 'user should not have write access')
예제 #4
0
    def gen_SOA(self):
        """Generates an SOA record object if the SOA record exists.

        :uniqueness: primary, contact, refresh, retry, expire, minimum, comment
        """
        if self.domain_id is None:
            return None

        cursor.execute("SELECT primary_master, hostmaster, refresh, "
                       "retry, expire, ttl "
                       "FROM soa "
                       "WHERE domain = %s" % self.domain_id)
        record = cursor.fetchone()

        if record:
            primary, contact, refresh, retry, expire, minimum = record
            primary, contact = primary.lower(), contact.lower()

            try:
                soa = SOA.objects.get(root_domain=self.domain)
            except SOA.DoesNotExist:
                soa = SOA()

            soa.primary = primary
            soa.contact = contact
            soa.refresh = refresh
            soa.retry = retry
            soa.expire = expire
            soa.minimum = minimum
            soa.root_domain = self.domain
            soa.description = ''
            soa.save()

            return soa
        else:
            master_domain = self.domain.master_domain
            if master_domain and master_domain.soa:
                soa = master_domain.soa
            else:
                print "WARNING: No SOA exists for %s." % self.domain.name
                return None

        return soa
예제 #5
0
    def gen_SOA(self):
        """Generates an SOA record object if the SOA record exists.

        :uniqueness: primary, contact, refresh, retry, expire, minimum, comment
        """
        if self.domain_id is None:
            return None

        cursor.execute("SELECT primary_master, hostmaster, refresh, "
                       "retry, expire, ttl "
                       "FROM soa "
                       "WHERE domain = %s" % self.domain_id)
        record = cursor.fetchone()

        if record:
            primary, contact, refresh, retry, expire, minimum = record
            primary, contact = primary.lower(), contact.lower()

            try:
                soa = SOA.objects.get(root_domain=self.domain)
            except SOA.DoesNotExist:
                soa = SOA()

            soa.primary = primary
            soa.contact = contact
            soa.refresh = refresh
            soa.retry = retry
            soa.expire = expire
            soa.minimum = minimum
            soa.root_domain = self.domain
            soa.description = ''
            soa.save()

            return soa
        else:
            master_domain = self.domain.master_domain
            if master_domain and master_domain.soa:
                soa = master_domain.soa
            else:
                print "WARNING: No SOA exists for %s." % self.domain.name
                return None

        return soa
예제 #6
0
    def test_soa_perms(self):
        """Test SOA perms"""
        self.setup_request()

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

        # initialize obj into ctnrs
        domain = Domain(id=None, name='foo')
        domain.save()
        obj = SOA(root_domain=domain)
        obj.primary = 'foo.bar'
        obj.contact = 'foo.gaz'
        obj.save()
        self.ctnr_admin.domains.add(domain)
        self.ctnr_user.domains.add(domain)
        self.ctnr_guest.domains.add(domain)
        self.save_all_ctnrs()

        self.check_perms_each_user(obj, perm_table)