oa-cadun 0.2.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -1
- data/lib/oa-cadun/version.rb +2 -2
- data/lib/omni_auth/strategies/cadun.rb +33 -25
- data/spec/omni_auth/strategies/cadun_spec.rb +36 -21
- data/spec/spec_helper.rb +1 -0
- metadata +1 -1
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm 1.9.2@
|
1
|
+
rvm 1.9.2@cadun
|
data/lib/oa-cadun/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module OACadun
|
2
|
-
VERSION = '0.
|
3
|
-
end
|
2
|
+
VERSION = '0.3'
|
3
|
+
end
|
@@ -3,48 +3,56 @@ module OmniAuth
|
|
3
3
|
class Cadun
|
4
4
|
include OmniAuth::Strategy
|
5
5
|
|
6
|
-
attr_reader :glb_id, :url, :params
|
7
|
-
|
8
6
|
def initialize(app, options = {})
|
9
7
|
super(app, :cadun, options)
|
10
8
|
end
|
11
9
|
|
12
10
|
def request_phase
|
13
|
-
redirect "https://login.dev.globoi.com/login/#{service_id}"
|
11
|
+
redirect "https://login.dev.globoi.com/login/#{service_id}?url=#{callback_url}"
|
14
12
|
end
|
15
13
|
|
16
14
|
def auth_hash
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
15
|
+
{
|
16
|
+
:provider => "cadun",
|
17
|
+
:uid => user.id,
|
18
|
+
:user_info => {
|
19
|
+
:id => user.id,
|
20
|
+
:GLBID => request.params['GLBID'],
|
21
|
+
:url => request.params['url'],
|
22
|
+
:email => user.email,
|
23
|
+
:status => user.status,
|
24
|
+
:nickname => user.login,
|
25
|
+
:name => user.name,
|
26
|
+
:address => user.address,
|
27
|
+
:suburb => user.suburb,
|
28
|
+
:city => user.city,
|
29
|
+
:state => user.state,
|
30
|
+
:country => user.country,
|
31
|
+
:gender => user.gender,
|
32
|
+
:birthday => user.birthday.strftime('%d/%m/%Y'),
|
33
|
+
:mobile => user.mobile,
|
34
|
+
:phone => user.phone,
|
35
|
+
:cpf => user.cpf
|
36
|
+
}
|
37
|
+
}
|
38
38
|
end
|
39
39
|
|
40
40
|
protected
|
41
41
|
def user
|
42
|
-
@user ||= ::Cadun::User.new(
|
42
|
+
@user ||= ::Cadun::User.new(request.params['GLBID'], env['REMOTE_ADDR'], service_id)
|
43
43
|
end
|
44
44
|
|
45
45
|
def service_id
|
46
46
|
@options[:service_id]
|
47
47
|
end
|
48
|
+
|
49
|
+
def callback_url
|
50
|
+
uri = URI.parse(request.referer)
|
51
|
+
port = uri.port == 80 ? nil : ":#{uri.port}"
|
52
|
+
|
53
|
+
callback_url = "http://#{uri.host}#{port}/auth/cadun/callback"
|
54
|
+
URI.escape(callback_url, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
55
|
+
end
|
48
56
|
end
|
49
57
|
end
|
50
58
|
end
|
@@ -3,45 +3,60 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe OmniAuth::Strategies::Cadun do
|
5
5
|
|
6
|
-
let(:app) { lambda{ |env| [200, {}, ['Hello']] } }
|
6
|
+
let(:app) { lambda { |env| [200, {}, ['Hello']] } }
|
7
|
+
let(:strategy) { OmniAuth::Strategies::Cadun.new(app, :service_id => 1) }
|
7
8
|
|
8
9
|
describe "#request_phase" do
|
10
|
+
context "when it has a referer" do
|
11
|
+
before do
|
12
|
+
strategy.call!(Rack::MockRequest.env_for("", "rack.session" => {}, "HTTP_REFERER" => "http://test.localhost/auth/cadun"))
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
@status, @headers, @body = strategy.request_phase
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "status" do
|
18
|
+
subject { @status }
|
19
|
+
specify { should == 302 }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "headers" do
|
23
|
+
subject { @headers }
|
24
|
+
specify { should include("Location" => "https://login.dev.globoi.com/login/1?url=http%3A%2F%2Ftest.localhost%2Fauth%2Fcadun%2Fcallback") }
|
25
|
+
end
|
17
26
|
end
|
18
27
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
28
|
+
context "when it has a referer and a different port" do
|
29
|
+
before do
|
30
|
+
strategy.call!(Rack::MockRequest.env_for("", "rack.session" => {}, "HTTP_REFERER" => "http://test.localhost:8080/auth/cadun"))
|
23
31
|
|
32
|
+
@status, @headers, @body = strategy.request_phase
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "status" do
|
36
|
+
subject { @status }
|
37
|
+
specify { should == 302 }
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "headers" do
|
41
|
+
subject { @headers }
|
42
|
+
specify { should include("Location" => "https://login.dev.globoi.com/login/1?url=http%3A%2F%2Ftest.localhost%3A8080%2Fauth%2Fcadun%2Fcallback") }
|
43
|
+
end
|
44
|
+
end
|
24
45
|
end
|
25
46
|
|
26
47
|
describe "#auth_hash" do
|
27
|
-
|
28
|
-
let(:strategy) { OmniAuth::Strategies::Cadun.new(app, :service_id => 1) }
|
29
|
-
|
30
48
|
before do
|
31
49
|
stub_requests
|
32
|
-
|
33
|
-
strategy.call!({ "rack.session" => {},
|
34
|
-
"REQUEST_URI" => "http://localhost?GLBID=GLBID&url=/go_back",
|
35
|
-
"REMOTE_ADDR" => "127.0.0.1" })
|
50
|
+
strategy.call!(Rack::MockRequest.env_for("http://localhost?GLBID=GLBID&url=/go_back", "rack.session" => {}))
|
36
51
|
end
|
37
52
|
|
38
|
-
subject { strategy.auth_hash }
|
53
|
+
subject { strategy.auth_hash[:user_info] }
|
39
54
|
|
40
55
|
specify { should include(:GLBID => "GLBID") }
|
41
56
|
specify { should include(:id => "21737810") }
|
42
57
|
specify { should include(:email => "fab1@spam.la") }
|
43
58
|
specify { should include(:status => "ATIVO") }
|
44
|
-
specify { should include(:
|
59
|
+
specify { should include(:nickname => "fabricio_fab1") }
|
45
60
|
specify { should include(:name => "Fabricio Rodrigo Lopes") }
|
46
61
|
specify { should include(:address => "Rua Uruguai, 59") }
|
47
62
|
specify { should include(:suburb => "Andaraí") }
|
data/spec/spec_helper.rb
CHANGED