oa-cadun 3.2.0 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/oa-cadun.rb +1 -1
- data/lib/oa-cadun/version.rb +1 -1
- data/lib/omni_auth/strategies/cadun.rb +19 -13
- data/oa-cadun.gemspec +1 -1
- data/spec/omni_auth/strategies/cadun_spec.rb +66 -47
- data/spec/spec_helper.rb +9 -1
- data/spec/support/fixtures/autorizacao_fail.xml +13 -0
- metadata +4 -3
data/lib/oa-cadun.rb
CHANGED
data/lib/oa-cadun/version.rb
CHANGED
@@ -6,16 +6,15 @@ module OmniAuth
|
|
6
6
|
module Strategies
|
7
7
|
class Cadun
|
8
8
|
include OmniAuth::Strategy
|
9
|
-
include ::Cadun
|
10
9
|
|
11
10
|
def initialize(app, options = {})
|
12
|
-
Config.load_file(options[:config])
|
11
|
+
::Cadun::Config.load_file(options[:config])
|
13
12
|
|
14
13
|
super(app, :cadun, options)
|
15
14
|
end
|
16
15
|
|
17
16
|
def request_phase
|
18
|
-
redirect "#{Config.login_url}/#{service_id}?url=#{callback_url}"
|
17
|
+
redirect "#{::Cadun::Config.login_url}/#{service_id}?url=#{callback_url}"
|
19
18
|
end
|
20
19
|
|
21
20
|
def callback_phase
|
@@ -30,16 +29,8 @@ module OmniAuth
|
|
30
29
|
self.class.build_auth_hash(user, request)
|
31
30
|
end
|
32
31
|
|
33
|
-
def self.build_auth_hash(user, request = nil)
|
34
|
-
hash = { :provider => "cadun", :uid => user.id, :user_info => user.to_hash.merge(:birthday => user.birthday.strftime('%d/%m/%Y')) }
|
35
|
-
hash[:user_info].merge!(:GLBID => request.params['GLBID'], :url => request.params['url']) if request
|
36
|
-
|
37
|
-
hash
|
38
|
-
end
|
39
|
-
|
40
|
-
protected
|
41
32
|
def user
|
42
|
-
@user ||= User.new(:glb_id => request.params['GLBID'], :ip =>
|
33
|
+
@user ||= ::Cadun::User.new(:glb_id => request.params['GLBID'], :ip => client_ip, :service_id => service_id)
|
43
34
|
end
|
44
35
|
|
45
36
|
def service_id
|
@@ -54,6 +45,21 @@ module OmniAuth
|
|
54
45
|
callback_url = "#{scheme}://#{uri}#{port}/auth/cadun/callback"
|
55
46
|
URI.escape(callback_url, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
56
47
|
end
|
48
|
+
|
49
|
+
def client_ip
|
50
|
+
if env['HTTP_X_FORWARDED_FOR'] and not env['HTTP_X_FORWARDED_FOR'].empty?
|
51
|
+
env['HTTP_X_FORWARDED_FOR'].split(',').last.strip
|
52
|
+
else
|
53
|
+
env['REMOTE_ADDR']
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.build_auth_hash(user, request = nil)
|
58
|
+
hash = { :provider => "cadun", :uid => user.id, :user_info => user.to_hash.merge(:birthday => user.birthday.strftime('%d/%m/%Y')) }
|
59
|
+
hash[:user_info].merge!(:GLBID => request.params['GLBID'], :url => request.params['url']) if request
|
60
|
+
|
61
|
+
hash
|
62
|
+
end
|
57
63
|
end
|
58
64
|
end
|
59
|
-
end
|
65
|
+
end
|
data/oa-cadun.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.require_paths = %w(lib)
|
17
17
|
|
18
18
|
s.add_dependency 'oa-core'
|
19
|
-
s.add_dependency 'cadun', '0.3.
|
19
|
+
s.add_dependency 'cadun', '0.3.3'
|
20
20
|
s.add_development_dependency 'rack'
|
21
21
|
s.add_development_dependency 'rspec'
|
22
22
|
s.add_development_dependency 'rr'
|
@@ -15,13 +15,11 @@ describe OmniAuth::Strategies::Cadun do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "status" do
|
18
|
-
|
19
|
-
specify { should == 302 }
|
18
|
+
it { @status.should == 302 }
|
20
19
|
end
|
21
20
|
|
22
21
|
describe "headers" do
|
23
|
-
|
24
|
-
specify { should include("Location" => "https://login.dev.globoi.com/login/1?url=http%3A%2F%2Ftest.localhost%2Fauth%2Fcadun%2Fcallback") }
|
22
|
+
it { @headers.should include("Location" => "https://login.dev.globoi.com/login/1?url=http%3A%2F%2Ftest.localhost%2Fauth%2Fcadun%2Fcallback") }
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
@@ -33,13 +31,11 @@ describe OmniAuth::Strategies::Cadun do
|
|
33
31
|
end
|
34
32
|
|
35
33
|
describe "status" do
|
36
|
-
|
37
|
-
specify { should == 302 }
|
34
|
+
it { @status.should == 302 }
|
38
35
|
end
|
39
36
|
|
40
37
|
describe "headers" do
|
41
|
-
|
42
|
-
specify { should include("Location" => "https://login.dev.globoi.com/login/1?url=http%3A%2F%2Ftest.localhost%3A8080%2Fauth%2Fcadun%2Fcallback") }
|
38
|
+
it { @headers.should include("Location" => "https://login.dev.globoi.com/login/1?url=http%3A%2F%2Ftest.localhost%3A8080%2Fauth%2Fcadun%2Fcallback") }
|
43
39
|
end
|
44
40
|
end
|
45
41
|
end
|
@@ -47,69 +43,92 @@ describe OmniAuth::Strategies::Cadun do
|
|
47
43
|
describe "#callback_phase" do
|
48
44
|
context "when the authorization fails" do
|
49
45
|
before do
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
strategy.call! Rack::MockRequest.env_for("http://localhost/auth/cadun/callback", "rack.session" => {})
|
46
|
+
stub_fail_requests
|
47
|
+
strategy.call! Rack::MockRequest.env_for("http://localhost/auth/cadun/callback?GLBID=GLBID", "rack.session" => {}, "REMOTE_ADDR" => "127.0.0.1")
|
54
48
|
end
|
55
49
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
specify { strategy.env['omniauth.error.type'].should == :invalid_credentials }
|
50
|
+
it { strategy.env['omniauth.auth'].should be_nil }
|
51
|
+
it { strategy.env['omniauth.error'].message.should == "not authorized" }
|
52
|
+
it { strategy.env['omniauth.error.type'].should == :invalid_credentials }
|
60
53
|
end
|
61
54
|
|
62
55
|
context "when the authorization succeeds" do
|
63
56
|
before do
|
64
57
|
stub_requests
|
65
|
-
strategy.call! Rack::MockRequest.env_for("http://localhost/auth/cadun/callback", "rack.session" => {})
|
58
|
+
strategy.call! Rack::MockRequest.env_for("http://localhost/auth/cadun/callback?GLBID=GLBID", "rack.session" => {}, "REMOTE_ADDR" => "127.0.0.1")
|
66
59
|
end
|
67
60
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
specify { strategy.env['omniauth.error.type'].should be_nil }
|
61
|
+
it { strategy.env['omniauth.auth'].should_not be_nil }
|
62
|
+
it { strategy.env['omniauth.error'].should be_nil }
|
63
|
+
it { strategy.env['omniauth.error.type'].should be_nil }
|
72
64
|
end
|
73
65
|
end
|
74
66
|
|
75
67
|
describe "#auth_hash" do
|
76
68
|
before do
|
77
69
|
stub_requests
|
78
|
-
strategy.call! Rack::MockRequest.env_for("http://localhost?GLBID=GLBID&url=/go_back", "rack.session" => {})
|
70
|
+
strategy.call! Rack::MockRequest.env_for("http://localhost?GLBID=GLBID&url=/go_back", "rack.session" => {}, "REMOTE_ADDR" => "127.0.0.1")
|
79
71
|
end
|
80
72
|
|
81
|
-
subject { strategy.auth_hash }
|
82
|
-
|
83
73
|
describe ":uid" do
|
84
|
-
|
74
|
+
it { strategy.auth_hash[:uid].should == "21737810" }
|
85
75
|
end
|
86
76
|
|
87
77
|
describe ":provider" do
|
88
|
-
|
78
|
+
it { strategy.auth_hash[:provider].should == "cadun" }
|
89
79
|
end
|
90
80
|
|
91
81
|
describe ":user_info" do
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
82
|
+
subject { strategy.auth_hash[:user_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(: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
|
+
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
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "#client_ip" do
|
108
|
+
it 'should return ip from REMOTE_ADDR when it comes alone' do
|
109
|
+
strategy.call! Rack::MockRequest.env_for("http://test.localhost/auth/cadun", "rack.session" => {}, 'REMOTE_ADDR' => '200.201.0.15')
|
110
|
+
strategy.client_ip.should == '200.201.0.15'
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should return ip from REMOTE_ADDR when HTTP_X_FORWARDED_FOR is empty' do
|
114
|
+
strategy.call! Rack::MockRequest.env_for("http://test.localhost/auth/cadun", "rack.session" => {}, 'REMOTE_ADDR' => '200.201.0.20', 'HTTP_X_FORWARDED_FOR' => '')
|
115
|
+
strategy.client_ip.should == '200.201.0.20'
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should return ip from HTTP_X_FORWARDED_FOR when it comes alone' do
|
119
|
+
strategy.call! Rack::MockRequest.env_for("http://test.localhost/auth/cadun", "rack.session" => {}, 'HTTP_X_FORWARDED_FOR' => '201.10.0.15')
|
120
|
+
strategy.client_ip.should == '201.10.0.15'
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should return ip from HTTP_X_FORWARDED_FOR even if REMOTE_ADDR is present' do
|
124
|
+
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
|
+
strategy.client_ip.should == '201.10.0.16'
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should always return the last ip from HTTP_X_FORWARDED_FOR' do
|
129
|
+
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
|
+
strategy.client_ip.should == '201.10.0.17'
|
112
131
|
end
|
113
132
|
end
|
114
133
|
|
115
|
-
end
|
134
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -24,4 +24,12 @@ def stub_requests
|
|
24
24
|
|
25
25
|
FakeWeb.register_uri :get, "http://isp-authenticator.dev.globoi.com:8280/cadunii/ws/resources/pessoa/21737810",
|
26
26
|
:body => File.join(File.dirname(__FILE__), "support", "fixtures", "pessoa.xml")
|
27
|
-
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def stub_fail_requests
|
30
|
+
FakeWeb.register_uri :put, "http://isp-authenticator.dev.globoi.com:8280/ws/rest/autorizacao",
|
31
|
+
:body => File.join(File.dirname(__FILE__), "support", "fixtures", "autorizacao_fail.xml")
|
32
|
+
|
33
|
+
FakeWeb.register_uri :get, "http://isp-authenticator.dev.globoi.com:8280/cadunii/ws/resources/pessoa/21737810",
|
34
|
+
:body => File.join(File.dirname(__FILE__), "support", "fixtures", "pessoa.xml")
|
35
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
2
|
+
<usuarioAutorizado>
|
3
|
+
<emailPrincipal>fab1@spam.la</emailPrincipal>
|
4
|
+
<glbId>1484e00106ea401d57902541631200e8a6d44556132366c754c4261655666625537614531655252536e6262626c63676676436c6c316744544d5636617651707a6d417a49756b6e3830415a4a394f36773a303a66616231407370616d2e6c61</glbId>
|
5
|
+
<ip>10.2.25.160</ip>
|
6
|
+
<login>fab1@spam.la</login>
|
7
|
+
<servicoID>2626</servicoID>
|
8
|
+
<status>NAO_AUTORIZADO</status>
|
9
|
+
<statusUsuario>ATIVO</statusUsuario>
|
10
|
+
<tipoUsuario>NAO_ASSINANTE</tipoUsuario>
|
11
|
+
<username>fabricio_fab1</username>
|
12
|
+
<usuarioID>21737810</usuarioID>
|
13
|
+
</usuarioAutorizado>
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: oa-cadun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 3.2.
|
5
|
+
version: 3.2.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Bruno
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2011-
|
15
|
+
date: 2011-06-08 00:00:00 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: oa-core
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
requirements:
|
34
34
|
- - "="
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: 0.3.
|
36
|
+
version: 0.3.3
|
37
37
|
type: :runtime
|
38
38
|
version_requirements: *id002
|
39
39
|
- !ruby/object:Gem::Dependency
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- spec/omni_auth/strategies/cadun_spec.rb
|
105
105
|
- spec/spec_helper.rb
|
106
106
|
- spec/support/fixtures/autorizacao.xml
|
107
|
+
- spec/support/fixtures/autorizacao_fail.xml
|
107
108
|
- spec/support/fixtures/config.yml
|
108
109
|
- spec/support/fixtures/pessoa.xml
|
109
110
|
homepage: https://github.com/azisaka/oa-cadun
|