From 066071288c76210d61519df52a45e5c877c81b0e Mon Sep 17 00:00:00 2001 From: gabrieljablonski Date: Thu, 19 Sep 2024 14:42:13 -0300 Subject: [PATCH] fix domain, add dns mock and update tests --- lib/legitbot/amazon.rb | 2 +- test/amazon_test.rb | 27 +++++++++++++++++++++++++-- test/lib/dns_server_mock.rb | 6 ++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/legitbot/amazon.rb b/lib/legitbot/amazon.rb index 9b70f9a..317415a 100644 --- a/lib/legitbot/amazon.rb +++ b/lib/legitbot/amazon.rb @@ -4,7 +4,7 @@ module Legitbot # :nodoc: # https://adbot.amazon.com/index.html # https://developer.amazon.com/amazonbot class Amazon < BotMatch - domains 'amazon.com.', 'amazonadbot.com.' + domains 'amazon.', 'amazonadbot.com.' end rule Legitbot::Amazon, %w[Amazonbot AmazonAdBot] diff --git a/test/amazon_test.rb b/test/amazon_test.rb index 7a33a8c..052b0f2 100644 --- a/test/amazon_test.rb +++ b/test/amazon_test.rb @@ -30,7 +30,7 @@ def test_malicious_ua refute_predicate bot, :valid? end - def test_valid_ua + def test_user_agent1 bot = Legitbot.bot( 'Mozilla/5.0 (compatible; AmazonAdBot/1.0; +https://adbot.amazon.com)', '54.166.7.90' @@ -40,7 +40,19 @@ def test_valid_ua assert_predicate bot, :valid? end - def test_valid_name + # rubocop:disable Layout/LineLength + def test_user_agent2 + bot = Legitbot.bot( + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.2.5 (KHTML\, like Gecko) Version/8.0.2 Safari/600.2.5 (Amazonbot/0.1; +https://developer.amazon.com/support/amazonbot)', + '52.70.240.171' + ) + + assert bot + assert_predicate bot, :valid? + end + # rubocop:enable Layout/LineLength + + def test_valid_name1 bot = Legitbot.bot( 'Mozilla/5.0 (compatible; AmazonAdBot/1.0; +https://adbot.amazon.com)', '54.166.7.90' @@ -49,6 +61,17 @@ def test_valid_name assert_equal :amazon, bot.detected_as end + # rubocop:disable Layout/LineLength + def test_valid_name2 + bot = Legitbot.bot( + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.2.5 (KHTML\, like Gecko) Version/8.0.2 Safari/600.2.5 (Amazonbot/0.1; +https://developer.amazon.com/support/amazonbot)', + '52.70.240.171' + ) + + assert_equal :amazon, bot.detected_as + end + # rubocop:enable Layout/LineLength + def test_fake_name bot = Legitbot.bot( 'Mozilla/5.0 (compatible; AmazonAdBot/1.0; +https://adbot.amazon.com)', diff --git a/test/lib/dns_server_mock.rb b/test/lib/dns_server_mock.rb index 99adeca..fd0dc04 100644 --- a/test/lib/dns_server_mock.rb +++ b/test/lib/dns_server_mock.rb @@ -29,6 +29,12 @@ '54.166.7.90' => { ptr: %w[crawler-54-166-7-90.amazonadbot.com] }, + '52-70-240-171.crawl.amazonbot.amazon' => { + a: %w[52.70.240.171] + }, + '52.70.240.171' => { + ptr: %w[52-70-240-171.crawl.amazonbot.amazon] + }, # Apple '17-58-98-60.applebot.apple.com' => {