legitbot 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9624f762d4c29b00c2baf6f53ec6f6dacaec29d4
4
- data.tar.gz: e6c2650c5471cb9075e9450fd8a5894f074ee05b
3
+ metadata.gz: '09d1957d911120207a2518f7ddd87673fb780206'
4
+ data.tar.gz: 7a8acb9e1bca9d0f409d84055a029baadf9a6c03
5
5
  SHA512:
6
- metadata.gz: dfa1e4d4ec277f2785e49f5af55a630aed08271fa4c7dd24d93d2155d8da8f9522947169a392a2111d6519ab74a0fa3d6410f184f7f67e067403c421ab56ecc7
7
- data.tar.gz: f3e765ee7215424adc1a91e990734bc8409634e321a0c2c37dab83e426c438be7134f432cf0424097489d7ce2397fd4a56711da3349f84cbef83ef26aace1f22
6
+ metadata.gz: 6372a1064b86b8a63e043fd0e737c5a87c394f0dd601bf96fe9d9d5945002ed286ce5f84928f3cfb7fb894d9cf3c7e7c970c6b4a59aef729f19100ffa484e4a1
7
+ data.tar.gz: c4538f8f81fdb71aa65dff43ea41c49c2bd51de9c664778bf2d86b7ca0483de614330dac32fde87db5933a2781e4e21fd6862e1b4ecf4d8be16c83932384f062
data/.gitignore CHANGED
@@ -2,4 +2,5 @@ Gemfile.lock
2
2
  .bundle
3
3
  *.gem
4
4
  *.gemfile.lock
5
+ /pkg
5
6
  /tags
data/README.md CHANGED
@@ -17,7 +17,7 @@ bot = Legitbot.bot(userAgent, ip)
17
17
  it will be an instance with methods
18
18
 
19
19
  ```ruby
20
- bot.detected_as # => "Google"
20
+ bot.detected_as # => :google
21
21
  bot.valid? # => true
22
22
  bot.fake? # => false
23
23
  ```
@@ -42,13 +42,6 @@ end
42
42
  * [Pinterest](https://help.pinterest.com/en/articles/about-pinterest-crawler-0)
43
43
  * [Yandex robots](https://yandex.com/support/webmaster/robot-workings/check-yandex-robots.xml)
44
44
 
45
- ## Issues, problems, plans
46
-
47
- * Rails middleware
48
- * More testing for Facebook
49
- * Make it possible to reload Facebook IP ranges
50
- * Bots masquerading as someone else, e.g. `Telegram (like Twitter)` - what to do?
51
-
52
45
  ## License
53
46
 
54
47
  Apache 2.0
@@ -12,5 +12,9 @@ module Legitbot
12
12
  end
13
13
  end
14
14
 
15
+ class Apple_as_Google < Apple
16
+ end
17
+
15
18
  rule Legitbot::Apple, %w(Applebot)
19
+ rule Legitbot::Apple_as_Google, %w(Googlebot)
16
20
  end
@@ -43,7 +43,7 @@ module Legitbot
43
43
  end
44
44
 
45
45
  def detected_as
46
- self.class.name.split('::').last
46
+ self.class.name.split('::').last.downcase.to_sym
47
47
  end
48
48
 
49
49
  def fake?
@@ -11,12 +11,15 @@ module Legitbot
11
11
  # :yields: a found bot
12
12
  #
13
13
  def self.bot(userAgent, ip, resolver_config = nil)
14
- bot =
14
+ bots =
15
15
  @rules.select { |rule|
16
16
  rule[:fragments].any? {|f| userAgent.index f}
17
17
  }.map { |rule|
18
18
  rule[:class].new(ip, resolver_config)
19
- }.first
19
+ }
20
+
21
+ bot = bots.select { |bot| bot.valid? }.first if bots.size > 1
22
+ bot = bots.first if bot.nil?
20
23
 
21
24
  if bot && block_given?
22
25
  yield bot
@@ -1,3 +1,3 @@
1
1
  module Legitbot
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -0,0 +1,22 @@
1
+ require 'minitest/autorun'
2
+ require 'legitbot'
3
+
4
+ class AppleAsGoogleTest < Minitest::Test
5
+ def test_valid_ip
6
+ ip = "17.58.98.60"
7
+ match = Legitbot::Apple_as_Google.new(ip)
8
+ assert match.valid?, msg: "#{ip} is a valid Applebot IP"
9
+ end
10
+
11
+ def test_invalid_ip
12
+ ip = "127.0.0.1"
13
+ match = Legitbot::Apple_as_Google.new(ip)
14
+ assert match.fake?, msg: "#{ip} is a fake Applebot IP"
15
+ end
16
+
17
+ def test_user_agent
18
+ bot = Legitbot.bot("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", "17.58.98.60")
19
+ assert_equal :apple_as_google, bot.detected_as
20
+ assert bot.valid?, msg: "A valid Applebot User-agent and IP"
21
+ end
22
+ end
data/test/apple_test.rb CHANGED
@@ -16,7 +16,7 @@ class AppleTest < Minitest::Test
16
16
 
17
17
  def test_user_agent
18
18
  bot = Legitbot.bot("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/8.0.2 Safari/600.2.5 (Applebot/0.1; +http://www.apple.com/go/applebot)", "17.58.98.60")
19
- assert_equal "Apple", bot.detected_as
19
+ assert_equal :apple, bot.detected_as
20
20
  assert bot.valid?, msg: "A valid Applebot User-agent and IP"
21
21
  end
22
22
  end
@@ -16,7 +16,7 @@ class FacebookTest < Minitest::Test
16
16
 
17
17
  def test_user_agent
18
18
  bot = Legitbot.bot("facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)", "31.13.76.56")
19
- assert_equal "Facebook", bot.detected_as
19
+ assert_equal :facebook, bot.detected_as
20
20
  assert bot.valid?, msg: "A valid Facebook User-agent and IP"
21
21
  end
22
22
  end
data/test/google_test.rb CHANGED
@@ -32,6 +32,6 @@ class GoogleTest < Minitest::Test
32
32
 
33
33
  def test_engine_name
34
34
  bot = Legitbot.bot("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", "66.249.64.141")
35
- assert_equal "Google", bot.detected_as
35
+ assert_equal :google, bot.detected_as
36
36
  end
37
37
  end
@@ -32,6 +32,6 @@ class PinterestTest < Minitest::Test
32
32
 
33
33
  def test_engine_name
34
34
  bot = Legitbot.bot("Mozilla/5.0 (compatible; Pinterestbot/1.0; +https://www.pinterest.com/bot.html)", "54.236.1.11")
35
- assert_equal "Pinterest", bot.detected_as
35
+ assert_equal :pinterest, bot.detected_as
36
36
  end
37
37
  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.1.2
4
+ version: 0.2.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: 2018-05-18 00:00:00.000000000 Z
11
+ date: 2018-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: irrc
@@ -92,6 +92,7 @@ files:
92
92
  - lib/legitbot/pinterest.rb
93
93
  - lib/legitbot/version.rb
94
94
  - lib/legitbot/yandex.rb
95
+ - test/apple_as_google_test.rb
95
96
  - test/apple_test.rb
96
97
  - test/botmatch_test.rb
97
98
  - test/facebook_test.rb
@@ -127,6 +128,7 @@ test_files:
127
128
  - test/legitbot_test.rb
128
129
  - test/pinterest_test.rb
129
130
  - test/apple_test.rb
131
+ - test/apple_as_google_test.rb
130
132
  - test/google_test.rb
131
133
  - test/botmatch_test.rb
132
134
  - test/facebook_test.rb