rapid7/metasploit-framework

View on GitHub
lib/msf/core/db_manager/cred.rb

Summary

Maintainability
F
3 days
Test Coverage

Method report_auth_info has a Cognitive Complexity of 58 (exceeds 5 allowed). Consider refactoring.
Open

  def report_auth_info(opts={})
    return if not active
    raise ArgumentError.new("Missing required option :host") if opts[:host].nil?
    raise ArgumentError.new("Missing required option :port") if (opts[:port].nil? and opts[:service].nil?)

Severity: Minor
Found in lib/msf/core/db_manager/cred.rb - 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

Method creds has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

  def creds(opts)
    query = nil
    ::ApplicationRecord.connection_pool.with_connection {
      # If :id exists we're looking for a specific record, skip the other stuff
      if opts[:id] && !opts[:id].to_s.empty?
Severity: Minor
Found in lib/msf/core/db_manager/cred.rb - About 3 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

Method report_auth_info has 84 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def report_auth_info(opts={})
    return if not active
    raise ArgumentError.new("Missing required option :host") if opts[:host].nil?
    raise ArgumentError.new("Missing required option :port") if (opts[:port].nil? and opts[:service].nil?)

Severity: Major
Found in lib/msf/core/db_manager/cred.rb - About 3 hrs to fix

    Method update_credential has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

      def update_credential(opts)
        ::ApplicationRecord.connection_pool.with_connection {
          # process workspace string for update if included in opts
          wspace = Msf::Util::DBManager.process_opts_workspace(opts, framework, false)
          opts = opts.clone()
    Severity: Minor
    Found in lib/msf/core/db_manager/cred.rb - About 2 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

    Method creds has 48 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def creds(opts)
        query = nil
        ::ApplicationRecord.connection_pool.with_connection {
          # If :id exists we're looking for a specific record, skip the other stuff
          if opts[:id] && !opts[:id].to_s.empty?
    Severity: Minor
    Found in lib/msf/core/db_manager/cred.rb - About 1 hr to fix

      Method update_credential has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def update_credential(opts)
          ::ApplicationRecord.connection_pool.with_connection {
            # process workspace string for update if included in opts
            wspace = Msf::Util::DBManager.process_opts_workspace(opts, framework, false)
            opts = opts.clone()
      Severity: Minor
      Found in lib/msf/core/db_manager/cred.rb - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

              if token[0].nil? or token[0].empty?
                cred = service.creds.where(user: token[0] || "", ptype: ptype, pass: token[1] || "").first_or_initialize
              else
                cred = service.creds.find_by_user_and_ptype_and_pass(token[0] || "", ptype, token[1] || "")
                unless cred
        Severity: Major
        Found in lib/msf/core/db_manager/cred.rb - About 40 mins to fix

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

            def delete_credentials(opts)
              raise ArgumentError.new("The following options are required: :ids") if opts[:ids].nil?
          
              ::ApplicationRecord.connection_pool.with_connection {
                deleted = []
          Severity: Major
          Found in lib/msf/core/db_manager/cred.rb and 1 other location - About 1 hr to fix
          lib/msf/core/db_manager/login.rb on lines 20..35

          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 48.

          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 3 locations. Consider refactoring.
          Open

                if opts[:public]
                  if opts[:public][:id]
                    public_id = opts[:public].delete(:id)
                    public = Metasploit::Credential::Public.find(public_id)
                    public.update_attributes(opts[:public])
          Severity: Major
          Found in lib/msf/core/db_manager/cred.rb and 2 other locations - About 50 mins to fix
          lib/msf/core/db_manager/cred.rb on lines 255..263
          lib/msf/core/db_manager/cred.rb on lines 265..273

          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 42.

          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 3 locations. Consider refactoring.
          Open

                if opts[:private]
                  if opts[:private][:id]
                    private_id = opts[:private].delete(:id)
                    private = Metasploit::Credential::Private.find(private_id)
                    private.update_attributes(opts[:private])
          Severity: Major
          Found in lib/msf/core/db_manager/cred.rb and 2 other locations - About 50 mins to fix
          lib/msf/core/db_manager/cred.rb on lines 245..253
          lib/msf/core/db_manager/cred.rb on lines 265..273

          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 42.

          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 3 locations. Consider refactoring.
          Open

                if opts[:origin]
                  if opts[:origin][:id]
                    origin_id = opts[:origin].delete(:id)
                    origin = Metasploit::Credential::Origin.find(origin_id)
                    origin.update_attributes(opts[:origin])
          Severity: Major
          Found in lib/msf/core/db_manager/cred.rb and 2 other locations - About 50 mins to fix
          lib/msf/core/db_manager/cred.rb on lines 245..253
          lib/msf/core/db_manager/cred.rb on lines 255..263

          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 42.

          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

              if (token[1])
                token[1] = token[1].unpack("C*").pack("C*")
                token[1] = token[1].gsub(/[\x00-\x1f\x7f-\xff]/n){|m| "\\x%.2x" % m.unpack("C")[0] }
          Severity: Minor
          Found in lib/msf/core/db_manager/cred.rb and 1 other location - About 30 mins to fix
          lib/msf/core/db_manager/cred.rb on lines 143..146

          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 32.

          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

              if (token[0])
                # convert the token to US-ASCII from UTF-8 to prevent an error
                token[0] = token[0].unpack("C*").pack("C*")
                token[0] = token[0].gsub(/[\x00-\x1f\x7f-\xff]/n){|m| "\\x%.2x" % m.unpack("C")[0] }
          Severity: Minor
          Found in lib/msf/core/db_manager/cred.rb and 1 other location - About 30 mins to fix
          lib/msf/core/db_manager/cred.rb on lines 149..151

          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 32.

          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

          There are no issues that match your filters.

          Category
          Status