oa-cadun 0.2.2 → 0.3

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/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm 1.9.2@oa-cadun
1
+ rvm 1.9.2@cadun
@@ -1,3 +1,3 @@
1
1
  module OACadun
2
- VERSION = '0.2.2'
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
- @params = CGI.parse(URI.parse(env['REQUEST_URI']).query)
18
- @glb_id = params['GLBID'].first
19
- @url = params['url'].first
20
-
21
- { :GLBID => glb_id,
22
- :url => url,
23
- :id => user.id,
24
- :email => user.email,
25
- :status => user.status,
26
- :username => user.login,
27
- :name => user.name,
28
- :address => user.address,
29
- :suburb => user.suburb,
30
- :city => user.city,
31
- :state => user.state,
32
- :country => user.country,
33
- :gender => user.gender,
34
- :birthday => user.birthday.strftime('%d/%m/%Y'),
35
- :mobile => user.mobile,
36
- :phone => user.phone,
37
- :cpf => user.cpf }
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(glb_id, env['REMOTE_ADDR'], service_id)
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
- before do
11
- @status, @headers, @body = OmniAuth::Strategies::Cadun.new(app, :service_id => 1).request_phase
12
- end
13
-
14
- describe "status" do
15
- subject { @status }
16
- specify { should == 302 }
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
- describe "headers" do
20
- subject { @headers }
21
- specify { should include("Location" => "https://login.dev.globoi.com/login/1") }
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(:username => "fabricio_fab1") }
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
@@ -1,5 +1,6 @@
1
1
  require "#{File.dirname(__FILE__)}/../lib/oa-cadun"
2
2
  require 'fakeweb'
3
+ require 'rack/mock'
3
4
 
4
5
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
5
6
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: oa-cadun
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.2
5
+ version: "0.3"
6
6
  platform: ruby
7
7
  authors:
8
8
  - Bruno Azisaka Maciel