Beispiel #1
0
    def runTest(self):
        """Add a user to a permissions group"""
        self._tester.go_to_admin("Permissions")
        tc.find('Manage Permissions')
        tc.formvalue('addsubj', 'sg_subject', 'authenticated')
        tc.formvalue('addsubj', 'sg_group', 'somegroup')
        tc.submit()
        authenticated = unicode_to_base64('authenticated')
        somegroup = unicode_to_base64('somegroup')
        tc.find('%s:%s' % (authenticated, somegroup))

        revoke_checkbox = '%s:%s' % (unicode_to_base64('anonymous'),
                                     unicode_to_base64('PERMISSION_GRANT'))
        tc.formvalue('addperm', 'gp_subject', 'anonymous')
        tc.formvalue('addperm', 'action', 'PERMISSION_GRANT')
        tc.submit()
        tc.find(revoke_checkbox)
        self._testenv.get_trac_environment().config.touch()
        self._tester.logout()
        self._tester.go_to_admin("Permissions")
        try:
            tc.formvalue('addsubj', 'sg_subject', 'someuser')
            tc.formvalue('addsubj', 'sg_group', 'authenticated')
            tc.submit()
            tc.find("The subject someuser was not added to the "
                    "group authenticated because the group has "
                    "TICKET_CHGPROP permission and users cannot "
                    "grant permissions they don't possess.")
        finally:
            self._tester.login('admin')
            self._tester.go_to_admin("Permissions")
            tc.formvalue('revokeform', 'sel', revoke_checkbox)
            tc.submit()
            tc.notfind(revoke_checkbox)
Beispiel #2
0
    def runTest(self):
        """Add a user to a permissions group"""
        self._tester.go_to_admin("Permissions")
        tc.find('Manage Permissions')
        tc.formvalue('addsubj', 'sg_subject', 'authenticated')
        tc.formvalue('addsubj', 'sg_group', 'somegroup')
        tc.submit()
        authenticated = unicode_to_base64('authenticated')
        somegroup = unicode_to_base64('somegroup')
        tc.find('%s:%s' % (authenticated, somegroup))

        revoke_checkbox = '%s:%s' % (unicode_to_base64('anonymous'),
                                     unicode_to_base64('PERMISSION_GRANT'))
        tc.formvalue('addperm', 'gp_subject', 'anonymous')
        tc.formvalue('addperm', 'action', 'PERMISSION_GRANT')
        tc.submit()
        tc.find(revoke_checkbox)
        self._testenv.get_trac_environment().config.touch()
        self._tester.logout()
        self._tester.go_to_admin("Permissions")
        try:
            tc.formvalue('addsubj', 'sg_subject', 'someuser')
            tc.formvalue('addsubj', 'sg_group', 'authenticated')
            tc.submit()
            tc.find("The subject someuser was not added to the "
                    "group authenticated because the group has "
                    "TICKET_CHGPROP permission and users cannot "
                    "grant permissions they don't possess.")
        finally:
            self._tester.login('admin')
            self._tester.go_to_admin("Permissions")
            tc.formvalue('revokeform', 'sel', revoke_checkbox)
            tc.submit()
            tc.notfind(revoke_checkbox)
Beispiel #3
0
    def runTest(self):
        """Add a user to a permissions group"""
        self._tester.go_to_admin("Permissions")
        tc.find('Manage Permissions')
        tc.formvalue('addsubj', 'sg_subject', 'authenticated')
        tc.formvalue('addsubj', 'sg_group', 'somegroup')
        tc.submit()
        authenticated = unicode_to_base64('authenticated')
        somegroup = unicode_to_base64('somegroup')
        tc.find('%s:%s' % (authenticated, somegroup))

        revoke_checkbox = '%s:%s' % (unicode_to_base64('anonymous'),
                                     unicode_to_base64('PERMISSION_GRANT'))
        tc.formvalue('addperm', 'gp_subject', 'anonymous')
        tc.formvalue('addperm', 'action', 'PERMISSION_GRANT')
        tc.submit()
        tc.find(revoke_checkbox)
        self._testenv.get_trac_environment().config.touch()
        self._tester.logout()
        self._tester.go_to_admin("Permissions")
        try:
            tc.formvalue('addsubj', 'sg_subject', 'someuser')
            tc.formvalue('addsubj', 'sg_group', 'authenticated')
            tc.submit()
            tc.find("The subject <strong>someuser</strong> was not added "
                    "to the group <strong>authenticated</strong>. The group "
                    "has <strong>TICKET_CREATE</strong> permission and you "
                    "cannot grant permissions you don't possess.")
        finally:
            self._tester.login('admin')
            self._tester.go_to_admin("Permissions")
            tc.formvalue('revokeform', 'sel', revoke_checkbox)
            tc.submit()
            tc.notfind(revoke_checkbox)
