Sha256: dcfdab6cf84572517e7a9ac0c7109bb4cf910e956ce525f50f000dd1d20101c8
Contents?: true
Size: 1.53 KB
Versions: 7
Compression:
Stored size: 1.53 KB
Contents
require 'minitest/autorun' require 'legitbot' class GoogleTest < Minitest::Test def test_malicious_ip ip = "149.210.164.47" match = Legitbot::Google.new ip reverse_name = match.reverse_name assert !match.subdomain_of?("googlebot.com."), msg: "#{reverse_name} is not a subdomain of googlebot.com" assert !match.valid?, msg: "#{ip} is not a real Googlebot IP" end def test_valid_ip ip = "66.249.64.141" match = Legitbot::Google.new ip reverse_name = match.reverse_name assert match.subdomain_of?("googlebot.com."), msg: "#{reverse_name} is a subdomain of googlebot.com" assert match.valid?, msg: "#{ip} is a valid Googlebot IP" end def test_malicious_ua bot = Legitbot.bot("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", "149.210.164.47") assert bot, msg: "Googlebot detected from User-Agent" assert !bot.valid?, msg: "Not a valid Googlebot" end def test_valid_ua bot = Legitbot.bot("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", "66.249.64.141") assert bot, msg: "Googlebot detected from User-Agent" assert bot.valid?, msg: "Valid Googlebot" end def test_valid_name bot = Legitbot.bot("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", "66.249.64.141") assert_equal :google, bot.detected_as end def test_fake_name bot = Legitbot.bot("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", "81.1.172.108") assert_equal :google, bot.detected_as end end
Version data entries
7 entries across 7 versions & 1 rubygems