legitbot 0.2.7 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae1f2268a473ad5c04afb57f84e947bface5de9fc0b126639ecd9d492f1fefa0
4
- data.tar.gz: 315a78cf41895bf503de265c77774152d944832959d22c9759576080b5d8d390
3
+ metadata.gz: cdde57656a3544982f83a9cf1afca4b63fcaa26e6da402a97de5ee053f2168fd
4
+ data.tar.gz: 8408a3c73d579ecf92526d7e4889376e5a61996df21df06511fe4076f5bf0913
5
5
  SHA512:
6
- metadata.gz: 5caded01279b6e06f3979ea29722b55981d54b69e692a4da27e1f818704dc8c6c486353dfff8723c5afdad241950072047a4ffaf4105f17eb38f32e44fa95836
7
- data.tar.gz: 2d9f49178129bf04ee6112d6f3f8eca8ca2fb2878daecb26a76b38ea28de63befca2744ecc5087b2a37b09e184621cde8a0016a6513be5556df7fc7e907cb3ad
6
+ metadata.gz: 3f21c0c3c93a2ac9eab93b919f8455a05f5accf07c82623be68fc372f6e3bdc38b88993cd3dc7682cc647b8e74b90290eeb474c5a35ab607f7bf2a2537a50c48
7
+ data.tar.gz: 610e55bbc7d66958c36bc6f77e265d6e14d0427a1d7df3346728cad3450a0cf77181cb76129cd31728db1bb693cba54e74c57aa77ddb6a2d5f26d1a6da3707a9
data/README.md CHANGED
@@ -43,6 +43,7 @@ end
43
43
 
44
44
  ## Supported
45
45
 
46
+ * [Ahrefs](https://ahrefs.com/robot)
46
47
  * [Applebot](https://support.apple.com/en-us/HT204683)
47
48
  * [Baidu spider](http://help.baidu.com/question?prod_en=master&class=498&id=1000973)
48
49
  * [Bingbot](https://blogs.bing.com/webmaster/2012/08/31/how-to-verify-that-bingbot-is-bingbot/)
@@ -0,0 +1,13 @@
1
+ module Legitbot
2
+ # https://ahrefs.com/robot
3
+ class Ahrefs < BotMatch
4
+ Ranges = %w(54.36.148.0/24 54.36.149.0/24 54.36.150.0/24 195.154.122.0/24 195.154.123.0/24 195.154.126.0/24 195.154.127.0/24)
5
+
6
+ def valid?
7
+ ip = IPAddr.new @ip
8
+ Ranges.any? { |range| IPAddr.new(range).include? ip }
9
+ end
10
+ end
11
+
12
+ rule Legitbot::Ahrefs, %w(AhrefsBot)
13
+ end
@@ -41,7 +41,6 @@ module Legitbot
41
41
  %i(ipv4 ipv6).map do |family|
42
42
  [family, results[AS][family][AS]]
43
43
  end.to_h
44
- # { ipv4: results[AS][:ipv4][AS], ipv6: results[AS][:ipv6][AS] }
45
44
  end
46
45
  end
47
46
 
@@ -1,3 +1,3 @@
1
1
  module Legitbot
2
- VERSION = '0.2.7'
2
+ VERSION = '0.3.0'
3
3
  end
data/lib/legitbot.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require_relative 'legitbot/legitbot'
2
2
  require_relative 'legitbot/botmatch'
3
3
 
4
+ require_relative 'legitbot/ahrefs'
4
5
  require_relative 'legitbot/apple'
5
6
  require_relative 'legitbot/baidu'
6
7
  require_relative 'legitbot/bing'
@@ -0,0 +1,28 @@
1
+ require 'minitest/autorun'
2
+ require 'legitbot'
3
+
4
+ class AhrefsTest < Minitest::Test
5
+ def test_malicious_ip
6
+ ip = "149.210.164.47"
7
+ match = Legitbot::Ahrefs.new ip
8
+ assert !match.valid?, msg: "#{ip} is not a real Ahrefs IP"
9
+ end
10
+
11
+ def test_valid_ip
12
+ ip = "54.36.148.0"
13
+ match = Legitbot::Ahrefs.new ip
14
+ assert match.valid?, msg: "#{ip} is a valid Ahrefs IP"
15
+ end
16
+
17
+ def test_malicious_ua
18
+ bot = Legitbot.bot("Mozilla/5.0 (compatible; AhrefsBot/6.1; +http://ahrefs.com/robot/)", "149.210.164.47")
19
+ assert bot, msg: "Ahrefs detected from User-Agent"
20
+ assert !bot.valid?, msg: "Not a valid Ahrefs"
21
+ end
22
+
23
+ def test_valid_ua
24
+ bot = Legitbot.bot("Mozilla/5.0 (compatible; AhrefsBot/6.1; +http://ahrefs.com/robot/)", "54.36.148.0")
25
+ assert bot, msg: "Ahrefs detected from User-Agent"
26
+ assert bot.valid?, msg: "Valid Ahrefs"
27
+ end
28
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legitbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Azarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-12 00:00:00.000000000 Z
11
+ date: 2019-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: irrc
@@ -81,6 +81,7 @@ files:
81
81
  - Rakefile
82
82
  - legitbot.gemspec
83
83
  - lib/legitbot.rb
84
+ - lib/legitbot/ahrefs.rb
84
85
  - lib/legitbot/apple.rb
85
86
  - lib/legitbot/baidu.rb
86
87
  - lib/legitbot/bing.rb
@@ -92,6 +93,7 @@ files:
92
93
  - lib/legitbot/pinterest.rb
93
94
  - lib/legitbot/version.rb
94
95
  - lib/legitbot/yandex.rb
96
+ - test/ahrefs_test.rb
95
97
  - test/apple_as_google_test.rb
96
98
  - test/apple_test.rb
97
99
  - test/botmatch_test.rb
@@ -127,6 +129,7 @@ summary: 'Validate requests from Web crawlers: impersonating or not?'
127
129
  test_files:
128
130
  - test/legitbot_test.rb
129
131
  - test/pinterest_test.rb
132
+ - test/ahrefs_test.rb
130
133
  - test/apple_test.rb
131
134
  - test/apple_as_google_test.rb
132
135
  - test/google_test.rb