Beispiel #4
0
 def runTest(self):
     """Remove a user from a permissions group"""
     self._tester.go_to_admin("Permissions")
     tc.find('Manage Permissions')
     authenticated = unicode_to_base64('authenticated')
     somegroup = unicode_to_base64('somegroup')
     tc.find('%s:%s' % (authenticated, somegroup))
     tc.formvalue('revokeform', 'sel', '%s:%s' % (authenticated, somegroup))
     tc.submit()
     tc.notfind('%s:%s' % (authenticated, somegroup))
Beispiel #5
0
 def runTest(self):
     """Create a permissions group"""
     self._tester.go_to_admin("Permissions")
     tc.find('Manage Permissions')
     tc.formvalue('addperm', 'gp_subject', 'somegroup')
     tc.formvalue('addperm', 'action', 'REPORT_CREATE')
     tc.submit()
     somegroup = unicode_to_base64('somegroup')
     REPORT_CREATE = unicode_to_base64('REPORT_CREATE')
     tc.find('%s:%s' % (somegroup, REPORT_CREATE))
Beispiel #6
0
 def runTest(self):
     """Remove a user from a permissions group"""
     self._tester.go_to_admin("Permissions")
     tc.find('Manage Permissions')
     authenticated = unicode_to_base64('authenticated')
     somegroup = unicode_to_base64('somegroup')
     tc.find('%s:%s' % (authenticated, somegroup))
     tc.formvalue('revokeform', 'sel', '%s:%s' % (authenticated, somegroup))
     tc.submit()
     tc.notfind('%s:%s' % (authenticated, somegroup))
Beispiel #7
0
 def runTest(self):
     """Create a permissions group"""
     self._tester.go_to_admin("Permissions")
     tc.find('Manage Permissions')
     tc.formvalue('addperm', 'gp_subject', 'somegroup')
     tc.formvalue('addperm', 'action', 'REPORT_CREATE')
     tc.submit()
     somegroup = unicode_to_base64('somegroup')
     REPORT_CREATE = unicode_to_base64('REPORT_CREATE')
     tc.find('%s:%s' % (somegroup, REPORT_CREATE))
Beispiel #8
0
 def runTest(self):
     """Remove a permissions group"""
     self._tester.go_to_admin("Permissions")
     tc.find('Manage Permissions')
     somegroup = unicode_to_base64('somegroup')
     REPORT_CREATE = unicode_to_base64('REPORT_CREATE')
     tc.find('%s:%s' % (somegroup, REPORT_CREATE))
     tc.formvalue('revokeform', 'sel', '%s:%s' % (somegroup, REPORT_CREATE))
     tc.submit()
     tc.notfind('%s:%s' % (somegroup, REPORT_CREATE))
     tc.notfind(somegroup)
Beispiel #9
0
 def runTest(self):
     """Add a user to a permissions group"""
     self._tester.go_to_admin()
     tc.follow('Permissions')
     tc.find('Manage Permissions')
     tc.formvalue('addsubj', 'sg_subject', 'authenticated')
     tc.formvalue('addsubj', 'sg_group', 'somegroup')
     tc.submit()
     authenticated = unicode_to_base64('authenticated')
     somegroup = unicode_to_base64('somegroup')
     tc.find('%s:%s' % (authenticated, somegroup))
Beispiel #10
0
 def runTest(self):
     """Add a user to a permissions group"""
     self._tester.go_to_admin()
     tc.follow('Permissions')
     tc.find('Manage Permissions')
     tc.formvalue('addsubj', 'sg_subject', 'authenticated')
     tc.formvalue('addsubj', 'sg_group', 'somegroup')
     tc.submit()
     authenticated = unicode_to_base64('authenticated')
     somegroup = unicode_to_base64('somegroup')
     tc.find('%s:%s' % (authenticated, somegroup))
Beispiel #11
0
 def runTest(self):
     """Remove a permissions group"""
     self._tester.go_to_admin("Permissions")
     tc.find('Manage Permissions')
     somegroup = unicode_to_base64('somegroup')
     REPORT_CREATE = unicode_to_base64('REPORT_CREATE')
     tc.find('%s:%s' % (somegroup, REPORT_CREATE))
     tc.formvalue('revokeform', 'sel', '%s:%s' % (somegroup, REPORT_CREATE))
     tc.submit()
     tc.notfind('%s:%s' % (somegroup, REPORT_CREATE))
     tc.notfind(somegroup)
