rapid7/ruby_smb

View on GitHub
lib/ruby_smb/client/authentication.rb

Summary

Maintainability
C
1 day
Test Coverage

Class Client has 22 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Client
    # This module holds all the backend client methods for authentication.
    module Authentication
      include RubySMB::PeerInfo

Severity: Minor
Found in lib/ruby_smb/client/authentication.rb - About 2 hrs to fix

    Method smb2_authenticate has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

          def smb2_authenticate
            response = smb2_ntlmssp_negotiate
            challenge_packet = smb2_ntlmssp_challenge_packet(response)
            if @dialect == '0x0311'
              update_preauth_hash(challenge_packet)
    Severity: Minor
    Found in lib/ruby_smb/client/authentication.rb - 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

    Method smb2_authenticate has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def smb2_authenticate
            response = smb2_ntlmssp_negotiate
            challenge_packet = smb2_ntlmssp_challenge_packet(response)
            if @dialect == '0x0311'
              update_preauth_hash(challenge_packet)
    Severity: Minor
    Found in lib/ruby_smb/client/authentication.rb - About 1 hr to fix

      Method authenticate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def authenticate
              if smb1
                if username.empty? && password.empty?
                  smb1_anonymous_auth
                else
      Severity: Minor
      Found in lib/ruby_smb/client/authentication.rb - 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

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

            def smb1_ntlmssp_challenge_packet(raw_response)
              packet = RubySMB::SMB1::Packet::SessionSetupResponse.read(raw_response)
              unless packet.valid?
                raise RubySMB::Error::InvalidPacket.new(
                  expected_proto: RubySMB::SMB1::SMB_PROTOCOL_ID,
      Severity: Minor
      Found in lib/ruby_smb/client/authentication.rb and 1 other location - About 55 mins to fix
      lib/ruby_smb/client/authentication.rb on lines 281..295

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

      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 smb2_ntlmssp_challenge_packet(raw_response)
              packet = RubySMB::SMB2::Packet::SessionSetupResponse.read(raw_response)
              unless packet.valid?
                raise RubySMB::Error::InvalidPacket.new(
                  expected_proto: RubySMB::SMB2::SMB2_PROTOCOL_ID,
      Severity: Minor
      Found in lib/ruby_smb/client/authentication.rb and 1 other location - About 55 mins to fix
      lib/ruby_smb/client/authentication.rb on lines 172..187

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

      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

            def smb1_session_setup_response(raw_response)
              packet = RubySMB::SMB1::Packet::SessionSetupResponse.read(raw_response)
      
              unless packet.valid?
                raise RubySMB::Error::InvalidPacket.new(
      Severity: Minor
      Found in lib/ruby_smb/client/authentication.rb and 2 other locations - About 25 mins to fix
      lib/ruby_smb/client/authentication.rb on lines 60..70
      lib/ruby_smb/client/authentication.rb on lines 262..272

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

      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

            def smb2_session_setup_response(raw_response)
              packet = RubySMB::SMB2::Packet::SessionSetupResponse.read(raw_response)
              unless packet.valid?
                raise RubySMB::Error::InvalidPacket.new(
                  expected_proto: RubySMB::SMB2::SMB2_PROTOCOL_ID,
      Severity: Minor
      Found in lib/ruby_smb/client/authentication.rb and 2 other locations - About 25 mins to fix
      lib/ruby_smb/client/authentication.rb on lines 60..70
      lib/ruby_smb/client/authentication.rb on lines 153..163

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

      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

            def smb1_anonymous_auth_response(raw_response)
              packet = RubySMB::SMB1::Packet::SessionSetupLegacyResponse.read(raw_response)
      
              unless packet.valid?
                raise RubySMB::Error::InvalidPacket.new(
      Severity: Minor
      Found in lib/ruby_smb/client/authentication.rb and 2 other locations - About 25 mins to fix
      lib/ruby_smb/client/authentication.rb on lines 153..163
      lib/ruby_smb/client/authentication.rb on lines 262..272

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

      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