oa-globocom 0.4.10 → 0.5.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.
- data/lib/oa-globocom/version.rb +2 -2
- data/lib/omni_auth/strategies/globocom.rb +9 -13
- data/oa-globocom.gemspec +1 -2
- data/spec/omni_auth/strategies/globocom_spec.rb +45 -43
- data/spec/spec_helper.rb +2 -2
- metadata +19 -30
data/lib/oa-globocom/version.rb
CHANGED
@@ -11,10 +11,10 @@ module OmniAuth
|
|
11
11
|
attr_reader :logger
|
12
12
|
|
13
13
|
def initialize(app, opts = {})
|
14
|
-
Cadun::Config.load_file
|
14
|
+
Cadun::Config.load_file opts[:config]
|
15
15
|
|
16
16
|
@logger = opts[:logger]
|
17
|
-
super
|
17
|
+
super app, :cadun, opts
|
18
18
|
end
|
19
19
|
|
20
20
|
def request_phase
|
@@ -25,21 +25,21 @@ module OmniAuth
|
|
25
25
|
begin
|
26
26
|
super
|
27
27
|
rescue Exception => e
|
28
|
-
logger.error
|
28
|
+
logger.error log_exception(e) if logger
|
29
29
|
|
30
|
-
fail!
|
30
|
+
fail! e.message, e.message
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
def auth_hash
|
35
|
-
hash = { :provider => "cadun", :uid => user.id, :
|
36
|
-
hash[:
|
35
|
+
hash = { :provider => "cadun", :uid => user.id, :info => user.to_hash.merge(:birthday => user.birthday.strftime('%d/%m/%Y')) }
|
36
|
+
hash[:credentials] = { :GLBID => request.params['GLBID'], :url => request.params['url'] } if request
|
37
37
|
|
38
38
|
hash
|
39
39
|
end
|
40
40
|
|
41
41
|
def user
|
42
|
-
@user ||= Cadun::User.new
|
42
|
+
@user ||= Cadun::User.new :glb_id => request.params['GLBID'], :ip => client_ip, :service_id => service_id
|
43
43
|
end
|
44
44
|
|
45
45
|
def service_id
|
@@ -52,15 +52,11 @@ module OmniAuth
|
|
52
52
|
scheme = request.env['rack.url_scheme']
|
53
53
|
|
54
54
|
callback_url = "#{scheme}://#{uri}#{port}/auth/#{name}/callback"
|
55
|
-
URI.escape
|
55
|
+
URI.escape callback_url, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")
|
56
56
|
end
|
57
57
|
|
58
58
|
def client_ip
|
59
|
-
|
60
|
-
env['HTTP_X_FORWARDED_FOR'].split(',').last.strip
|
61
|
-
else
|
62
|
-
env['REMOTE_ADDR']
|
63
|
-
end
|
59
|
+
env['HTTP_X_FORWARDED_FOR'].present? ? env['HTTP_X_FORWARDED_FOR'].split(',').last.strip : env['REMOTE_ADDR']
|
64
60
|
end
|
65
61
|
|
66
62
|
def log_env
|
data/oa-globocom.gemspec
CHANGED
@@ -15,12 +15,11 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
16
16
|
s.require_paths = %w(lib)
|
17
17
|
|
18
|
-
s.add_dependency '
|
18
|
+
s.add_dependency 'omniauth', '~> 1.0.0'
|
19
19
|
s.add_dependency 'cadun', '~> 0.6.0'
|
20
20
|
s.add_development_dependency 'rack'
|
21
21
|
s.add_development_dependency 'rake'
|
22
22
|
s.add_development_dependency 'rspec'
|
23
|
-
s.add_development_dependency 'rr'
|
24
23
|
s.add_development_dependency 'webmock'
|
25
24
|
s.add_development_dependency 'timecop'
|
26
25
|
end
|
@@ -79,54 +79,59 @@ describe OmniAuth::Strategies::GloboCom do
|
|
79
79
|
end
|
80
80
|
|
81
81
|
describe ":user_info" do
|
82
|
-
subject { strategy.auth_hash[:
|
82
|
+
subject { strategy.auth_hash[:info] }
|
83
|
+
|
84
|
+
it { should include :address => "Rua Uruguai, 59" }
|
85
|
+
it { should include :birthday => "22/02/1983" }
|
86
|
+
it { should include :city => "Rio de Janeiro" }
|
87
|
+
it { should include :country => "Brasil" }
|
88
|
+
it { should include :cpf => "09532034765" }
|
89
|
+
it { should include :email => "fab1@spam.la" }
|
90
|
+
it { should include :gender => "MASCULINO" }
|
91
|
+
it { should include :cadun_id => "21737810" }
|
92
|
+
it { should include :mobile => "21 99999999" }
|
93
|
+
it { should include :name => "Fabricio Rodrigo Lopes" }
|
94
|
+
it { should include :neighborhood => "Andaraí" }
|
95
|
+
it { should include :login => "fabricio_fab1" }
|
96
|
+
it { should include :phone => "21 22881060" }
|
97
|
+
it { should include :state => "RJ" }
|
98
|
+
it { should include :status => "ATIVO" }
|
99
|
+
it { should include :user_type => "NAO_ASSINANTE" }
|
100
|
+
it { should include :zipcode => "20510060" }
|
101
|
+
it { should include :complement => "807" }
|
102
|
+
end
|
103
|
+
|
104
|
+
describe ":credentials" do
|
105
|
+
subject { strategy.auth_hash[:credentials] }
|
83
106
|
|
84
|
-
it { should include(:address => "Rua Uruguai, 59") }
|
85
|
-
it { should include(:birthday => "22/02/1983") }
|
86
|
-
it { should include(:city => "Rio de Janeiro") }
|
87
|
-
it { should include(:country => "Brasil") }
|
88
|
-
it { should include(:cpf => "09532034765") }
|
89
|
-
it { should include(:email => "fab1@spam.la") }
|
90
|
-
it { should include(:gender => "MASCULINO") }
|
91
107
|
it { should include(:GLBID => "GLBID") }
|
92
|
-
it { should include(:cadun_id => "21737810") }
|
93
|
-
it { should include(:mobile => "21 99999999") }
|
94
|
-
it { should include(:name => "Fabricio Rodrigo Lopes") }
|
95
|
-
it { should include(:neighborhood => "Andaraí") }
|
96
|
-
it { should include(:login => "fabricio_fab1") }
|
97
|
-
it { should include(:phone => "21 22881060") }
|
98
|
-
it { should include(:state => "RJ") }
|
99
|
-
it { should include(:status => "ATIVO") }
|
100
108
|
it { should include(:url => "/go_back") }
|
101
|
-
it { should include(:user_type => "NAO_ASSINANTE") }
|
102
|
-
it { should include(:zipcode => "20510060") }
|
103
|
-
it { should include(:complement => "807") }
|
104
109
|
end
|
105
110
|
end
|
106
111
|
|
107
112
|
describe "#client_ip" do
|
108
113
|
it 'should return ip from REMOTE_ADDR when it comes alone' do
|
109
|
-
strategy.call! Rack::MockRequest.env_for
|
114
|
+
strategy.call! Rack::MockRequest.env_for "http://test.localhost/auth/cadun", "rack.session" => {}, 'REMOTE_ADDR' => '200.201.0.15'
|
110
115
|
strategy.client_ip.should == '200.201.0.15'
|
111
116
|
end
|
112
117
|
|
113
118
|
it 'should return ip from REMOTE_ADDR when HTTP_X_FORWARDED_FOR is empty' do
|
114
|
-
strategy.call! Rack::MockRequest.env_for
|
119
|
+
strategy.call! Rack::MockRequest.env_for "http://test.localhost/auth/cadun", "rack.session" => {}, 'REMOTE_ADDR' => '200.201.0.20', 'HTTP_X_FORWARDED_FOR' => ''
|
115
120
|
strategy.client_ip.should == '200.201.0.20'
|
116
121
|
end
|
117
122
|
|
118
123
|
it 'should return ip from HTTP_X_FORWARDED_FOR when it comes alone' do
|
119
|
-
strategy.call! Rack::MockRequest.env_for
|
124
|
+
strategy.call! Rack::MockRequest.env_for "http://test.localhost/auth/cadun", "rack.session" => {}, 'HTTP_X_FORWARDED_FOR' => '201.10.0.15'
|
120
125
|
strategy.client_ip.should == '201.10.0.15'
|
121
126
|
end
|
122
127
|
|
123
128
|
it 'should return ip from HTTP_X_FORWARDED_FOR even if REMOTE_ADDR is present' do
|
124
|
-
strategy.call! Rack::MockRequest.env_for
|
129
|
+
strategy.call! Rack::MockRequest.env_for "http://test.localhost/auth/cadun", "rack.session" => {}, 'REMOTE_ADDR' => '200.201.0.15', 'HTTP_X_FORWARDED_FOR' => '201.10.0.16'
|
125
130
|
strategy.client_ip.should == '201.10.0.16'
|
126
131
|
end
|
127
132
|
|
128
133
|
it 'should always return the last ip from HTTP_X_FORWARDED_FOR' do
|
129
|
-
strategy.call! Rack::MockRequest.env_for
|
134
|
+
strategy.call! Rack::MockRequest.env_for "http://test.localhost/auth/cadun", "rack.session" => {}, 'HTTP_X_FORWARDED_FOR' => '201.10.0.15, 201.10.0.16, 201.10.0.17'
|
130
135
|
strategy.client_ip.should == '201.10.0.17'
|
131
136
|
end
|
132
137
|
end
|
@@ -145,41 +150,38 @@ describe OmniAuth::Strategies::GloboCom do
|
|
145
150
|
it "should render the log" do
|
146
151
|
stub_fail_requests
|
147
152
|
|
148
|
-
Timecop.travel(Time.
|
153
|
+
Timecop.travel(Time.local(2011, 11, 24, 1, 2, 0)) do
|
149
154
|
strategy.call! Rack::MockRequest.env_for("http://localhost/auth/cadun/callback?GLBID=GLBID", "rack.session" => {}, "REMOTE_ADDR" => "127.0.0.1")
|
150
155
|
|
151
|
-
exception = Exception.new
|
152
|
-
strategy.log_exception(exception).should == "
|
156
|
+
exception = Exception.new 'NAO_AUTORIZADO'
|
157
|
+
strategy.log_exception(exception).should == "24/11/2011 01:02 - SERVER_NAME: localhost | PATH_INFO: /auth/cadun/callback | QUERY_STRING: GLBID=GLBID | EXCEPTION: NAO_AUTORIZADO"
|
153
158
|
end
|
154
159
|
end
|
155
160
|
end
|
156
161
|
|
157
|
-
describe "logging failures" do
|
158
|
-
before do
|
159
|
-
pending("RR doesn't implement superclass stubs. I don't know how to figure it out yet.")
|
160
|
-
end
|
161
|
-
|
162
|
+
describe "logging failures" do
|
162
163
|
it "should log the failure" do
|
163
|
-
|
164
|
+
logger = double('logger')
|
165
|
+
|
166
|
+
strategy = OmniAuth::Strategies::GloboCom.new app, :service_id => 1, :config => "#{File.dirname(__FILE__)}/../../support/fixtures/config.yml", :logger => logger
|
164
167
|
stub_fail_requests
|
165
168
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
169
|
+
Timecop.travel(Time.local(2011, 11, 24, 1, 2, 0)) do
|
170
|
+
logger.should_receive(:error).with("24/11/2011 01:02 - SERVER_NAME: localhost | PATH_INFO: /auth/cadun/callback | QUERY_STRING: GLBID=GLBID | EXCEPTION: NAO_AUTORIZADO")
|
171
|
+
strategy.stub!(:call_app!).and_raise Exception
|
172
|
+
strategy.stub!(:logger).and_return logger
|
170
173
|
|
171
|
-
|
174
|
+
strategy.call! Rack::MockRequest.env_for "http://localhost/auth/cadun/callback?GLBID=GLBID", "rack.session" => {}, "REMOTE_ADDR" => "127.0.0.1"
|
175
|
+
end
|
172
176
|
end
|
173
177
|
|
174
178
|
it "should not log the failure" do
|
175
179
|
stub_fail_requests
|
176
180
|
|
177
|
-
|
178
|
-
|
179
|
-
stub(strategy).call_app! { raise Exception }
|
180
|
-
stub(strategy).logger { nil }
|
181
|
+
strategy.stub!(:call_app!).and_raise Exception
|
182
|
+
strategy.should_not_receive :log_exception
|
181
183
|
|
182
|
-
strategy.call! Rack::MockRequest.env_for
|
184
|
+
strategy.call! Rack::MockRequest.env_for "http://localhost/auth/cadun/callback?GLBID=GLBID", "rack.session" => {}, "REMOTE_ADDR" => "127.0.0.1"
|
183
185
|
end
|
184
186
|
end
|
185
187
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,8 +6,8 @@ require 'timecop'
|
|
6
6
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
7
7
|
|
8
8
|
RSpec.configure do |config|
|
9
|
-
config.mock_with :
|
10
|
-
config.filter_run :
|
9
|
+
config.mock_with :rspec
|
10
|
+
config.filter_run :wip => true
|
11
11
|
config.run_all_when_everything_filtered = true
|
12
12
|
|
13
13
|
config.before(:suite) do
|
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
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,22 +11,22 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2011-
|
14
|
+
date: 2011-11-24 00:00:00.000000000Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
|
-
name:
|
18
|
-
requirement: &
|
17
|
+
name: omniauth
|
18
|
+
requirement: &70284217905800 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.
|
23
|
+
version: 1.0.0
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *70284217905800
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: cadun
|
29
|
-
requirement: &
|
29
|
+
requirement: &70284217905180 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ~>
|
@@ -34,10 +34,10 @@ dependencies:
|
|
34
34
|
version: 0.6.0
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *70284217905180
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: rack
|
40
|
-
requirement: &
|
40
|
+
requirement: &70284217904680 !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: *
|
48
|
+
version_requirements: *70284217904680
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: rake
|
51
|
-
requirement: &
|
51
|
+
requirement: &70284217904020 !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: *
|
59
|
+
version_requirements: *70284217904020
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: rspec
|
62
|
-
requirement: &
|
62
|
+
requirement: &70284217892560 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
64
|
requirements:
|
65
65
|
- - ! '>='
|
@@ -67,21 +67,10 @@ dependencies:
|
|
67
67
|
version: '0'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
|
-
version_requirements: *
|
71
|
-
- !ruby/object:Gem::Dependency
|
72
|
-
name: rr
|
73
|
-
requirement: &2156103020 !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
|
-
requirements:
|
76
|
-
- - ! '>='
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
version: '0'
|
79
|
-
type: :development
|
80
|
-
prerelease: false
|
81
|
-
version_requirements: *2156103020
|
70
|
+
version_requirements: *70284217892560
|
82
71
|
- !ruby/object:Gem::Dependency
|
83
72
|
name: webmock
|
84
|
-
requirement: &
|
73
|
+
requirement: &70284217892140 !ruby/object:Gem::Requirement
|
85
74
|
none: false
|
86
75
|
requirements:
|
87
76
|
- - ! '>='
|
@@ -89,10 +78,10 @@ dependencies:
|
|
89
78
|
version: '0'
|
90
79
|
type: :development
|
91
80
|
prerelease: false
|
92
|
-
version_requirements: *
|
81
|
+
version_requirements: *70284217892140
|
93
82
|
- !ruby/object:Gem::Dependency
|
94
83
|
name: timecop
|
95
|
-
requirement: &
|
84
|
+
requirement: &70284217891720 !ruby/object:Gem::Requirement
|
96
85
|
none: false
|
97
86
|
requirements:
|
98
87
|
- - ! '>='
|
@@ -100,7 +89,7 @@ dependencies:
|
|
100
89
|
version: '0'
|
101
90
|
type: :development
|
102
91
|
prerelease: false
|
103
|
-
version_requirements: *
|
92
|
+
version_requirements: *70284217891720
|
104
93
|
description: The goal of this gem is to allow the developer to use ContaGlobo.com
|
105
94
|
(a login webservice made by Globo.com) in any web app using OmniAuth
|
106
95
|
email:
|
@@ -146,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
135
|
version: '0'
|
147
136
|
requirements: []
|
148
137
|
rubyforge_project:
|
149
|
-
rubygems_version: 1.8.
|
138
|
+
rubygems_version: 1.8.10
|
150
139
|
signing_key:
|
151
140
|
specification_version: 3
|
152
141
|
summary: OmniAuth strategy for Globo.com authentication system
|