Skip to content

Commit

Permalink
Merge pull request #3 from ninoseki/spec-refactoring
Browse files Browse the repository at this point in the history
refactor: spec refactoring
  • Loading branch information
ninoseki committed May 22, 2019
2 parents 49ba1e2 + 0abcf2c commit c042909
Show file tree
Hide file tree
Showing 9 changed files with 1,499 additions and 899 deletions.
38 changes: 29 additions & 9 deletions lib/urlhaus_monitor/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ class Entry

def initialize(line)
parts = CSV.parse(line.chomp).flatten
raise ArgumentError, "#{line} is not valid." unless parts.length == 8
raise ArgumentError, "#{line} is not valid." unless parts.length == 8 || parts.length == 9

@date_added = parts.shift
@url = parts.shift
@url_status = parts.shift
@threat = parts.shift
@host = parts.shift
@ip_address = parts.shift
@asnumber = parts.shift
@country = parts.shift
if parts.length == 8
parse_without_tags parts
else
parse_with_tags parts
end
end

def defanged_url
Expand Down Expand Up @@ -96,5 +93,28 @@ def _urlscan_link
def _urlhaus_link
"https://urlhaus.abuse.ch/host/#{host}/"
end

def parse_without_tags(parts)
@date_added = parts.shift
@url = parts.shift
@url_status = parts.shift
@threat = parts.shift
@host = parts.shift
@ip_address = parts.shift
@asnumber = parts.shift
@country = parts.shift
end

def parse_with_tags(parts)
@date_added = parts.shift
@url = parts.shift
@url_status = parts.shift
@threat = parts.shift
@tags = parts.shift
@host = parts.shift
@ip_address = parts.shift
@asnumber = parts.shift
@country = parts.shift
end
end
end
24 changes: 12 additions & 12 deletions spec/checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
subject { URLhausMonitor::Checker.new }

describe "#lookup_by_country" do
it "should return an array of Entry" do
entries = subject.lookup_by_country("JP")
expect(entries).to be_an(Array)
expect(entries.first).to be_a(URLhausMonitor::Entry)
let(:entries) { subject.lookup_by_country("JP") }

it do
entries.each { |entry| expect(entry).to be_a(URLhausMonitor::Entry) }
end
end

describe "#lookup_by_tld" do
it "should return an array of Entry" do
entries = subject.lookup_by_tld("jp")
expect(entries).to be_an(Array)
expect(entries.first).to be_a(URLhausMonitor::Entry)
let(:entries) { subject.lookup_by_tld("jp") }

it do
entries.each { |entry| expect(entry).to be_a(URLhausMonitor::Entry) }
end
end

describe "#lookup_by_asn" do
it "should return an array of Entry" do
entries = subject.lookup_by_asn("7506")
expect(entries).to be_an(Array)
expect(entries.first).to be_a(URLhausMonitor::Entry)
let(:entries) { subject.lookup_by_asn("7506") }

it do
entries.each { |entry| expect(entry).to be_a(URLhausMonitor::Entry) }
end
end
end
2 changes: 1 addition & 1 deletion spec/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe URLhausMonitor::CLI do
subject { URLhausMonitor::CLI }
subject { described_class }

describe "#lookup_by_country" do
before do
Expand Down
22 changes: 11 additions & 11 deletions spec/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@

RSpec.describe URLhausMonitor::Entry do
subject {
URLhausMonitor::Entry.new '"2019-03-23 08:02:08","http://store.sensyu.org/data/Smarty/config/msg.jpg","online","malware_download","store.sensyu.org","157.7.144.5","7506","JP"'
described_class.new '"2019-03-23 08:02:08","http://store.sensyu.org/data/Smarty/config/msg.jpg","online","malware_download","store.sensyu.org","157.7.144.5","7506","JP"'
}

it "should have date_added" do
it do
expect(subject.date_added).to eq("2019-03-23 08:02:08")
end

it "should have url" do
it do
expect(subject.url).to eq("http://store.sensyu.org/data/Smarty/config/msg.jpg")
end

it "should have url_status" do
it do
expect(subject.url_status).to eq("online")
end

it "should have threat" do
it do
expect(subject.threat).to eq("malware_download")
end

it "should have host" do
it do
expect(subject.host).to eq("store.sensyu.org")
end

it "should have ip_address" do
it do
expect(subject.ip_address).to eq("157.7.144.5")
end

it "should have asnumber" do
it do
expect(subject.asnumber).to eq("7506")
end

it "should have country" do
it do
expect(subject.country).to eq("JP")
end

describe "#defanged_url" do
it "should reeturn a defanged url" do
it do
expect(subject.defanged_url).to eq("http://store[.]sensyu[.]org/data/Smarty/config/msg[.]jpg")
end
end

describe "#defanged_host" do
it "should reeturn a defanged host" do
it "reeturns a defanged host" do
expect(subject.defanged_host).to eq("store[.]sensyu[.]org")
end
end
Expand Down
Loading

0 comments on commit c042909

Please sign in to comment.