Beispiel #12
0
 def test_to_and_from_base64_whitespace(self):
     # test that removing whitespace does not affect conversion
     text = 'a space: '
     text_base64 = unicode_to_base64(text)
     self.assertEqual('YSBzcGFjZTog', text_base64)
     self.assertEqual(text, unicode_from_base64(text_base64))
     text = 'two newlines: \n\n'
     text_base64 = unicode_to_base64(text)
     self.assertEqual('dHdvIG5ld2xpbmVzOiAKCg==', text_base64)
     self.assertEqual(text, unicode_from_base64(text_base64))
     text = 'a test string ' * 10000
     text_base64_strip = unicode_to_base64(text)
     text_base64_no_strip = unicode_to_base64(text, strip_newlines=False)
     self.assertNotEqual(text_base64_strip, text_base64_no_strip)
     self.assertEqual(text, unicode_from_base64(text_base64_strip))
     self.assertEqual(text, unicode_from_base64(text_base64_no_strip))
Beispiel #13
0
 def test_to_and_from_base64_whitespace(self):
     # test that removing whitespace does not affect conversion
     text = "a space: "
     text_base64 = unicode_to_base64(text)
     self.assertEqual("YSBzcGFjZTog", text_base64)
     self.assertEqual(text, unicode_from_base64(text_base64))
     text = "two newlines: \n\n"
     text_base64 = unicode_to_base64(text)
     self.assertEqual("dHdvIG5ld2xpbmVzOiAKCg==", text_base64)
     self.assertEqual(text, unicode_from_base64(text_base64))
     text = "a test string " * 10000
     text_base64_strip = unicode_to_base64(text)
     text_base64_no_strip = unicode_to_base64(text, strip_newlines=False)
     self.assertNotEqual(text_base64_strip, text_base64_no_strip)
     self.assertEqual(text, unicode_from_base64(text_base64_strip))
     self.assertEqual(text, unicode_from_base64(text_base64_no_strip))
