tlsfuzzer/tlsfuzzer

View on GitHub
tlsfuzzer/runner.py

Summary

Maintainability
C
1 day
Test Coverage
A
98%

Function run has a Cognitive Complexity of 57 (exceeds 10 allowed). Consider refactoring.
Open

    def run(self):
        """Execute conversation"""
        node = self.conversation
        try:
            while node is not None:
Severity: Minor
Found in tlsfuzzer/runner.py - About 1 day 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

Cyclomatic complexity is too high in method run. (27)
Open

    def run(self):
        """Execute conversation"""
        node = self.conversation
        try:
            while node is not None:
Severity: Minor
Found in tlsfuzzer/runner.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

Cyclomatic complexity is too high in class Runner. (14)
Open

class Runner(object):
    """Test if sending a set of commands returns expected values"""

    def __init__(self, conversation):
        """Link conversation with runner"""
Severity: Minor
Found in tlsfuzzer/runner.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

Cyclomatic complexity is too high in function guess_response. (11)
Open

def guess_response(content_type, data, ssl2=False):
    """Guess which kind of message is in the record layer payload"""
    if content_type == ContentType.change_cipher_spec:
        if len(data) != 1:
            return "ChangeCipherSpec(invalid size)"
Severity: Minor
Found in tlsfuzzer/runner.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

Function guess_response has a Cognitive Complexity of 18 (exceeds 10 allowed). Consider refactoring.
Open

def guess_response(content_type, data, ssl2=False):
    """Guess which kind of message is in the record layer payload"""
    if content_type == ContentType.change_cipher_spec:
        if len(data) != 1:
            return "ChangeCipherSpec(invalid size)"
Severity: Minor
Found in tlsfuzzer/runner.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

Avoid too many return statements within this function.
Open

            return "Handshake(invalid size)"
Severity: Major
Found in tlsfuzzer/runner.py - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

                return "Handshake({0})".format(SSL2HandshakeType.toStr(data[0]))
    Severity: Major
    Found in tlsfuzzer/runner.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

              return "ApplicationData(len={0})".format(len(data))
      Severity: Major
      Found in tlsfuzzer/runner.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                        return "Handshake(server_hello, hello_retry_request)"
        Severity: Major
        Found in tlsfuzzer/runner.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                      return "Handshake({0})".format(HandshakeType.toStr(data[0]))
          Severity: Major
          Found in tlsfuzzer/runner.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return ("Message(content_type={0}, first_byte={1}, "
            Severity: Major
            Found in tlsfuzzer/runner.py - About 30 mins to fix

              TODO found
              Open

                          # TODO put into a log
              Severity: Minor
              Found in tlsfuzzer/runner.py by fixme

              The backslash is redundant between brackets
              Open

                                                           guess_response(\
              Severity: Minor
              Found in tlsfuzzer/runner.py by pep8

              Avoid explicit line join between brackets.

              The preferred way of wrapping long lines is by using Python's
              implied line continuation inside parentheses, brackets and braces.
              Long lines can be broken over multiple lines by wrapping expressions
              in parentheses.  These should be used in preference to using a
              backslash for line continuation.
              
              E502: aaa = [123, \\n       123]
              E502: aaa = ("bbb " \\n       "ccc")
              
              Okay: aaa = [123,\n       123]
              Okay: aaa = ("bbb "\n       "ccc")
              Okay: aaa = "bbb " \\n    "ccc"
              Okay: aaa = 123  # \\

              Do not use bare 'except'
              Open

                      except:
              Severity: Minor
              Found in tlsfuzzer/runner.py by pep8

              When catching exceptions, mention specific exceptions when possible.

              Okay: except Exception:
              Okay: except BaseException:
              E722: except:

              The backslash is redundant between brackets
              Open

                      certificates = (msg for msg in self.handshake_messages if\
              Severity: Minor
              Found in tlsfuzzer/runner.py by pep8

              Avoid explicit line join between brackets.

              The preferred way of wrapping long lines is by using Python's
              implied line continuation inside parentheses, brackets and braces.
              Long lines can be broken over multiple lines by wrapping expressions
              in parentheses.  These should be used in preference to using a
              backslash for line continuation.
              
              E502: aaa = [123, \\n       123]
              E502: aaa = ("bbb " \\n       "ccc")
              
              Okay: aaa = [123,\n       123]
              Okay: aaa = ("bbb "\n       "ccc")
              Okay: aaa = "bbb " \\n    "ccc"
              Okay: aaa = 123  # \\

              Line too long (80 > 79 characters)
              Open

                                          raise AssertionError("Unexpected closure from peer")
              Severity: Minor
              Found in tlsfuzzer/runner.py by pep8

              Limit all lines to a maximum of 79 characters.

              There are still many devices around that are limited to 80 character
              lines; plus, limiting windows to 80 characters makes it possible to
              have several windows side-by-side.  The default wrapping on such
              devices looks ugly.  Therefore, please limit all lines to a maximum
              of 79 characters. For flowing long blocks of text (docstrings or
              comments), limiting the length to 72 characters is recommended.
              
              Reports error E501.

              Expected 2 blank lines, found 1
              Open

              class ConnectionState(object):
              Severity: Minor
              Found in tlsfuzzer/runner.py by pep8

              Separate top-level function and class definitions with two blank lines.

              Method definitions inside a class are separated by a single blank
              line.
              
              Extra blank lines may be used (sparingly) to separate groups of
              related functions.  Blank lines may be omitted between a bunch of
              related one-liners (e.g. a set of dummy implementations).
              
              Use blank lines in functions, sparingly, to indicate logical
              sections.
              
              Okay: def a():\n    pass\n\n\ndef b():\n    pass
              Okay: def a():\n    pass\n\n\nasync def b():\n    pass
              Okay: def a():\n    pass\n\n\n# Foo\n# Bar\n\ndef b():\n    pass
              Okay: default = 1\nfoo = 1
              Okay: classify = 1\nfoo = 1
              
              E301: class Foo:\n    b = 0\n    def bar():\n        pass
              E302: def a():\n    pass\n\ndef b(n):\n    pass
              E302: def a():\n    pass\n\nasync def b(n):\n    pass
              E303: def a():\n    pass\n\n\n\ndef b(n):\n    pass
              E303: def a():\n\n\n\n    pass
              E304: @decorator\n\ndef a():\n    pass
              E305: def a():\n    pass\na()
              E306: def a():\n    def b():\n        pass\n    def c():\n        pass

              There are no issues that match your filters.

              Category
              Status