gengiscan 0.30.0 → 0.40.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gengiscan/engine.rb +7 -4
- data/lib/gengiscan/version.rb +1 -1
- data/spec/gengiscan_spec.rb +36 -1
- metadata +4 -4
data/lib/gengiscan/engine.rb
CHANGED
@@ -14,14 +14,17 @@ module Gengiscan
|
|
14
14
|
|
15
15
|
def detect(url)
|
16
16
|
uri = URI(url)
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
begin
|
18
|
+
res = Net::HTTP.get_response(uri)
|
19
|
+
{:status=>:OK, :code=>res.code, :server=>res['Server'], :powered=>res['X-Powered-By'], :generator=>get_generator_signature(res)}
|
20
|
+
rescue
|
21
|
+
{:status=>:KO, :code=>nil, :server=>nil, :powered=>nil, :generator=>nil}
|
22
|
+
end
|
20
23
|
end
|
21
24
|
|
22
25
|
private
|
23
|
-
def get_generator_signature(res)
|
24
26
|
|
27
|
+
def get_generator_signature(res)
|
25
28
|
generator = ""
|
26
29
|
doc=Nokogiri::HTML(res.body)
|
27
30
|
doc.xpath("//meta[@name='generator']/@content").each do |value|
|
data/lib/gengiscan/version.rb
CHANGED
data/spec/gengiscan_spec.rb
CHANGED
@@ -4,13 +4,48 @@ include WebMock::API
|
|
4
4
|
describe 'gengiscan' do
|
5
5
|
let(:g) {Gengiscan::Engine.new}
|
6
6
|
|
7
|
-
|
7
|
+
describe 'when the server is up and running' do
|
8
|
+
it 'returns a status saying OK' do
|
9
|
+
stub_request(:get, "http://www.test.com/index.html").
|
10
|
+
with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
|
11
|
+
to_return(:status=>200, :body=>"<!DOCTYPE html><html><head><meta name=\"generator\" content=\"WordPress 2.3\" /></head><body>A test cms powered</body></html>", :headers=>{})
|
12
|
+
hash = g.detect('http://www.test.com/index.html')
|
13
|
+
hash[:status].should == :OK
|
14
|
+
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'detect generator meta tag' do
|
8
19
|
stub_request(:get, "http://www.test.com/index.html").
|
9
20
|
with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
|
10
21
|
to_return(:status=>200, :body=>"<!DOCTYPE html><html><head><meta name=\"generator\" content=\"WordPress 2.3\" /></head><body>A test cms powered</body></html>", :headers=>{})
|
11
22
|
|
12
23
|
hash = g.detect('http://www.test.com/index.html')
|
13
24
|
hash[:generator].should == "WordPress 2.3"
|
25
|
+
end
|
14
26
|
|
27
|
+
it 'detect server header' do
|
28
|
+
stub_request(:get, "http://www.test.com/index.html").
|
29
|
+
with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
|
30
|
+
to_return(:status=>200, :body=>"<!DOCTYPE html><html><head><meta name=\"generator\" content=\"WordPress 2.3\" /></head><body>A test cms powered</body></html>", :headers=>{'Server' => 'Apache'})
|
31
|
+
hash = g.detect('http://www.test.com/index.html')
|
32
|
+
hash[:server].should == "Apache"
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
it 'detect x-powered-by header' do
|
37
|
+
stub_request(:get, "http://www.test.com/index.html").
|
38
|
+
with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
|
39
|
+
to_return(:status=>200, :body=>"<!DOCTYPE html><html><head><meta name=\"generator\" content=\"WordPress 2.3\" /></head><body>A test cms powered</body></html>", :headers=>{'X-Powered-By' => 'Linux'})
|
40
|
+
hash = g.detect('http://www.test.com/index.html')
|
41
|
+
hash[:powered].should == "Linux"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
describe 'when the server does not exist' do
|
46
|
+
it 'returns a status saying KO' do
|
47
|
+
hash = g.detect('http://i-dont-exist.it')
|
48
|
+
hash[:status].should == :KO
|
49
|
+
end
|
15
50
|
end
|
16
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gengiscan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.40.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -111,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
111
|
version: '0'
|
112
112
|
segments:
|
113
113
|
- 0
|
114
|
-
hash:
|
114
|
+
hash: -667058402699579580
|
115
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
version: '0'
|
121
121
|
segments:
|
122
122
|
- 0
|
123
|
-
hash:
|
123
|
+
hash: -667058402699579580
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
126
|
rubygems_version: 1.8.24
|