Sha256: 8c023185475e7579e0007c3ed3ff3b69c077df0e3476491056b18d215ff50d86

Contents?: true

Size: 1.53 KB

Versions: 11

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

require 'minitest/autorun'
require 'legitbot'

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

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

  def test_malicious_ua
    bot = Legitbot.bot(
      'Mozilla/5.0 (compatible; Pinterestbot/1.0; +https://www.pinterest.com/bot.html)',
      '149.210.164.47'
    )
    assert bot, msg: 'Pinterest detected from User-Agent'
    assert !bot.valid?, msg: 'Not a valid Pinterest'
  end

  def test_valid_ua
    bot = Legitbot.bot(
      'Mozilla/5.0 (compatible; Pinterestbot/1.0; +https://www.pinterest.com/bot.html)',
      '54.236.1.11'
    )
    assert bot, msg: 'Pinterest detected from User-Agent'
    assert bot.valid?, msg: 'Valid Pinterest'
  end

  # rubocop:disable Metrics/LineLength
  def test_android_not_bot
    bot = Legitbot.bot(
      'Mozilla/5.0 (Linux; Android 8.0.0; SM-G965F Build/R16NW; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/70.0.3538.64 Mobile Safari/537.36 [Pinterest/Android]',
      '85.117.106.133'
    )
    assert_nil bot
  end
  # rubocop:enable Metrics/LineLength

  def test_engine_name
    bot = Legitbot.bot(
      'Mozilla/5.0 (compatible; Pinterestbot/1.0; +https://www.pinterest.com/bot.html)',
      '54.236.1.11'
    )
    assert_equal :pinterest, bot.detected_as
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
legitbot-1.3.0 test/pinterest_test.rb
legitbot-1.2.0 test/pinterest_test.rb
legitbot-1.1.1 test/pinterest_test.rb
legitbot-1.1.0 test/pinterest_test.rb
legitbot-1.0.2 test/pinterest_test.rb
legitbot-1.0.1 test/pinterest_test.rb
legitbot-1.0.0 test/pinterest_test.rb
legitbot-0.4.3 test/pinterest_test.rb
legitbot-0.4.2 test/pinterest_test.rb
legitbot-0.4.1 test/pinterest_test.rb
legitbot-0.4.0 test/pinterest_test.rb