edgewall/trac

View on GitHub
trac/web/auth.py

Summary

Maintainability
C
1 day
Test Coverage

File auth.py has 376 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
#
# Copyright (C) 2003-2023 Edgewall Software
# Copyright (C) 2003-2005 Jonas Borgström <jonas@edgewall.com>
# All rights reserved.
Severity: Minor
Found in trac/web/auth.py - About 5 hrs to fix

    Function _do_login has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def _do_login(self, req):
            """Log the remote user in.
    
            This function expects to be called when the remote user name
            is available. The user name is inserted into the `auth_cookie`
    Severity: Minor
    Found in trac/web/auth.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function load has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def load(self, filename):
            # FIXME use a logger
            self.hash = {}
            with open(filename, encoding='utf-8') as fd:
                for line in fd:
    Severity: Minor
    Found in trac/web/auth.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _redirect_back has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def _redirect_back(self, req):
            """Redirect the user back to the URL she came from."""
            referer = self._referer(req)
            if referer:
                if not referer.startswith(('http://', 'https://')):
    Severity: Minor
    Found in trac/web/auth.py - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function do_auth has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def do_auth(self, environ, start_response):
            header = environ.get('HTTP_AUTHORIZATION')
            if not header or not header.startswith('Digest'):
                self.send_auth_request(environ, start_response)
                return None
    Severity: Minor
    Found in trac/web/auth.py - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function load has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def load(self, filename):
            """Load account information from apache style htdigest files,
            only users from the specified realm are used
            """
            # FIXME use a logger
    Severity: Minor
    Found in trac/web/auth.py - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function do_auth has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def do_auth(self, environ, start_response):
            header = environ.get('HTTP_AUTHORIZATION')
            if header and header.startswith('Basic'):
                auth = str(b64decode(header[6:]), 'utf-8').split(':', 1)
                if len(auth) == 2:
    Severity: Minor
    Found in trac/web/auth.py - About 35 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Avoid too many return statements within this function.
    Open

                return False
    Severity: Major
    Found in trac/web/auth.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                  return None
      Severity: Major
      Found in trac/web/auth.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return auth['username']
        Severity: Major
        Found in trac/web/auth.py - About 30 mins to fix

          Function _do_logout has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def _do_logout(self, req):
                  """Log the user out.
          
                  Simply deletes the corresponding record from the auth_cookie
                  table.
          Severity: Minor
          Found in trac/web/auth.py - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          There are no issues that match your filters.

          Category
          Status