test/test_puma_server_ssl.rb

Summary

Maintainability
D
2 days
Test Coverage

File test_puma_server_ssl.rb has 447 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require_relative "helper"

if ::Puma::HAS_SSL
  require "puma/minissl"
  require_relative "helpers/test_puma/puma_socket"
Severity: Minor
Found in test/test_puma_server_ssl.rb - About 6 hrs to fix

    Method assert_ssl_client_error_match has 32 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def assert_ssl_client_error_match(error, subject: nil, context: CTX, &blk)
        port = 0
    
        app = lambda { |env| [200, {}, [env['rack.url_scheme']]] }
    
    
    Severity: Minor
    Found in test/test_puma_server_ssl.rb - About 1 hr to fix

      Method test_tls_v1_rejection has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        def test_tls_v1_rejection
          start_server { |ctx| ctx.no_tlsv1 = true }
      
          assert_raises(OpenSSL::SSL::SSLError) do
            send_http_read_resp_body ctx: new_ctx { |c|
      Severity: Minor
      Found in test/test_puma_server_ssl.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 test_tls_v1_1_rejection has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        def test_tls_v1_1_rejection
          start_server { |ctx| ctx.no_tlsv1_1 = true }
      
          assert_raises(OpenSSL::SSL::SSLError) do
            send_http_read_response ctx: new_ctx { |c|
      Severity: Minor
      Found in test/test_puma_server_ssl.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 test_ssl_v3_rejection has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def test_ssl_v3_rejection
          skip("SSLv3 protocol is unavailable") if Puma::MiniSSL::OPENSSL_NO_SSL3
          start_server
      
          assert_raises(OpenSSL::SSL::SSLError) do
      Severity: Minor
      Found in test/test_puma_server_ssl.rb - 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

      Method assert_ssl_client_error_match has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def assert_ssl_client_error_match(error, subject: nil, context: CTX, &blk)
          port = 0
      
          app = lambda { |env| [200, {}, [env['rack.url_scheme']]] }
      
      
      Severity: Minor
      Found in test/test_puma_server_ssl.rb - 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

      Method test_tls_v1_3 has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def test_tls_v1_3
          skip("TLSv1.3 protocol can not be set") unless OpenSSL::SSL::SSLContext.instance_methods(false).include?(:min_version=)
      
          start_server
      
      
      Severity: Minor
      Found in test/test_puma_server_ssl.rb - 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

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

        def test_verify_fail_if_client_unknown_ca
          error = Puma.jruby? ? /No trusted certificate found/ : /self[- ]signed certificate in certificate chain/
          cert_subject = Puma.jruby? ? '/DC=net/DC=puma/CN=localhost' : '/DC=net/DC=puma/CN=CAU'
          assert_ssl_client_error_match(error, subject: cert_subject) do |client_ctx|
            key = "#{CERT_PATH}/client_unknown.key"
      Severity: Minor
      Found in test/test_puma_server_ssl.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

      Identical blocks of code found in 3 locations. Consider refactoring.
      Open

          assert_ssl_client_error_match(false, context: ctx) do |client_ctx|
            key = "#{CERT_PATH}/client.key"
            crt = "#{CERT_PATH}/client.crt"
            client_ctx.key = OpenSSL::PKey::RSA.new File.read(key)
            client_ctx.cert = OpenSSL::X509::Certificate.new File.read(crt)
      Severity: Major
      Found in test/test_puma_server_ssl.rb and 2 other locations - About 1 hr to fix
      test/test_puma_server_ssl.rb on lines 368..375
      test/test_puma_server_ssl.rb on lines 407..414

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

      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

            key = "#{CERT_PATH}/client.key"
            crt = "#{CERT_PATH}/client.crt"
            client_ctx.key = OpenSSL::PKey::RSA.new File.read(key)
            client_ctx.cert = OpenSSL::X509::Certificate.new File.read(crt)
            client_ctx.ca_file = "#{CERT_PATH}/ca.crt"
      Severity: Minor
      Found in test/test_puma_server_ssl.rb and 1 other location - About 1 hr to fix
      test/test_puma_server_ssl.rb on lines 423..431

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

      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

      Identical blocks of code found in 3 locations. Consider refactoring.
      Open

          assert_ssl_client_error_match(false, context: ctx) do |client_ctx|
            key = "#{CERT_PATH}/client.key"
            crt = "#{CERT_PATH}/client.crt"
            client_ctx.key = OpenSSL::PKey::RSA.new File.read(key)
            client_ctx.cert = OpenSSL::X509::Certificate.new File.read(crt)
      Severity: Major
      Found in test/test_puma_server_ssl.rb and 2 other locations - About 1 hr to fix
      test/test_puma_server_ssl.rb on lines 407..414
      test/test_puma_server_ssl.rb on lines 462..469

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

      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

      Identical blocks of code found in 3 locations. Consider refactoring.
      Open

          assert_ssl_client_error_match(false, context: ctx) do |client_ctx|
            key = "#{CERT_PATH}/client.key"
            crt = "#{CERT_PATH}/client.crt"
            client_ctx.key = OpenSSL::PKey::RSA.new File.read(key)
            client_ctx.cert = OpenSSL::X509::Certificate.new File.read(crt)
      Severity: Major
      Found in test/test_puma_server_ssl.rb and 2 other locations - About 1 hr to fix
      test/test_puma_server_ssl.rb on lines 368..375
      test/test_puma_server_ssl.rb on lines 462..469

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

      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

            key = "#{CERT_PATH}/client.key"
            crt = "#{CERT_PATH}/client.crt"
            client_ctx.key = OpenSSL::PKey::RSA.new File.read(key)
            client_ctx.cert = OpenSSL::X509::Certificate.new File.read(crt)
            client_ctx.ca_file = "#{CERT_PATH}/ca.crt"
      Severity: Minor
      Found in test/test_puma_server_ssl.rb and 1 other location - About 1 hr to fix
      test/test_puma_server_ssl.rb on lines 441..449

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

      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 test_tls_v1_1_rejection
          start_server { |ctx| ctx.no_tlsv1_1 = true }
      
          assert_raises(OpenSSL::SSL::SSLError) do
            send_http_read_response ctx: new_ctx { |c|
      Severity: Minor
      Found in test/test_puma_server_ssl.rb and 1 other location - About 45 mins to fix
      test/test_puma_server_ssl.rb on lines 132..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 41.

      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 test_tls_v1_rejection
          start_server { |ctx| ctx.no_tlsv1 = true }
      
          assert_raises(OpenSSL::SSL::SSLError) do
            send_http_read_resp_body ctx: new_ctx { |c|
      Severity: Minor
      Found in test/test_puma_server_ssl.rb and 1 other location - About 45 mins to fix
      test/test_puma_server_ssl.rb on lines 150..164

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

      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

            key = "#{CERT_PATH}/client_expired.key"
            crt = "#{CERT_PATH}/client_expired.crt"
            client_ctx.key = OpenSSL::PKey::RSA.new File.read(key)
            client_ctx.cert = OpenSSL::X509::Certificate.new File.read(crt)
            client_ctx.ca_file = "#{CERT_PATH}/ca.crt"
      Severity: Minor
      Found in test/test_puma_server_ssl.rb and 1 other location - About 35 mins to fix
      test/test_puma_server_ssl.rb on lines 328..332

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

      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

            key = "#{CERT_PATH}/client_unknown.key"
            crt = "#{CERT_PATH}/client_unknown.crt"
            client_ctx.key = OpenSSL::PKey::RSA.new File.read(key)
            client_ctx.cert = OpenSSL::X509::Certificate.new File.read(crt)
            client_ctx.ca_file = "#{CERT_PATH}/unknown_ca.crt"
      Severity: Minor
      Found in test/test_puma_server_ssl.rb and 1 other location - About 35 mins to fix
      test/test_puma_server_ssl.rb on lines 339..343

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

      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