failmap/admin

View on GitHub

Showing 577 of 577 total issues

File test_zorgkaart.py has 481 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import logging

import websecmap
from websecmap.api.apis.zorgkaart import organization_and_url_import
from websecmap.organizations.models import Coordinate, Organization, OrganizationType, Url
Severity: Minor
Found in websecmap/api/tests/test_zorgkaart.py - About 7 hrs to fix

    File severity.py has 467 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    """
    Business logic that determines what points and calculations are stored.
    
    This file contains (or should) verbose explantion of why points are given.
    
    
    Severity: Minor
    Found in websecmap/reporting/severity.py - About 7 hrs to fix

      File admin.py has 466 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import logging
      from copy import deepcopy
      from datetime import datetime
      from typing import Dict, Any
      
      
      Severity: Minor
      Found in websecmap/map/admin.py - About 7 hrs to fix

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        Severity: Major
        Found in websecmap/scanners/management/commands/onboard_reset.py and 1 other location - About 6 hrs to fix
        websecmap/scanners/management/commands/onboard_forward.py on lines 0..25

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 109.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        Severity: Major
        Found in websecmap/scanners/management/commands/onboard_forward.py and 1 other location - About 6 hrs to fix
        websecmap/scanners/management/commands/onboard_reset.py on lines 0..29

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 109.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        File subdomains.py has 450 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import itertools
        import logging
        import random
        import string
        import tempfile
        Severity: Minor
        Found in websecmap/scanners/scanner/subdomains.py - About 6 hrs to fix

          Cyclomatic complexity is too high in function create_url_reports. (34)
          Open

          def create_url_reports(url: Url) -> List[UrlReport]:
              timeline = create_timeline(url)
              url_reports: List[Union[UrlReport, None]] = []
          
              """
          Severity: Minor
          Found in websecmap/reporting/report.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

          File tls_qualys.py has 425 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          """
          Manages endpoints:
           Protocols: https
           Ports: 443
           IP's: any related to a domain on mentioned protocols and ports.
          Severity: Minor
          Found in websecmap/scanners/scanner/tls_qualys.py - About 6 hrs to fix

            File forms.py has 401 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            import logging
            import time
            
            import tldextract
            from dal import autocomplete
            Severity: Minor
            Found in websecmap/game/forms.py - About 5 hrs to fix

              Cyclomatic complexity is too high in function calculate_high_level_stats. (28)
              Open

              @app.task(queue="reporting")
              def calculate_high_level_stats(days: int = 1, countries: List = None, organization_types: List = None):
                  log.info("Creating high_level_stats")
              
                  map_configurations = filter_map_configs(countries=countries, organization_types=organization_types)
              Severity: Minor
              Found in websecmap/map/report.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

              File admin.py has 394 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              from django.contrib import admin
              from django.utils.html import format_html
              from django.utils.safestring import mark_safe
              from import_export.admin import ImportExportModelAdmin
              from jet.admin import CompactInline
              Severity: Minor
              Found in websecmap/scanners/admin.py - About 5 hrs to fix

                File models.py has 390 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                # coding=UTF-8
                # from __future__ import unicode_literals
                
                import hashlib
                import logging
                Severity: Minor
                Found in websecmap/organizations/models.py - About 5 hrs to fix

                  Cyclomatic complexity is too high in function get_improvements. (27)
                  Open

                  def get_improvements(country, organization_type, weeks_back, weeks_duration):
                      # todo: adjustable timespan
                      # todo: adjustable weeks_back
                  
                      weeks_back = int(weeks_back)
                  Severity: Minor
                  Found in websecmap/map/logic/improvements.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

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                  def reflag_endpointgenericscan(type):
                      log.debug("Setting flags on EndpointGenericScan type: %s" % type)
                      EndpointGenericScan.objects.all().filter(type=type).update(is_the_latest_scan=False)
                  
                      # get the latest endpointgenericscans
                  Severity: Major
                  Found in websecmap/scanners/management/commands/set_latest_scan.py and 1 other location - About 5 hrs to fix
                  websecmap/scanners/management/commands/set_latest_scan.py on lines 28..49

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 86.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                  def reflag_urlgenericscan(type):
                      log.debug("Setting flags on UrlGenericScan type: %s" % type)
                      UrlGenericScan.objects.all().filter(type=type).update(is_the_latest_scan=False)
                  
                      # get the latest scans
                  Severity: Major
                  Found in websecmap/scanners/management/commands/set_latest_scan.py and 1 other location - About 5 hrs to fix
                  websecmap/scanners/management/commands/set_latest_scan.py on lines 52..73

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 86.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Cyclomatic complexity is too high in function calculate_forum_standaardisatie_views_mail. (25)
                  Open

                  def calculate_forum_standaardisatie_views_mail(scan_data):
                      # These values are published in the forum standaardisatie magazine.
                      custom_api_field_results = scan_data["results"]["custom"]
                  
                      # not all custom fields are defined yet, temporarily all will be false, these fields will be defined next week:

                  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 test_url_report. (25)
                  Open

                  def test_url_report(db):
                      # Url test.nl has been created
                      day_0 = datetime(day=1, month=1, year=2000, tzinfo=pytz.utc)
                      # First endpoint was created, first OK scan
                      day_1 = datetime(day=2, month=1, year=2000, tzinfo=pytz.utc)

                  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 get_map_data. (24)
                  Open

                  def get_map_data(
                      country: str = "NL", organization_type: str = "municipality", days_back: int = 0, displayed_issue: str = None
                  ):
                  
                      # A bug in the live version (possibly due to |safe) gives a Country(code='NL')} instead of
                  Severity: Minor
                  Found in websecmap/map/logic/map.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 analyze_result has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
                  Open

                  def analyze_result(result: List[str]):
                      """
                      All possible outcomes:
                      https://github.com/dotse/dnscheck/blob/5b0fce771259d9dfc03c6c69abba44f2be142c30/engine/t/config/policy.yaml
                  
                  
                  Severity: Minor
                  Found in websecmap/scanners/scanner/dnssec.py - About 4 hrs 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

                  Similar blocks of code found in 4 locations. Consider refactoring.
                  Open

                  class ExplainedEndpointIssues(models.Model):
                      """
                      Some issues can be explained. This counts the amount of explained issues on a single endpoint for all
                      explained scans below it.
                      """
                  Severity: Major
                  Found in websecmap/reporting/models.py and 3 other locations - About 4 hrs to fix
                  websecmap/reporting/models.py on lines 130..152
                  websecmap/reporting/models.py on lines 194..208
                  websecmap/reporting/models.py on lines 211..228

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 80.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Severity
                  Category
                  Status
                  Source
                  Language