Skip to content

Commit

Permalink
Merge pull request #37 from Bravado-network/master
Browse files Browse the repository at this point in the history
fix(bots): introduce Pentalbot support
  • Loading branch information
alaz authored Dec 16, 2020
2 parents 9bb24a5 + 16848f5 commit 01077e8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ end
* [Pinterest](https://help.pinterest.com/en/articles/about-pinterest-crawler-0)
* [Twitterbot](https://developer.twitter.com/en/docs/tweets/optimize-with-cards/guides/getting-started), the list of IPs is in the [Troubleshooting page](https://developer.twitter.com/en/docs/tweets/optimize-with-cards/guides/troubleshooting-cards)
* [Yandex robots](https://yandex.com/support/webmaster/robot-workings/check-yandex-robots.xml)
* [Petal robots (Huawei search)](http://aspiegel.com/petalbot)

## License

Expand Down
1 change: 1 addition & 0 deletions lib/legitbot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
require_relative 'legitbot/pinterest'
require_relative 'legitbot/twitter'
require_relative 'legitbot/yandex'
require_relative 'legitbot/petalbot'
10 changes: 10 additions & 0 deletions lib/legitbot/petalbot.rb
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
52 changes: 52 additions & 0 deletions test/petalbot_test.rb
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

0 comments on commit 01077e8

Please sign in to comment.