From 15ecc145a2ec6fd871e66a19142a2bb4bdfe1eba Mon Sep 17 00:00:00 2001 From: Alexander Azarov Date: Sat, 16 Jul 2022 19:03:18 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20detect=20and=20validate=20you.com?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + lib/legitbot.rb | 1 + lib/legitbot/you.rb | 12 ++++++++++++ test/you_test.rb | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 lib/legitbot/you.rb create mode 100644 test/you_test.rb diff --git a/README.md b/README.md index 272b403..629629d 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,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) +* [You.com](https://about.you.com/youbot/) ## License diff --git a/lib/legitbot.rb b/lib/legitbot.rb index 596a43d..c18b526 100644 --- a/lib/legitbot.rb +++ b/lib/legitbot.rb @@ -17,3 +17,4 @@ require_relative 'legitbot/pinterest' require_relative 'legitbot/twitter' require_relative 'legitbot/yandex' +require_relative 'legitbot/you' diff --git a/lib/legitbot/you.rb b/lib/legitbot/you.rb new file mode 100644 index 0000000..db1d99e --- /dev/null +++ b/lib/legitbot/you.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Legitbot # :nodoc: + # https://about.you.com/youbot/ + class You < BotMatch + ip_ranges %w[ + 20.59.40.22 + ] + end + + rule Legitbot::You, %w[YouBot/] +end diff --git a/test/you_test.rb b/test/you_test.rb new file mode 100644 index 0000000..16143eb --- /dev/null +++ b/test/you_test.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'legitbot' + +class YouTest < Minitest::Test + def test_malicious_ip + ip = '20.59.41.22' + match = Legitbot::You.new ip + refute_predicate match, :valid? + end + + def test_valid_ip + ip = '20.59.40.22' + match = Legitbot::You.new ip + assert_predicate match, :valid? + end + + def test_malicious_ua + bot = Legitbot.bot( + 'Mozilla/5.0 (compatible; YouBot/1.0; +https://about.you.com/youbot/)', + '20.59.41.22' + ) + assert bot + refute_predicate bot, :valid? + end + + def test_valid_ua + bot = Legitbot.bot( + 'Mozilla/5.0 (compatible; YouBot/1.0; +https://about.you.com/youbot/)', + '20.59.40.22' + ) + assert bot + assert_predicate bot, :valid? + end +end