-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4d6dce
commit 24ec3c3
Showing
5 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
module Legitbot # :nodoc: | ||
# https://dataforseo.com/dataforseo-bot | ||
class DataForSEO < BotMatch | ||
domains 'dataforseo.com.' | ||
end | ||
|
||
rule Legitbot::DataForSEO, %w[DataForSeoBot] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'test_helper' | ||
|
||
class DataForSEOTest < Minitest::Test | ||
include Minitest::Hooks | ||
include DnsServerMock | ||
|
||
def test_malicious_ip | ||
ip = '149.210.164.47' | ||
match = Legitbot::DataForSEO.new ip | ||
|
||
refute_predicate match, :valid? | ||
end | ||
|
||
def test_valid_ip | ||
ip = '136.243.228.176' | ||
match = Legitbot::DataForSEO.new ip | ||
|
||
assert_predicate match, :valid? | ||
end | ||
|
||
def test_malicious_ua | ||
bot = Legitbot.bot( | ||
'Mozilla/5.0 (compatible; DataForSeoBot; +https://dataforseo.com/dataforseo-bot)', | ||
'149.210.164.47' | ||
) | ||
|
||
assert bot | ||
refute_predicate bot, :valid? | ||
end | ||
|
||
def test_valid_ua | ||
bot = Legitbot.bot( | ||
'Mozilla/5.0 (compatible; DataForSeoBot; +https://dataforseo.com/dataforseo-bot)', | ||
'136.243.228.176' | ||
) | ||
|
||
assert bot | ||
assert_predicate bot, :valid? | ||
end | ||
|
||
def test_valid_name | ||
bot = Legitbot.bot( | ||
'Mozilla/5.0 (compatible; DataForSeoBot; +https://dataforseo.com/dataforseo-bot)', | ||
'136.243.228.176' | ||
) | ||
|
||
assert_equal :dataforseo, bot.detected_as | ||
end | ||
|
||
def test_fake_name | ||
bot = Legitbot.bot( | ||
'Mozilla/5.0 (compatible; DataForSeoBot; +https://dataforseo.com/dataforseo-bot)', | ||
'81.1.172.108' | ||
) | ||
|
||
assert_equal :dataforseo, bot.detected_as | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters