rackamole 0.2.6 → 0.2.7
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.
- data/HISTORY +5 -1
- data/lib/rackamole/mole.rb +5 -14
- data/lib/rackamole/store/mongo_db.rb +2 -1
- data/lib/rackamole/utils/agent_detect.rb +73 -0
- data/lib/rackamole.rb +1 -1
- data/spec/expected_results/mole_exception.log +2 -1
- data/spec/expected_results/mole_feature.log +2 -1
- data/spec/expected_results/mole_perf.log +2 -1
- data/spec/rackamole/mole_spec.rb +58 -38
- data/spec/rackamole/store/log_spec.rb +22 -16
- data/spec/rackamole/store/mongo_db_spec.rb +12 -2
- data/spec/rackamole/utils/agent_detect_spec.rb +105 -0
- metadata +4 -2
data/HISTORY
CHANGED
@@ -33,4 +33,8 @@
|
|
33
33
|
* Added options for excluding certain mole information for being logged see mole_excludes option.
|
34
34
|
* Eliminated unwise defaults. From now, the option :app_name must be specified when initializing.
|
35
35
|
The option :db_name must also be present if the mongo store is used.
|
36
|
-
Keep in mind for rackamole to work with wackamole your db name must follow: mole_{app_name}_{environment}_mdb.
|
36
|
+
Keep in mind for rackamole to work with wackamole your db name must follow: mole_{app_name}_{environment}_mdb.
|
37
|
+
|
38
|
+
0.2.7
|
39
|
+
* Bug fixes and cleanup
|
40
|
+
* Added user_agent parsing. now extracting os/platform/version as well as browser type and version.
|
data/lib/rackamole/mole.rb
CHANGED
@@ -280,13 +280,16 @@ module Rack
|
|
280
280
|
# Optional elements...
|
281
281
|
mole?( :software , info, env['SERVER_SOFTWARE'] )
|
282
282
|
mole?( :ip , info, ip )
|
283
|
-
mole?( :browser , info, id_browser( user_agent ) )
|
284
283
|
mole?( :url , info, request.url )
|
285
284
|
mole?( :path , info, request.path )
|
286
285
|
mole?( :status , info, status )
|
287
286
|
mole?( :headers , info, headers )
|
288
287
|
mole?( :body , info, response.body ) if response
|
289
288
|
|
289
|
+
# Gather up browser and client machine info
|
290
|
+
agent_info = Rackamole::Utils::AgentDetect.parse( user_agent )
|
291
|
+
%w(browser machine).each { |type| mole?(type.to_sym, info, agent_info[type.to_sym] ) }
|
292
|
+
|
290
293
|
# Dump request params
|
291
294
|
unless request.params.empty?
|
292
295
|
info[:params] = filter_params( request.params, options[:param_excludes] || [] )
|
@@ -324,19 +327,7 @@ module Rack
|
|
324
327
|
end
|
325
328
|
results
|
326
329
|
end
|
327
|
-
|
328
|
-
# Attempts to detect browser type from agent info.
|
329
|
-
# BOZO !! Probably more efficient way to do this...
|
330
|
-
def browser_types() @browsers ||= [ 'Firefox', 'Safari', 'MSIE 8.0', 'MSIE 7.0', 'MSIE 6.0', 'Opera', 'Chrome' ] end
|
331
|
-
|
332
|
-
def id_browser( user_agent )
|
333
|
-
return "N/A" if !user_agent or user_agent.empty?
|
334
|
-
browser_types.each do |b|
|
335
|
-
return b if user_agent.match( /.*?#{b.gsub(/\./,'\.')}.*?/ )
|
336
|
-
end
|
337
|
-
"N/A"
|
338
|
-
end
|
339
|
-
|
330
|
+
|
340
331
|
# Trim stack trace
|
341
332
|
def trim_stack( boom )
|
342
333
|
boom.backtrace[0...4]
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# This agent business is a cluster fuck. Won't even pretend detection will
|
2
|
+
# be accurate. But at least an honest try...
|
3
|
+
# BOZO !! Need to handle iphone, android, etc...
|
4
|
+
module Rackamole::Utils
|
5
|
+
class AgentDetect
|
6
|
+
|
7
|
+
# browsers...
|
8
|
+
def self.browsers() %w[Opera Firefox Chrome Safari MSIE]; end
|
9
|
+
|
10
|
+
# Parses user agent to extract browser and machine info
|
11
|
+
def self.parse( agent )
|
12
|
+
browsers.each do |browser|
|
13
|
+
return extract( agent, browser ) if check?( agent, browser )
|
14
|
+
end
|
15
|
+
defaults
|
16
|
+
end
|
17
|
+
|
18
|
+
# =========================================================================
|
19
|
+
private
|
20
|
+
|
21
|
+
# Check for known browsers
|
22
|
+
def self.check?( agent, browser )
|
23
|
+
agent.match( /#{browser}/ )
|
24
|
+
end
|
25
|
+
|
26
|
+
# Pre populate info hash
|
27
|
+
def self.defaults
|
28
|
+
info = { :browser => {}, :machine => {} }
|
29
|
+
%w[name version].each { |t| info[:browser][t.to_sym] = "N/A" }
|
30
|
+
%w[platform os version local].each { |t| info[:machine][t.to_sym] = "N/A" }
|
31
|
+
info
|
32
|
+
end
|
33
|
+
|
34
|
+
# Extract machine and browser info
|
35
|
+
def self.extract( agent, browser )
|
36
|
+
@info = defaults
|
37
|
+
begin
|
38
|
+
extract_browser( agent, browser )
|
39
|
+
extract_platform( agent )
|
40
|
+
rescue => boom
|
41
|
+
$stderr.puts "Unable to parse user agent `#{agent}"
|
42
|
+
$stderr.puts boom
|
43
|
+
boom.backtrace.each { |l| $stderr.puts l }
|
44
|
+
end
|
45
|
+
@info
|
46
|
+
end
|
47
|
+
|
48
|
+
# Extract browser and version
|
49
|
+
def self.extract_browser( agent, browser )
|
50
|
+
@info[:browser][:name] = browser
|
51
|
+
match = agent.match( /#{browser}[\/|\s]([\d|\.?]+)/ )
|
52
|
+
@info[:browser][:version] = match[1] if match and match[1]
|
53
|
+
end
|
54
|
+
|
55
|
+
# Extracts machine info
|
56
|
+
def self.extract_platform( agent )
|
57
|
+
match = agent.match( /\((.*)\)/ )
|
58
|
+
return unless match and match[1]
|
59
|
+
|
60
|
+
machine_info = match[1]
|
61
|
+
tokens = machine_info.split( ";" )
|
62
|
+
unless tokens.empty?
|
63
|
+
platform = tokens[0].strip
|
64
|
+
@info[:machine][:platform] = platform
|
65
|
+
index = 1
|
66
|
+
index += 1 if tokens[1].match( /[MSIE|U]/ )
|
67
|
+
os = tokens[index].match( /(.+)\s([\w\d|\.]+)/ )
|
68
|
+
@info[:machine][:os] = os[1].strip
|
69
|
+
@info[:machine][:version] = os[2].strip
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/rackamole.rb
CHANGED
@@ -4,7 +4,8 @@ Type : 2
|
|
4
4
|
App_name : "Test app"
|
5
5
|
Environment : :test
|
6
6
|
Ip : "1.1.1.1"
|
7
|
-
Browser : "Ibrowse"
|
7
|
+
Browser : {"name"=>"Ibrowse", "version"=>"1.X"}
|
8
|
+
Machine : {"platform"=>"Blee", "os"=>"Windoze", "version"=>"10.0"}
|
8
9
|
User_id : 100
|
9
10
|
User_name : "Fernand"
|
10
11
|
Request_time : 1.0
|
@@ -4,7 +4,8 @@ Type : 0
|
|
4
4
|
App_name : "Test app"
|
5
5
|
Environment : :test
|
6
6
|
Ip : "1.1.1.1"
|
7
|
-
Browser : "Ibrowse"
|
7
|
+
Browser : {"name"=>"Ibrowse", "version"=>"1.X"}
|
8
|
+
Machine : {"platform"=>"Blee", "os"=>"Windoze", "version"=>"10.0"}
|
8
9
|
User_id : 100
|
9
10
|
User_name : "Fernand"
|
10
11
|
Request_time : 1.0
|
@@ -4,7 +4,8 @@ Type : 1
|
|
4
4
|
App_name : "Test app"
|
5
5
|
Environment : :test
|
6
6
|
Ip : "1.1.1.1"
|
7
|
-
Browser : "Ibrowse"
|
7
|
+
Browser : {"name"=>"Ibrowse", "version"=>"1.X"}
|
8
|
+
Machine : {"platform"=>"Blee", "os"=>"Windoze", "version"=>"10.0"}
|
8
9
|
User_id : 100
|
9
10
|
User_name : "Fernand"
|
10
11
|
Request_time : 1.0
|
data/spec/rackamole/mole_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe Rack::Mole do
|
|
10
10
|
@test_env = {
|
11
11
|
'rack.session' => { :user_id => 100, :username => "fernand" },
|
12
12
|
'HTTP_X_FORWARDED_FOR' => '1.1.1.1',
|
13
|
-
'HTTP_USER_AGENT' => "Firefox"
|
13
|
+
'HTTP_USER_AGENT' => "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.0.12) Gecko/20080326 CentOS/1.5.0.12-14.el5.centos Firefox/1.5.0.12"
|
14
14
|
}
|
15
15
|
@opts = {
|
16
16
|
:app_name => "Test App",
|
@@ -184,11 +184,12 @@ describe Rack::Mole do
|
|
184
184
|
@test_store.mole_result[:session].should_not be_nil
|
185
185
|
@test_store.mole_result[:session].keys.should have(2).items
|
186
186
|
@test_store.mole_result[:status].should == 200
|
187
|
+
@test_store.mole_result[:machine].should_not be_nil
|
187
188
|
|
188
189
|
# Excluded
|
189
190
|
@test_store.mole_result[:headers].should be_nil
|
190
191
|
@test_store.mole_result[:body].should be_nil
|
191
|
-
@test_store.mole_result[:browser].should be_nil
|
192
|
+
@test_store.mole_result[:browser].should be_nil
|
192
193
|
@test_store.mole_result[:ip].should be_nil
|
193
194
|
@test_store.mole_result[:url].should be_nil
|
194
195
|
end
|
@@ -202,23 +203,27 @@ describe Rack::Mole do
|
|
202
203
|
|
203
204
|
it "should set the mole meta correctly" do
|
204
205
|
get "/fred/blee", nil, @test_env
|
205
|
-
|
206
|
-
@test_store.mole_result[:app_name].should
|
207
|
-
@test_store.mole_result[:environment].should
|
208
|
-
@test_store.mole_result[:user_id].should
|
209
|
-
@test_store.mole_result[:user_name].should
|
210
|
-
@test_store.mole_result[:ip].should
|
211
|
-
@test_store.mole_result[:browser].should
|
212
|
-
@test_store.mole_result[:
|
213
|
-
@test_store.mole_result[:
|
214
|
-
@test_store.mole_result[:
|
215
|
-
@test_store.mole_result[:
|
216
|
-
@test_store.mole_result[:
|
217
|
-
@test_store.mole_result[:
|
218
|
-
@test_store.mole_result[:
|
219
|
-
@test_store.mole_result[:
|
220
|
-
@test_store.mole_result[:
|
221
|
-
@test_store.mole_result[:
|
206
|
+
|
207
|
+
@test_store.mole_result[:app_name].should == "Test App"
|
208
|
+
@test_store.mole_result[:environment].should == :test
|
209
|
+
@test_store.mole_result[:user_id].should be_nil
|
210
|
+
@test_store.mole_result[:user_name].should == 'fernand'
|
211
|
+
@test_store.mole_result[:ip].should == '1.1.1.1'
|
212
|
+
@test_store.mole_result[:browser][:name].should == "Firefox"
|
213
|
+
@test_store.mole_result[:browser][:version].should == '1.5.0.12'
|
214
|
+
@test_store.mole_result[:machine][:platform].should == 'X11'
|
215
|
+
@test_store.mole_result[:machine][:os].should == 'Linux'
|
216
|
+
@test_store.mole_result[:machine][:version].should == 'i686'
|
217
|
+
@test_store.mole_result[:method].should == 'GET'
|
218
|
+
@test_store.mole_result[:url].should == 'http://example.org/fred/blee'
|
219
|
+
@test_store.mole_result[:path].should == '/fred/blee'
|
220
|
+
@test_store.mole_result[:type].should == Rackamole.feature
|
221
|
+
@test_store.mole_result[:params].should be_nil
|
222
|
+
@test_store.mole_result[:session].should_not be_nil
|
223
|
+
@test_store.mole_result[:session].keys.should have(2).items
|
224
|
+
@test_store.mole_result[:status].should == 200
|
225
|
+
@test_store.mole_result[:headers].should == { "Content-Type" => "text/plain" }
|
226
|
+
@test_store.mole_result[:body].should be_nil
|
222
227
|
end
|
223
228
|
|
224
229
|
it "mole an exception correctly" do
|
@@ -227,12 +232,12 @@ describe Rack::Mole do
|
|
227
232
|
rescue => boom
|
228
233
|
@test_env['mole.exception'] = boom
|
229
234
|
get "/crap/out", nil, @test_env
|
230
|
-
@test_store.mole_result[:type].should
|
231
|
-
@test_store.mole_result[:stack].should
|
232
|
-
@test_store.mole_result[:fault].should
|
235
|
+
@test_store.mole_result[:type].should == Rackamole.fault
|
236
|
+
@test_store.mole_result[:stack].should have(4).items
|
237
|
+
@test_store.mole_result[:fault].should == 'Oh snap!'
|
233
238
|
last_request.env['mole.stash'].should_not be_nil
|
234
|
-
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:
|
235
|
-
fault.should_not
|
239
|
+
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:231" )
|
240
|
+
fault.should_not be_nil
|
236
241
|
fault.count.should == 1
|
237
242
|
end
|
238
243
|
end
|
@@ -390,20 +395,35 @@ describe Rack::Mole do
|
|
390
395
|
end
|
391
396
|
|
392
397
|
# ---------------------------------------------------------------------------
|
393
|
-
describe '#id_browser' do
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
398
|
+
# describe '#id_browser' do
|
399
|
+
# before :all do
|
400
|
+
# @rack = Rack::Mole.new( nil, :app_name => "test app" )
|
401
|
+
# end
|
402
|
+
#
|
403
|
+
# it "should detect a browser type correctly" do
|
404
|
+
# agents =
|
405
|
+
# [
|
406
|
+
# "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0_1 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko)"
|
407
|
+
# "Opera/9.61 (Windows NT 5.1; U; ru) Presto/2.1.1"
|
408
|
+
# "Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)",
|
409
|
+
# "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; (R1 1.5); .NET CLR 1.1.4322)",
|
410
|
+
# "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.49 Safari/532.5",
|
411
|
+
# "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-us) AppleWebKit/531.9 (KHTML, like Gecko) Version/4.0.3 Safari/531.9",
|
412
|
+
# "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; InfoPath.2; MS-RTC LM 8; SPC 3.1 P1 Ta)",
|
413
|
+
# "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7"
|
414
|
+
# ]
|
415
|
+
# # results = ["Chrome - 4.0.249.49", "Safari - 531.9", "MSIE 7.0", "Firefox - 3.5.7"]
|
416
|
+
# # results = ["Chrome", "Safari", "MSIE 7.0", "Firefox"]
|
417
|
+
# agents.each do |agent|
|
418
|
+
# browser = @rack.send( :id_browser, agent )
|
419
|
+
# browser.should == results.shift
|
420
|
+
# end
|
421
|
+
# end
|
422
|
+
#
|
423
|
+
# it "should return unknow if can't detect it" do
|
424
|
+
# @rack.send( :id_browser, 'IBrowse' ).should == 'N/A'
|
425
|
+
# end
|
426
|
+
# end
|
407
427
|
|
408
428
|
# ---------------------------------------------------------------------------
|
409
429
|
describe 'YAML load' do
|
@@ -9,26 +9,32 @@ describe Rackamole::Store::Log do
|
|
9
9
|
@store = Rackamole::Store::Log.new( @test_file )
|
10
10
|
|
11
11
|
@args = OrderedHash.new
|
12
|
-
@args[:type]
|
13
|
-
@args[:app_name]
|
14
|
-
@args[:environment]
|
15
|
-
@args[:ip]
|
16
|
-
@args[:browser]
|
17
|
-
@args[:
|
18
|
-
@args[:
|
19
|
-
@args[:
|
20
|
-
@args[:
|
21
|
-
@args[:
|
22
|
-
@args[:
|
23
|
-
@args[:
|
24
|
-
@args[:
|
12
|
+
@args[:type] = Rackamole.feature
|
13
|
+
@args[:app_name] = "Test app"
|
14
|
+
@args[:environment] = :test
|
15
|
+
@args[:ip] = "1.1.1.1"
|
16
|
+
@args[:browser] = OrderedHash.new
|
17
|
+
@args[:browser][:name] = "Ibrowse"
|
18
|
+
@args[:browser][:version] = "1.X"
|
19
|
+
@args[:machine] = OrderedHash.new
|
20
|
+
@args[:machine][:platform] = "Blee"
|
21
|
+
@args[:machine][:os] = "Windoze"
|
22
|
+
@args[:machine][:version] = "10.0"
|
23
|
+
@args[:user_id] = 100
|
24
|
+
@args[:user_name] = "Fernand"
|
25
|
+
@args[:request_time] = 1.0
|
26
|
+
@args[:url] = "http://test_me/"
|
27
|
+
@args[:path] = "/fred"
|
28
|
+
@args[:method] = 'GET'
|
29
|
+
@args[:params] = { :blee => "duh".to_json }
|
30
|
+
@args[:session] = { :fred => 10.to_json }
|
25
31
|
end
|
26
32
|
|
27
33
|
it "should mole a feature correctly" do
|
28
34
|
@store.mole( @args )
|
29
|
-
results = File.read( @test_file ).gsub( /.* Mole \:\s/, '' )
|
30
|
-
expected = File.read( File.join( File.dirname(__FILE__), %w[.. .. expected_results mole_feature.log] ) )
|
31
|
-
expected.should == results
|
35
|
+
results = File.read( @test_file ).gsub( /.* Mole \:\s/, '' )
|
36
|
+
expected = File.read( File.join( File.dirname(__FILE__), %w[.. .. expected_results mole_feature.log] ) )
|
37
|
+
expected.should == results
|
32
38
|
end
|
33
39
|
|
34
40
|
it "should mole an exception correctly" do
|
@@ -23,7 +23,13 @@ describe Rackamole::Store::MongoDb do
|
|
23
23
|
@args[:environment] = :test
|
24
24
|
@args[:perf_issue] = false
|
25
25
|
@args[:ip] = "1.1.1.1"
|
26
|
-
@args[:browser]
|
26
|
+
@args[:browser] = OrderedHash.new
|
27
|
+
@args[:browser][:name] = "Ibrowse"
|
28
|
+
@args[:browser][:version] = "1.X"
|
29
|
+
@args[:machine] = OrderedHash.new
|
30
|
+
@args[:machine][:platform] = "Blee"
|
31
|
+
@args[:machine][:os] = "Windoze"
|
32
|
+
@args[:machine][:version] = "10.0"
|
27
33
|
@args[:user_id] = 100
|
28
34
|
@args[:user_name] = "Fernand"
|
29
35
|
@args[:request_time] = 1.0
|
@@ -52,7 +58,11 @@ describe Rackamole::Store::MongoDb do
|
|
52
58
|
log['fid'].should_not be_nil
|
53
59
|
log['par'].should == { 'blee' => 'duh'.to_json }
|
54
60
|
log['ip'].should == '1.1.1.1'
|
55
|
-
log['bro'].should ==
|
61
|
+
log['bro']['name'].should == "Ibrowse"
|
62
|
+
log['bro']['version'].should == "1.X"
|
63
|
+
log['mac']['platform'].should == "Blee"
|
64
|
+
log['mac']['os'].should == "Windoze"
|
65
|
+
log['mac']['version'].should == "10.0"
|
56
66
|
log['url'].should == 'http://test_me/'
|
57
67
|
log['met'].should == 'GET'
|
58
68
|
log['ses'].should == { 'fred' => '10' }
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), %w[.. .. spec_helper] )
|
2
|
+
|
3
|
+
describe Rackamole::Utils::AgentDetect do
|
4
|
+
|
5
|
+
describe "os" do
|
6
|
+
it "should detect the os and version correctly" do
|
7
|
+
agents = [
|
8
|
+
"Opera/8.65 (X11; Linux i686; U; ru)",
|
9
|
+
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) Opera 8.65 [en]",
|
10
|
+
"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/1.5.0.12 (.NET CLR 3.5.30729)",
|
11
|
+
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.6) Gecko/2009011912 Firefox/1.5.0.12 Ubiquity/0.1.5",
|
12
|
+
"Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.0.12) Gecko/20080326 CentOS/1.5.0.12-14.el5.centos Firefox/1.5.0.12",
|
13
|
+
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.24 Safari/532.0",
|
14
|
+
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.24 Safari/532.0",
|
15
|
+
"Mozilla/5.0 (iPod; U; CPU like Mac OS X; fr) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A102 Safari/522.12",
|
16
|
+
"Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/522.12",
|
17
|
+
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)",
|
18
|
+
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; CPT-IE401SP1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)",
|
19
|
+
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 1.1.4322; InfoPath.2)",
|
20
|
+
"Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)"
|
21
|
+
]
|
22
|
+
expectations = [
|
23
|
+
{
|
24
|
+
:browser => { :name => "Opera", :version => "8.65" },
|
25
|
+
:machine => { :platform => "X11", :os => "Linux", :version => "i686", :local => "N/A" }
|
26
|
+
},
|
27
|
+
{
|
28
|
+
:browser => { :name => "Opera", :version => "8.65" },
|
29
|
+
:machine => { :platform => "compatible", :os => "Windows NT", :version => "5.1", :local => "N/A" }
|
30
|
+
},
|
31
|
+
{
|
32
|
+
:browser => { :name => "Firefox", :version => "1.5.0.12" },
|
33
|
+
:machine => { :platform => "Windows", :os => "Windows NT", :version => "6.0", :local => "en-US" }
|
34
|
+
},
|
35
|
+
{
|
36
|
+
:browser => { :name => "Firefox", :version => "1.5.0.12" },
|
37
|
+
:machine => { :platform => "Macintosh", :os => "Intel Mac OS X", :version => "10.5", :local => "en-US" }
|
38
|
+
},
|
39
|
+
{
|
40
|
+
:browser => { :name => "Firefox", :version => "1.5.0.12" },
|
41
|
+
:machine => { :platform => "X11", :os => "Linux", :version => "i686", :local => "en-US" }
|
42
|
+
},
|
43
|
+
{
|
44
|
+
:browser => { :name => "Chrome", :version => "3.0.195.24" },
|
45
|
+
:machine => { :platform => "Windows", :os => "Windows NT", :version => "5.1", :local => "en-US" }
|
46
|
+
},
|
47
|
+
{
|
48
|
+
:browser => { :name => "Chrome", :version => "3.0.195.24" },
|
49
|
+
:machine => { :platform => "Macintosh", :os => "Intel Mac OS X", :version => "10_5_6", :local => "en-US" }
|
50
|
+
},
|
51
|
+
{
|
52
|
+
:browser => { :name => "Safari", :version => "522.12" },
|
53
|
+
:machine => { :platform => "iPod", :os => "CPU like Mac OS", :version => "X", :local => "fr" }
|
54
|
+
},
|
55
|
+
{
|
56
|
+
:browser => { :name => "Safari", :version => "522.12" },
|
57
|
+
:machine => { :platform => "iPhone", :os => "CPU like Mac OS", :version => "X", :local => "en" }
|
58
|
+
},
|
59
|
+
{
|
60
|
+
:browser => { :name => "MSIE", :version => "8.0" },
|
61
|
+
:machine => { :platform => "compatible", :os => "Windows NT", :version => "5.1", :local => "N/A" }
|
62
|
+
},
|
63
|
+
{
|
64
|
+
:browser => { :name => "MSIE", :version => "7.0" },
|
65
|
+
:machine => { :platform => "compatible", :os => "Windows NT", :version => "5.1", :local => "N/A" }
|
66
|
+
},
|
67
|
+
{
|
68
|
+
:browser => { :name => "MSIE", :version => "6.0" },
|
69
|
+
:machine => { :platform => "compatible", :os => "Windows NT", :version => "5.1", :local => "N/A" }
|
70
|
+
},
|
71
|
+
{
|
72
|
+
:browser => { :name => "MSIE", :version => "5.00" },
|
73
|
+
:machine => { :platform => "compatible", :os => "Windows", :version => "98", :local => "N/A" }
|
74
|
+
}
|
75
|
+
]
|
76
|
+
count = 0
|
77
|
+
agents.each do |agent|
|
78
|
+
info = Rackamole::Utils::AgentDetect.parse( agent )
|
79
|
+
expected = expectations[count]
|
80
|
+
info.should_not be_nil
|
81
|
+
%w(name version).each { |t| info[:browser][t.to_sym].should == expected[:browser][t.to_sym] }
|
82
|
+
%w(platform os version).each { |t| info[:machine][t.to_sym].should == expected[:machine][t.to_sym] }
|
83
|
+
count += 1
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "failure" do
|
89
|
+
it "should not crap out if the user agent is not parsable" do
|
90
|
+
info = Rackamole::Utils::AgentDetect.parse( "Firefox" )
|
91
|
+
%w(browser machine).each { |k| info[k.to_sym].each_pair { |i,v| v.should == (i == :name ? "Firefox" : "N/A") } }
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should produce an empty info object if nothing can be detected" do
|
95
|
+
agents = [
|
96
|
+
"Oper/8.65 (X11 Linux i686 U ru)",
|
97
|
+
]
|
98
|
+
agents.each do |agent|
|
99
|
+
info = Rackamole::Utils::AgentDetect.parse( agent )
|
100
|
+
info.should_not be_nil
|
101
|
+
%w(browser machine).each { |k| info[k.to_sym].each_pair { |i,v| v.should == "N/A" } }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rackamole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fernand Galiana
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-28 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- lib/rackamole/store.rb
|
131
131
|
- lib/rackamole/store/log.rb
|
132
132
|
- lib/rackamole/store/mongo_db.rb
|
133
|
+
- lib/rackamole/utils/agent_detect.rb
|
133
134
|
- spec/expected_results/mole_exception.log
|
134
135
|
- spec/expected_results/mole_feature.log
|
135
136
|
- spec/expected_results/mole_perf.log
|
@@ -143,6 +144,7 @@ files:
|
|
143
144
|
- spec/rackamole/stash/perf_spec.rb
|
144
145
|
- spec/rackamole/store/log_spec.rb
|
145
146
|
- spec/rackamole/store/mongo_db_spec.rb
|
147
|
+
- spec/rackamole/utils/agent_detect_spec.rb
|
146
148
|
- spec/rackamole_spec.rb
|
147
149
|
- spec/spec_helper.rb
|
148
150
|
- spec/test_configs/flawed_config.yml
|