oa-globocom 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ module OAGloboCom
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 4
5
- PATCH = 6
5
+ PATCH = 7
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH] * '.'
8
8
  end
@@ -8,9 +8,12 @@ module OmniAuth
8
8
  class GloboCom
9
9
  include OmniAuth::Strategy
10
10
 
11
+ attr_reader :logger
12
+
11
13
  def initialize(app, opts = {})
12
14
  Cadun::Config.load_file(opts[:config])
13
15
 
16
+ @logger = opts[:logger]
14
17
  super(app, :cadun, opts)
15
18
  end
16
19
 
@@ -22,6 +25,8 @@ module OmniAuth
22
25
  begin
23
26
  super
24
27
  rescue => e
28
+ logger.error(log_exception(e)) if logger
29
+
25
30
  fail!(e.message, e.message)
26
31
  end
27
32
  end
@@ -57,6 +62,14 @@ module OmniAuth
57
62
  env['REMOTE_ADDR']
58
63
  end
59
64
  end
65
+
66
+ def log_env
67
+ "SERVER_NAME: #{request.env['SERVER_NAME']} | PATH_INFO: #{request.env['PATH_INFO']} | QUERY_STRING: #{request.env['QUERY_STRING']}"
68
+ end
69
+
70
+ def log_exception(exception)
71
+ "#{log_env} | EXCEPTION: #{exception}"
72
+ end
60
73
  end
61
74
  end
62
75
  end
@@ -131,4 +131,50 @@ describe OmniAuth::Strategies::GloboCom do
131
131
  end
132
132
  end
133
133
 
134
+ describe "#log_env" do
135
+ it 'should render the log' do
136
+ stub_fail_requests
137
+ strategy.call! Rack::MockRequest.env_for("http://localhost/auth/cadun/callback?GLBID=GLBID", "rack.session" => {}, "REMOTE_ADDR" => "127.0.0.1")
138
+ strategy.log_env.should == "SERVER_NAME: localhost | PATH_INFO: /auth/cadun/callback | QUERY_STRING: GLBID=GLBID"
139
+ end
140
+ end
141
+
142
+ describe "#log_exception" do
143
+ it "should render the log" do
144
+ stub_fail_requests
145
+ strategy.call! Rack::MockRequest.env_for("http://localhost/auth/cadun/callback?GLBID=GLBID", "rack.session" => {}, "REMOTE_ADDR" => "127.0.0.1")
146
+
147
+ exception = Exception.new('Error')
148
+ strategy.log_exception(exception).should == "SERVER_NAME: localhost | PATH_INFO: /auth/cadun/callback | QUERY_STRING: GLBID=GLBID | EXCEPTION: Error"
149
+ end
150
+ end
151
+
152
+ describe "logging failures" do
153
+ before do
154
+ pending("RR doesn't implement superclass stubs. I don't know how to figure it out yet.")
155
+ end
156
+
157
+ it "should log the failure" do
158
+ strategy = OmniAuth::Strategies::GloboCom.new app, :service_id => 1, :config => "#{File.dirname(__FILE__)}/../../support/fixtures/config.yml", :logger => Logger.new($stdout)
159
+ stub_fail_requests
160
+
161
+ logger = mock('logger')
162
+ mock(logger).error('SERVER_NAME: localhost | PATH_INFO: /auth/cadun/callback | QUERY_STRING: GLBID=GLBID | EXCEPTION: Exception')
163
+ stub(strategy).call_app! { raise Exception }
164
+ stub(strategy).logger { logger }
165
+
166
+ strategy.call! Rack::MockRequest.env_for("http://localhost/auth/cadun/callback?GLBID=GLBID", "rack.session" => {}, "REMOTE_ADDR" => "127.0.0.1")
167
+ end
168
+
169
+ it "should not log the failure" do
170
+ stub_fail_requests
171
+
172
+ logger = mock('logger')
173
+ dont_allow(logger).error
174
+ stub(strategy).call_app! { raise Exception }
175
+ stub(strategy).logger { nil }
176
+
177
+ strategy.call! Rack::MockRequest.env_for("http://localhost/auth/cadun/callback?GLBID=GLBID", "rack.session" => {}, "REMOTE_ADDR" => "127.0.0.1")
178
+ end
179
+ end
134
180
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oa-globocom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-07-28 00:00:00.000000000Z
14
+ date: 2011-08-05 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: oa-core
18
- requirement: &2156660480 !ruby/object:Gem::Requirement
18
+ requirement: &2152430320 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: 0.2.6
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *2156660480
26
+ version_requirements: *2152430320
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: cadun
29
- requirement: &2156659980 !ruby/object:Gem::Requirement
29
+ requirement: &2152429820 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ~>
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: 0.5.5
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *2156659980
37
+ version_requirements: *2152429820
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rack
40
- requirement: &2156689280 !ruby/object:Gem::Requirement
40
+ requirement: &2152429440 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: '0'
46
46
  type: :development
47
47
  prerelease: false
48
- version_requirements: *2156689280
48
+ version_requirements: *2152429440
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: rake
51
- requirement: &2156688820 !ruby/object:Gem::Requirement
51
+ requirement: &2152428980 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ! '>='
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: '0'
57
57
  type: :development
58
58
  prerelease: false
59
- version_requirements: *2156688820
59
+ version_requirements: *2152428980
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: rspec
62
- requirement: &2156688400 !ruby/object:Gem::Requirement
62
+ requirement: &2152428560 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ! '>='
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
- version_requirements: *2156688400
70
+ version_requirements: *2152428560
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rr
73
- requirement: &2156687980 !ruby/object:Gem::Requirement
73
+ requirement: &2152428140 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ! '>='
@@ -78,10 +78,10 @@ dependencies:
78
78
  version: '0'
79
79
  type: :development
80
80
  prerelease: false
81
- version_requirements: *2156687980
81
+ version_requirements: *2152428140
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: fakeweb
84
- requirement: &2156687560 !ruby/object:Gem::Requirement
84
+ requirement: &2152427720 !ruby/object:Gem::Requirement
85
85
  none: false
86
86
  requirements:
87
87
  - - ! '>='
@@ -89,7 +89,7 @@ dependencies:
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
- version_requirements: *2156687560
92
+ version_requirements: *2152427720
93
93
  description: The goal of this gem is to allow the developer to use ContaGlobo.com
94
94
  (a login webservice made by Globo.com) in any web app using OmniAuth
95
95
  email: