Sha256: 8e8278c94c794f16bfa8fcefe3bc5469bd7f467345caadc11834697432922ce8

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 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_engine_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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
legitbot-0.1.2 test/google_test.rb