Skip to content

Commit

Permalink
feat: add Phishing Database feed
Browse files Browse the repository at this point in the history
  • Loading branch information
ninoseki committed May 14, 2020
1 parent 29c277e commit 0230a9f
Show file tree
Hide file tree
Showing 5 changed files with 871 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/miteru/feeds.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require_relative "./feeds/feed"
require_relative "./feeds/phishing_database"
require_relative "./feeds/ayashige"
require_relative "./feeds/urlscan"
require_relative "./feeds/urlscan_pro"
Expand All @@ -11,6 +12,7 @@ class Feeds

def initialize
@feeds = [
PhishingDatabase.new,
UrlScan.new(Miteru.configuration.size),
UrlScanPro.new,
Miteru.configuration.ayashige? ? Ayashige.new : nil
Expand Down
20 changes: 20 additions & 0 deletions lib/miteru/feeds/phishing_database.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require "json"
require "uri"

module Miteru
class Feeds
class PhishingDatabase < Feed
URL = "https://raw.githubusercontent.com/mitchellkrogza/Phishing.Database/master/phishing-links-NEW-today.txt"

def urls
body = get(URL)
body.to_s.lines.map(&:chomp)
rescue HTTPResponseError, HTTP::Error, JSON::ParserError => e
puts "Failed to load phishing database feed (#{e})"
[]
end
end
end
end
13 changes: 13 additions & 0 deletions spec/feeds/phishing_database_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

RSpec.describe Miteru::Feeds::PhishingDatabase, :vcr do
subject { described_class }

describe "#urls" do
it "returns an Array" do
results = subject.new.urls
expect(results).to be_an(Array)
results.all? { |url| url.start_with?(/^http|^https/) }
end
end
end
1 change: 1 addition & 0 deletions spec/feeds_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
allow(Miteru::Feeds::UrlScan).to receive_message_chain(:new, :urls).and_return([url])
allow(Miteru::Feeds::UrlScanPro).to receive_message_chain(:new, :urls).and_return([url])
allow(Miteru::Feeds::Ayashige).to receive_message_chain(:new, :urls).and_return([url])
allow(Miteru::Feeds::PhishingDatabase).to receive_message_chain(:new, :urls).and_return([url])
end

it "returns an Array without duplicated" do
Expand Down

0 comments on commit 0230a9f

Please sign in to comment.