Sha256: e7ca23bd0996fea8397f61ff4412ae7cb320f37b9046a7f93d0c6b4c8418dd58

Contents?: true

Size: 1.2 KB

Versions: 20

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require_relative 'test_helper'

class PetalbotTest < Minitest::Test
  include Minitest::Hooks
  include DnsServerMock

  def test_malicious_ip
    ip = '149.210.164.47'
    match = Legitbot::Petalbot.new ip

    refute_predicate match, :valid?
  end

  def test_valid_ip
    ip = '114.119.134.10'
    match = Legitbot::Petalbot.new ip

    assert_predicate match, :valid?
  end

  def test_malicious_ua
    bot = Legitbot.bot(
      'Mozilla/5.0 (compatible;PetalBot; +https://aspiegel.com/petalbot)',
      '149.210.164.47'
    )

    assert bot
    refute_predicate bot, :valid?
  end

  def test_valid_ua
    bot = Legitbot.bot(
      'Mozilla/5.0 (compatible;PetalBot; +https://aspiegel.com/petalbot)',
      '114.119.134.10'
    )

    assert bot
    assert_predicate bot, :valid?
  end

  def test_valid_name
    bot = Legitbot.bot(
      'Mozilla/5.0 (compatible;PetalBot; +https://aspiegel.com/petalbot)',
      '66.249.64.141'
    )

    assert_equal :petalbot, bot.detected_as
  end

  def test_fake_name
    bot = Legitbot.bot(
      'Mozilla/5.0 (compatible; PetalBot/2.1; +http://www.google.com/bot.html)',
      '81.1.172.108'
    )

    assert_equal :petalbot, bot.detected_as
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
legitbot-1.11.6 test/petalbot_test.rb
legitbot-1.11.5 test/petalbot_test.rb
legitbot-1.11.4 test/petalbot_test.rb
legitbot-1.11.3 test/petalbot_test.rb
legitbot-1.11.2 test/petalbot_test.rb
legitbot-1.11.1 test/petalbot_test.rb
legitbot-1.11.0 test/petalbot_test.rb
legitbot-1.10.6 test/petalbot_test.rb
legitbot-1.10.5 test/petalbot_test.rb
legitbot-1.10.4 test/petalbot_test.rb
legitbot-1.10.3 test/petalbot_test.rb
legitbot-1.10.1 test/petalbot_test.rb
legitbot-1.10.0 test/petalbot_test.rb
legitbot-1.9.4 test/petalbot_test.rb
legitbot-1.9.3 test/petalbot_test.rb
legitbot-1.9.2 test/petalbot_test.rb
legitbot-1.9.1 test/petalbot_test.rb
legitbot-1.9.0 test/petalbot_test.rb
legitbot-1.8.0 test/petalbot_test.rb
legitbot-1.7.3 test/petalbot_test.rb