Skip to content

Commit

Permalink
Introduce 'Danger' response for suspicious domains
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanHallam committed Mar 3, 2025
1 parent 1243d77 commit 9dafc46
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app/lib/link_checker/uri_checker/danger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module LinkChecker::UriChecker
class Danger < Problem
def initialize(**options)
super(type: :danger, **options)
end
end
end
2 changes: 1 addition & 1 deletion app/lib/link_checker/uri_checker/http_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def initialize(options = {})
end
end

class SuspiciousDomain < LinkChecker::UriChecker::Warning
class SuspiciousDomain < LinkChecker::UriChecker::Danger
def initialize(options = {})
super(summary: :suspicious_destination, message: :website_on_list_of_suspicious_domains, **options)
end
Expand Down
7 changes: 7 additions & 0 deletions app/lib/link_checker/uri_checker/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ def warnings
.uniq
end

def danger
problems
.select { |problem| problem.type == :danger }
.map(&:message)
.uniq
end

def errors
problems
.select { |problem| problem.type == :error }
Expand Down
9 changes: 8 additions & 1 deletion spec/lib/link_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
end
end

shared_examples "has danger" do |danger = nil|
it "should have danger" do
expect(subject.danger).to_not be_empty
expect(subject.danger).to include(danger) if danger
end
end

shared_examples "has a problem summary" do |summary|
it "should have a problem summary of #{summary}" do
expect(subject.problem_summary).to eq(summary)
Expand Down Expand Up @@ -102,7 +109,7 @@
let(:uri) { "https://malicious.example.com" }
before { stub_request(:get, uri).to_return(status: 200) }
include_examples "has a problem summary", "Suspicious Destination"
include_examples "has warnings"
include_examples "has danger"
include_examples "has no errors"
end

Expand Down

0 comments on commit 9dafc46

Please sign in to comment.