Sha256: 60bda54c7bf61ef71906d55e9ba373c88b845c36bc0bffcc9d5d906522dcd472

Contents?: true

Size: 865 Bytes

Versions: 3

Compression:

Stored size: 865 Bytes

Contents

require 'minitest/autorun'
require 'legitbot'

class AhrefsTest < Minitest::Test
  def test_malicious_ip
    ip = "149.210.164.47"
    match = Legitbot::Ahrefs.new ip
    assert !match.valid?, msg: "#{ip} is not a real Ahrefs IP"
  end

  def test_valid_ip
    ip = "54.36.148.0"
    match = Legitbot::Ahrefs.new ip
    assert match.valid?, msg: "#{ip} is a valid Ahrefs IP"
  end

  def test_malicious_ua
    bot = Legitbot.bot("Mozilla/5.0 (compatible; AhrefsBot/6.1; +http://ahrefs.com/robot/)", "149.210.164.47")
    assert bot, msg: "Ahrefs detected from User-Agent"
    assert !bot.valid?, msg: "Not a valid Ahrefs"
  end

  def test_valid_ua
    bot = Legitbot.bot("Mozilla/5.0 (compatible; AhrefsBot/6.1; +http://ahrefs.com/robot/)", "54.36.148.0")
    assert bot, msg: "Ahrefs detected from User-Agent"
    assert bot.valid?, msg: "Valid Ahrefs"
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
legitbot-0.3.2 test/ahrefs_test.rb
legitbot-0.3.1 test/ahrefs_test.rb
legitbot-0.3.0 test/ahrefs_test.rb