Beispiel #14
0
    def runTest(self):
        """Tests for the Copy Permissions functionality
        added in http://trac.edgewall.org/ticket/11099."""
        checkbox_value = lambda s, p: '%s:%s' % (unicode_to_base64(s),
                                                 unicode_to_base64(p))
        grant_msg = "The subject %s has been granted the permission %s\."

        def grant_permission(subject, action):
            tc.formvalue('addperm', 'gp_subject', subject)
            tc.formvalue('addperm', 'action', action)
            tc.submit()
            tc.find(grant_msg % (subject, action))
            tc.find(checkbox_value(subject, action))

        env = self._testenv.get_trac_environment()

        # Copy permissions from subject to target
        self._tester.go_to_admin('Permissions')
        perm_sys = PermissionSystem(env)
        anon_perms = perm_sys.store.get_user_permissions('anonymous')
        for perm in anon_perms:
            tc.find(checkbox_value('anonymous', perm))
            tc.notfind(checkbox_value('user1', perm))
        tc.formvalue('copyperm', 'cp_subject', 'anonymous')
        tc.formvalue('copyperm', 'cp_target', 'user1')
        tc.submit()
        for perm in anon_perms:
            tc.find("The subject user1 has been granted the permission %s\." %
                    perm)
            tc.find(checkbox_value('user1', perm))

        # Subject doesn't have any permissions
        tc.notfind(checkbox_value('noperms', ''))
        tc.formvalue('copyperm', 'cp_subject', 'noperms')
        tc.formvalue('copyperm', 'cp_target', 'user1')
        tc.submit()
        tc.find("The subject noperms does not have any permissions\.")

        # Subject belongs to group but doesn't directly have any permissions
        grant_permission('group1', 'TICKET_VIEW')
        tc.formvalue('addsubj', 'sg_subject', 'noperms')
        tc.formvalue('addsubj', 'sg_group', 'group1')
        tc.submit()
        tc.find("The subject noperms has been added to the group group1\.")

        tc.formvalue('copyperm', 'cp_subject', 'noperms')
        tc.formvalue('copyperm', 'cp_target', 'user1')
        tc.submit()
        tc.find("The subject noperms does not have any permissions\.")

        # Target uses reserved all upper-case form
        tc.formvalue('copyperm', 'cp_subject', 'noperms')
        tc.formvalue('copyperm', 'cp_target', 'USER1')
        tc.submit()
        tc.find("All upper-cased tokens are reserved for permission names\.")
        self._tester.go_to_admin("Permissions")

        # Subject users reserved all upper-case form
        tc.formvalue('copyperm', 'cp_subject', 'USER1')
        tc.formvalue('copyperm', 'cp_target', 'noperms')
        tc.submit()
        tc.find("All upper-cased tokens are reserved for permission names\.")
        self._tester.go_to_admin("Permissions")

        # Target already possess one of the permissions
        anon_perms = perm_sys.store.get_user_permissions('anonymous')
        for perm in anon_perms:
            tc.notfind(checkbox_value('user2', perm))
        grant_permission('user2', anon_perms[0])

        tc.formvalue('copyperm', 'cp_subject', 'anonymous')
        tc.formvalue('copyperm', 'cp_target', 'user2')
        tc.submit()

        tc.notfind("The subject <em>user2</em> has been granted the "
                   "permission %s\." % anon_perms[0])
        for perm in anon_perms[1:]:
            tc.find("The subject user2 has been granted the permission %s\." %
                    perm)
            tc.find(checkbox_value('user2', perm))

        # Subject has a permission that is no longer defined
        try:
            env.db_transaction("INSERT INTO permission VALUES (%s,%s)",
                               ('anonymous', 'NOTDEFINED_PERMISSION'))
        except env.db_exc.IntegrityError:
            pass
        env.config.touch()  # invalidate permission cache
        tc.reload()
        tc.find(checkbox_value('anonymous', 'NOTDEFINED_PERMISSION'))
        perm_sys = PermissionSystem(env)
        anon_perms = perm_sys.store.get_user_permissions('anonymous')
        for perm in anon_perms:
            tc.notfind(checkbox_value('user3', perm))

        tc.formvalue('copyperm', 'cp_subject', 'anonymous')
        tc.formvalue('copyperm', 'cp_target', 'user3')
        tc.submit()

        for perm in anon_perms:
            msg = grant_msg % ('user3', perm)
            if perm == 'NOTDEFINED_PERMISSION':
                tc.notfind(msg)
                tc.notfind(checkbox_value('user3', perm))
            else:
                tc.find(msg)
                tc.find(checkbox_value('user3', perm))
        perm_sys.revoke_permission('anonymous', 'NOTDEFINED_PERMISSION')

        # Actor doesn't posses permission
        grant_permission('anonymous', 'PERMISSION_GRANT')
        grant_permission('user3', 'TRAC_ADMIN')
        self._tester.logout()
        self._tester.go_to_admin("Permissions")

        try:
            tc.formvalue('copyperm', 'cp_subject', 'user3')
            tc.formvalue('copyperm', 'cp_target', 'user4')
            tc.submit()

            perm_sys = PermissionSystem(env)
            for perm in [
                    perm[1] for perm in perm_sys.get_all_permissions()
                    if perm[0] == 'user3' and perm[1] != 'TRAC_ADMIN'
            ]:
                tc.find(grant_msg % ('user4', perm))
            tc.notfind("The permission TRAC_ADMIN was not granted to user4 "
                       "because users cannot grant permissions they don't "
                       "possess.")
        finally:
            self._testenv.revoke_perm('anonymous', 'PERMISSION_GRANT')
            self._tester.login('admin')
Beispiel #15
0
 def test_to_and_from_base64_unicode(self):
     text = u'Trac は ØÆÅ'
     text_base64 = unicode_to_base64(text)
     self.assertEqual('VHJhYyDjga8gw5jDhsOF', text_base64)
     self.assertEqual(text, unicode_from_base64(text_base64))
