Sha256: 49790594d502ee9403b7cbec1de21eda17aa79fcbd3121528e1aac0a9236374c

Contents?: true

Size: 1.59 KB

Versions: 3

Compression:

Stored size: 1.59 KB

Contents

module CMSScanner
  module Finders
    # Independent Finders container
    # This class is designed to handle independent results
    # which are not related with each others
    # e.g: interesting files
    class IndependentFinders < Array
      # @return [ Findings ]
      def findings
        @findings ||= NS::Finders::Findings.new
      end

      # @param [ Hash ] opts
      # @option opts [ Symbol ] mode :mixed, :passive or :aggressive
      #
      # @return [ Findings ]
      def run(opts = {})
        methods = symbols_from_mode(opts[:mode])

        each do |finder|
          methods.each do |symbol|
            run_finder(finder, symbol, opts)
          end
        end

        filter_findings
      end

      protected

      # @param [ Symbol ] mode :mixed, :passive or :aggressive
      # @return [ Array<Symbol> ] The symbols to call for the mode
      def symbols_from_mode(mode)
        symbols = [:passive, :aggressive]

        return symbols if mode.nil? || mode == :mixed
        symbols.include?(mode) ? [*mode] : []
      end

      # @param [ CMSScanner::Finders::Finder ] finder
      # @param [ Symbol ] symbol See return values of #symbols_from_mode
      # @param [ Hash ] opts
      def run_finder(finder, symbol, opts)
        [*finder.send(symbol, opts.merge(found: findings))].compact.each do |found|
          findings << found
        end
      end

      # Allow child classes to filter the findings, such as return the best one
      # or remove the low confidence ones.
      #
      # @return [ Findings ]
      def filter_findings
        findings
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cms_scanner-0.0.35.1 lib/cms_scanner/finders/independent_finders.rb
cms_scanner-0.0.35 lib/cms_scanner/finders/independent_finders.rb
cms_scanner-0.0.34 lib/cms_scanner/finders/independent_finders.rb