Sha256: 37c2794c45f51d4803dc371771c70df9a17b390a2bd230ed48927c5fb6e31b70

Contents?: true

Size: 1.6 KB

Versions: 50

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

module CMSScanner
  module Finders
    # This class is designed to return a unique result such as a version
    # Note: Finders contained can return multiple results but the #run will only
    # returned the best finding
    class UniqueFinders < BaseFinders
      # @param [ Hash ] opts
      # @option opts [ Symbol ] :mode :mixed, :passive or :aggressive
      # @option opts [ Int ] :confidence_threshold  If a finding's confidence reaches this value,
      #                                             it will be returned as the best finding.
      #                                             Default is 100.
      #                                             If <= 0, all finders will be ran.
      #
      # @return [ Object, false ] The best finding or false if none
      def run(opts = {})
        opts[:confidence_threshold] ||= 100

        symbols_from_mode(opts[:mode]).each do |symbol|
          each do |finder|
            run_finder(finder, symbol, opts)

            next if opts[:confidence_threshold] <= 0

            findings.each { |f| return f if f.confidence >= opts[:confidence_threshold] }
          end
        end

        filter_findings
      end

      protected

      # @return [ Object, false ] The best finding or false if none
      def filter_findings
        # results are sorted by confidence ASC
        findings.sort_by!(&:confidence)

        # If all findings have the same confidence, false is returned
        return false if findings.size > 1 && findings.first.confidence == findings.last.confidence

        findings.last || false
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 3 rubygems

Version Path
cms_scanner-0.14.3 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.14.2 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.13.9 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.13.8 lib/cms_scanner/finders/unique_finders.rb
new_cms_scanner-0.13.7 lib/cms_scanner/finders/unique_finders.rb
k8s_cms_scanner-0.1.0 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.13.7 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.13.6 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.13.5 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.13.4 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.13.3 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.13.2 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.13.1 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.13.0 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.12.2 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.12.1 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.12.0 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.11.0 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.10.1 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.10.0 lib/cms_scanner/finders/unique_finders.rb