Edgewall Software

Opened 11 years ago

Last modified 7 years ago

#11272 closed enhancement

Improve error handling and reporting for AuthzPolicy — at Version 1

Reported by: Ryan J Ollos Owned by: Ryan J Ollos
Priority: normal Milestone: 1.0.2
Component: general Version: 1.0-stable
Severity: normal Keywords: authzpolicy, exception
Cc: Jun Omae Branch:
Release Notes:
API Changes:
Internal Changes:

Description (last modified by Ryan J Ollos)

We can improve error handling and reporting for 3 scenarios that may be seen when using the AuthzPolicy.

  1. When an authz file has duplicated sections, Trac generates an internal error with a traceback:
    Traceback (most recent call last):
      File "/home/user/Workspace/t8976/teo-rjollos.git/trac/web/main.py", line 497, in _dispatch_request
        dispatcher.dispatch(req)
      File "/home/user/Workspace/t8976/teo-rjollos.git/trac/web/main.py", line 214, in dispatch
        resp = chosen_handler.process_request(req)
      File "/home/user/Workspace/t8976/teo-rjollos.git/trac/wiki/web_ui.py", line 126, in process_request
        req.perm(page.resource).require('WIKI_VIEW')
      File "/home/user/Workspace/t8976/teo-rjollos.git/trac/perm.py", line 578, in require
        if not self._has_permission(action, resource):
      File "/home/user/Workspace/t8976/teo-rjollos.git/trac/perm.py", line 570, in _has_permission
        check_permission(action, perm.username, resource, perm)
      File "/home/user/Workspace/t8976/teo-rjollos.git/trac/perm.py", line 462, in check_permission
        perm)
      File "/home/user/Workspace/t8976/teo-rjollos.git/tracopt/perm/authz_policy.py", line 147, in check_permission
        self.parse_authz()
      File "/home/user/Workspace/t8976/teo-rjollos.git/tracopt/perm/authz_policy.py", line 176, in parse_authz
        self.authz = ConfigObj(self.get_authz_file(), encoding='utf8')
      File "/usr/lib/python2.7/dist-packages/configobj.py", line 1230, in __init__
        self._load(infile, configspec)
      File "/usr/lib/python2.7/dist-packages/configobj.py", line 1320, in _load
        raise error
    ConfigObjError: Parsing failed with several errors.
    First error at line 4.
    
    Though the duplicate sections error is easy to reproduce, the proposed change should trap and present a user-friendly error message when any exception is thrown while ConfigObj is parsing the file (by trapping all ConfigObjErrors).
  2. When the authz file is not found, Trac generates an internal error with a traceback:
    Traceback (most recent call last):
      File "/home/user/Workspace/t11260/teo-rjollos.git/trac/web/main.py", line 497, in _dispatch_request
        dispatcher.dispatch(req)
      File "/home/user/Workspace/t11260/teo-rjollos.git/trac/web/main.py", line 214, in dispatch
        resp = chosen_handler.process_request(req)
      File "/home/user/Workspace/t11260/teo-rjollos.git/trac/wiki/web_ui.py", line 126, in process_request
        req.perm(page.resource).require('WIKI_VIEW')
      File "/home/user/Workspace/t11260/teo-rjollos.git/trac/perm.py", line 578, in require
        if not self._has_permission(action, resource):
      File "/home/user/Workspace/t11260/teo-rjollos.git/trac/perm.py", line 570, in _has_permission
        check_permission(action, perm.username, resource, perm)
      File "/home/user/Workspace/t11260/teo-rjollos.git/trac/perm.py", line 462, in check_permission
        perm)
      File "/home/user/Workspace/t11260/teo-rjollos.git/tracopt/perm/authz_policy.py", line 149, in check_permission
        self.parse_authz()
      File "/home/user/Workspace/t11260/teo-rjollos.git/tracopt/perm/authz_policy.py", line 211, in parse_authz
        self.authz_mtime = self.get_authz_file_mtime
      File "/home/user/Workspace/t11260/teo-rjollos.git/tracopt/perm/authz_policy.py", line 178, in get_authz_file_mtime
        return os.path.getmtime(self.get_authz_file())
      File "/home/user/Workspace/t11260/lib/python2.7/genericpath.py", line 54, in getmtime
        return os.stat(filename).st_mtime
    OSError: [Errno 2] No such file or directory: '/home/user/Workspace/t11260/tracdev/conf/authzpolicy?.conf'
    
  3. If there is an error in the configuration of permission policies, for example: permission_policies = AuthzPermissionPolicy, DefaultPermissionPolicy, LegacyAttachmentPolicy (the first entry should be AuthzPolicy), no error is reported. There should at least be a warning in the logs.

While ExtensionOption throw an exception when the specified implementation of the interface can't be found, OrderedExtensionOption does not. Changing the behavior of OrderedExtensionOption will have to be carefully considered.

Change History (1)

comment:1 by Ryan J Ollos, 11 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.