-
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.
Merge pull request #37 from Bravado-network/master
fix(bots): introduce Pentalbot support
- Loading branch information
Showing
4 changed files
with
64 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: | ||
# http://aspiegel.com/petalbot | ||
class Petalbot < BotMatch | ||
domains 'aspiegel.com.' | ||
end | ||
|
||
rule Legitbot::Petalbot, %w[PetalBot] | ||
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,52 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'minitest/autorun' | ||
require 'legitbot' | ||
|
||
class PetalbotTest < Minitest::Test | ||
def test_malicious_ip | ||
ip = '149.210.164.47' | ||
match = Legitbot::Petalbot.new ip | ||
assert !match.valid?, msg: "#{ip} is not a real Petalbot IP" | ||
end | ||
|
||
def test_valid_ip | ||
ip = '114.119.153.50' | ||
match = Legitbot::Petalbot.new ip | ||
assert match.valid?, msg: "#{ip} is a valid Petalbot IP" | ||
end | ||
|
||
def test_malicious_ua | ||
bot = Legitbot.bot( | ||
'Mozilla/5.0 (compatible;PetalBot; +https://aspiegel.com/petalbot)', | ||
'149.210.164.47' | ||
) | ||
assert bot, msg: 'Petalbot detected from User-Agent' | ||
assert !bot.valid?, msg: 'Not a valid Petalbot' | ||
end | ||
|
||
def test_valid_ua | ||
bot = Legitbot.bot( | ||
'Mozilla/5.0 (compatible;PetalBot; +https://aspiegel.com/petalbot)', | ||
'114.119.153.50' | ||
) | ||
assert bot, msg: 'Petalbot detected from User-Agent' | ||
assert bot.valid?, msg: 'Valid Petalbot' | ||
end | ||
|
||
def test_valid_name | ||
bot = Legitbot.bot( | ||
'Mozilla/5.0 (compatible;PetalBot; +https://aspiegel.com/petalbot)', | ||
'66.249.64.141' | ||
) | ||
assert_equal :petalbot, bot.detected_as | ||
end | ||
|
||
def test_fake_name | ||
bot = Legitbot.bot( | ||
'Mozilla/5.0 (compatible; PetalBot/2.1; +http://www.google.com/bot.html)', | ||
'81.1.172.108' | ||
) | ||
assert_equal :petalbot, bot.detected_as | ||
end | ||
end |