Beispiel #16
0
    def runTest(self):
        """Tests for the Copy Permissions functionality
        added in http://trac.edgewall.org/ticket/11099."""
        checkbox_value = lambda s, p: '%s:%s' % (unicode_to_base64(s),
                                                 unicode_to_base64(p))
        grant_msg = "The subject %s has been granted the permission %s\."
        def grant_permission(subject, action):
            tc.formvalue('addperm', 'gp_subject', subject)
            tc.formvalue('addperm', 'action', action)
            tc.submit()
            tc.find(grant_msg % (subject, action))
            tc.find(checkbox_value(subject, action))

        env = self._testenv.get_trac_environment()

        # Copy permissions from subject to target
        self._tester.go_to_admin('Permissions')
        perm_sys = PermissionSystem(env)
        anon_perms = perm_sys.store.get_user_permissions('anonymous')
        for perm in anon_perms:
            tc.find(checkbox_value('anonymous', perm))
            tc.notfind(checkbox_value('user1', perm))
        tc.formvalue('copyperm', 'cp_subject', 'anonymous')
        tc.formvalue('copyperm', 'cp_target', 'user1')
        tc.submit()
        for perm in anon_perms:
            tc.find("The subject user1 has been granted the permission %s\."
                    % perm)
            tc.find(checkbox_value('user1', perm))

        # Subject doesn't have any permissions
        tc.notfind(checkbox_value('noperms', ''))
        tc.formvalue('copyperm', 'cp_subject', 'noperms')
        tc.formvalue('copyperm', 'cp_target', 'user1')
        tc.submit()
        tc.find("The subject noperms does not have any permissions\.")

        # Subject belongs to group but doesn't directly have any permissions
        grant_permission('group1', 'TICKET_VIEW')
        tc.formvalue('addsubj', 'sg_subject', 'noperms')
        tc.formvalue('addsubj', 'sg_group', 'group1')
        tc.submit()
        tc.find("The subject noperms has been added to the group group1\.")

        tc.formvalue('copyperm', 'cp_subject', 'noperms')
        tc.formvalue('copyperm', 'cp_target', 'user1')
        tc.submit()
        tc.find("The subject noperms does not have any permissions\.")

        # Target uses reserved all upper-case form
        tc.formvalue('copyperm', 'cp_subject', 'noperms')
        tc.formvalue('copyperm', 'cp_target', 'USER1')
        tc.submit()
        tc.find("All upper-cased tokens are reserved for permission names\.")
        self._tester.go_to_admin("Permissions")

        # Subject users reserved all upper-case form
        tc.formvalue('copyperm', 'cp_subject', 'USER1')
        tc.formvalue('copyperm', 'cp_target', 'noperms')
        tc.submit()
        tc.find("All upper-cased tokens are reserved for permission names\.")
        self._tester.go_to_admin("Permissions")

        # Target already possess one of the permissions
        anon_perms = perm_sys.store.get_user_permissions('anonymous')
        for perm in anon_perms:
            tc.notfind(checkbox_value('user2', perm))
        grant_permission('user2', anon_perms[0])

        tc.formvalue('copyperm', 'cp_subject', 'anonymous')
        tc.formvalue('copyperm', 'cp_target', 'user2')
        tc.submit()

        tc.notfind("The subject <em>user2</em> has been granted the "
                   "permission %s\." % anon_perms[0])
        for perm in anon_perms[1:]:
            tc.find("The subject user2 has been granted the permission %s\."
                    % perm)
            tc.find(checkbox_value('user2', perm))

        # Subject has a permission that is no longer defined
        try:
            env.db_transaction("INSERT INTO permission VALUES (%s,%s)",
                               ('anonymous', 'NOTDEFINED_PERMISSION'))
        except env.db_exc.IntegrityError:
            pass
        env.config.touch()  # invalidate permission cache
        tc.reload()
        tc.find(checkbox_value('anonymous', 'NOTDEFINED_PERMISSION'))
        perm_sys = PermissionSystem(env)
        anon_perms = perm_sys.store.get_user_permissions('anonymous')
        for perm in anon_perms:
            tc.notfind(checkbox_value('user3', perm))

        tc.formvalue('copyperm', 'cp_subject', 'anonymous')
        tc.formvalue('copyperm', 'cp_target', 'user3')
        tc.submit()

        for perm in anon_perms:
            msg = grant_msg % ('user3', perm)
            if perm == 'NOTDEFINED_PERMISSION':
                tc.notfind(msg)
                tc.notfind(checkbox_value('user3', perm))
            else:
                tc.find(msg)
                tc.find(checkbox_value('user3', perm))
        perm_sys.revoke_permission('anonymous', 'NOTDEFINED_PERMISSION')

        # Actor doesn't posses permission
        grant_permission('anonymous', 'PERMISSION_GRANT')
        grant_permission('user3', 'TRAC_ADMIN')
        self._tester.logout()
        self._tester.go_to_admin("Permissions")

        try:
            tc.formvalue('copyperm', 'cp_subject', 'user3')
            tc.formvalue('copyperm', 'cp_target', 'user4')
            tc.submit()

            perm_sys = PermissionSystem(env)
            for perm in [perm[1] for perm in perm_sys.get_all_permissions()
                                 if perm[0] == 'user3'
                                 and perm[1] != 'TRAC_ADMIN']:
                tc.find(grant_msg % ('user4', perm))
            tc.notfind("The permission TRAC_ADMIN was not granted to user4 "
                       "because users cannot grant permissions they don't "
                       "possess.")
        finally:
            self._testenv.revoke_perm('anonymous', 'PERMISSION_GRANT')
            self._tester.login('admin')
Beispiel #17
0
 def test_to_and_from_base64_unicode(self):
     text = u"Trac は ØÆÅ"
     text_base64 = unicode_to_base64(text)
     self.assertEqual("VHJhYyDjga8gw5jDhsOF", text_base64)
     self.assertEqual(text, unicode_from_base64(text_base64))