• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wpscanteam / CMSScanner / 10771931262

09 Sep 2024 11:06AM UTC coverage: 99.925%. Remained the same
10771931262

push

github

web-flow
Merge pull request #261 from wpscanteam/dependabot/bundler/webmock-tw-3.23.1

Update webmock requirement from ~> 3.19.1 to ~> 3.23.1

315 of 346 branches covered (91.04%)

1333 of 1334 relevant lines covered (99.93%)

120.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/app/controllers/core.rb
1
# frozen_string_literal: true
2

3
require_relative 'core/cli_options'
4✔
4

5
module CMSScanner
4✔
6
  module Controller
4✔
7
    # Core Controller
8
    class Core < Base
4✔
9
      def setup_cache
4✔
10
        return unless NS::ParsedCli.cache_dir
76!
11

12
        storage_path = File.join(NS::ParsedCli.cache_dir, Digest::MD5.hexdigest(target.url))
76✔
13

14
        Typhoeus::Config.cache = Cache::Typhoeus.new(storage_path)
76✔
15
        Typhoeus::Config.cache.clean if NS::ParsedCli.clear_cache
76!
16
      end
17

18
      def before_scan
4✔
19
        maybe_output_banner_help_and_version
68✔
20

21
        setup_cache
68✔
22
        check_target_availability
68✔
23
      end
24

25
      def maybe_output_banner_help_and_version
4✔
26
        output('banner') if NS::ParsedCli.banner
84✔
27
        output('help', help: option_parser.simple_help, simple: true) if NS::ParsedCli.help
84✔
28
        output('help', help: option_parser.full_help, simple: false) if NS::ParsedCli.hh
84✔
29
        output('version') if NS::ParsedCli.version
84✔
30

31
        exit(NS::ExitCode::OK) if NS::ParsedCli.help || NS::ParsedCli.hh || NS::ParsedCli.version
84✔
32
      end
33

34
      # Checks that the target is accessible, raises related errors otherwise
35
      #
36
      # @return [ Void ]
37
      def check_target_availability
4✔
38
        res = NS::Browser.get(target.url)
68✔
39

40
        case res.code
68✔
41
        when 0
4✔
42
          raise Error::TargetDown, res
4✔
43
        when 401
8✔
44
          raise Error::HTTPAuthRequired
8✔
45
        when 403
12✔
46
          raise Error::AccessForbidden, NS::ParsedCli.random_user_agent unless NS::ParsedCli.force
12✔
47
        when 407
8✔
48
          raise Error::ProxyAuthRequired
8✔
49
        end
50

51
        handle_redirection(res)
40✔
52
      end
53

54
      # Checks for redirects, an out of scope redirect will raise an Error::HTTPRedirect
55
      #
56
      # @param [ Typhoeus::Response ] res
57
      def handle_redirection(res)
4✔
58
        effective_url = target.homepage_res.effective_url # Basically get and follow location of target.url
40✔
59
        effective_uri = Addressable::URI.parse(effective_url)
40✔
60

61
        # Case of http://a.com => https://a.com (or the opposite)
62
        if !NS::ParsedCli.ignore_main_redirect && target.uri.domain == effective_uri.domain &&
40✔
63
           target.uri.path == effective_uri.path && target.uri.scheme != effective_uri.scheme
64

4✔
65
          target.url = effective_url
4✔
66
        end
67

68
        return if target.in_scope?(effective_url)
40✔
69

70
        raise Error::HTTPRedirect, effective_url unless NS::ParsedCli.ignore_main_redirect
8✔
71

72
        # Sets back homepage_res to unfollowed location in case of ignore_main_redirect used
73
        target.homepage_res = res
4✔
74
      end
75

76
      def run
4✔
77
        @start_time = Time.now
8✔
78
        @start_memory = NS.start_memory
8✔
79

80
        output('started', url: target.url, ip: target.ip, effective_url: target.homepage_url)
8✔
81
      end
82

83
      def after_scan
4✔
84
        @stop_time   = Time.now
4✔
85
        @elapsed     = @stop_time - @start_time
4✔
86
        @used_memory = GetProcessMem.new.bytes - @start_memory
4✔
87

88
        output('finished',
4✔
89
               cached_requests: NS.cached_requests,
90
               requests_done: NS.total_requests,
91
               data_sent: NS.total_data_sent,
92
               data_received: NS.total_data_received)
93
      end
94
    end
95
  end
96
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc