legitbot 0.1.2 → 0.2.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 +4 -4
- data/.gitignore +1 -0
- data/README.md +1 -8
- data/lib/legitbot/apple.rb +4 -0
- data/lib/legitbot/botmatch.rb +1 -1
- data/lib/legitbot/legitbot.rb +5 -2
- data/lib/legitbot/version.rb +1 -1
- data/test/apple_as_google_test.rb +22 -0
- data/test/apple_test.rb +1 -1
- data/test/facebook_test.rb +1 -1
- data/test/google_test.rb +1 -1
- data/test/pinterest_test.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09d1957d911120207a2518f7ddd87673fb780206'
|
4
|
+
data.tar.gz: 7a8acb9e1bca9d0f409d84055a029baadf9a6c03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6372a1064b86b8a63e043fd0e737c5a87c394f0dd601bf96fe9d9d5945002ed286ce5f84928f3cfb7fb894d9cf3c7e7c970c6b4a59aef729f19100ffa484e4a1
|
7
|
+
data.tar.gz: c4538f8f81fdb71aa65dff43ea41c49c2bd51de9c664778bf2d86b7ca0483de614330dac32fde87db5933a2781e4e21fd6862e1b4ecf4d8be16c83932384f062
|
data/.gitignore
CHANGED
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 # =>
|
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
|
data/lib/legitbot/apple.rb
CHANGED
data/lib/legitbot/botmatch.rb
CHANGED
data/lib/legitbot/legitbot.rb
CHANGED
@@ -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
|
-
|
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
|
-
}
|
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
|
data/lib/legitbot/version.rb
CHANGED
@@ -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
|
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
|
data/test/facebook_test.rb
CHANGED
@@ -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
|
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
|
35
|
+
assert_equal :google, bot.detected_as
|
36
36
|
end
|
37
37
|
end
|
data/test/pinterest_test.rb
CHANGED
@@ -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
|
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.
|
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-
|
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
|