cadun 0.3.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
data/cadun.gemspec CHANGED
@@ -7,18 +7,20 @@ Gem::Specification.new do |s|
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = %w(Bruno Azisaka Maciel)
9
9
  s.email = %w(bruno@azisaka.com.br)
10
- s.homepage = 'https://github.com/azisaka/Cadun'
11
- s.summary = 'A wrapper for the CadUn authentication/authorization API'
12
- s.description = 'A wrapper for the CadUn authentication/authorization API'
13
-
14
- s.rubyforge_project = 'cadun'
10
+ s.homepage = ''
11
+ s.summary = "A wrapper for the Globo.com's authentication/authorization API"
12
+ s.description = "A wrapper for the Globo.com's authentication/authorization API"
15
13
 
16
14
  s.files = `git ls-files`.split("\n")
17
15
  s.test_files = `git ls-files -- {spec}/*`.split("\n")
18
16
  s.require_paths = %w(lib)
19
17
 
20
- s.add_dependency 'nokogiri'
21
- s.add_development_dependency 'rack'
18
+ s.add_dependency 'activesupport', '>= 3.0.0'
19
+ s.add_dependency 'builder', '>= 2.1.2'
20
+ s.add_dependency 'rest-client'
21
+ s.add_dependency 'json'
22
+ s.add_dependency 'i18n'
23
+ s.add_development_dependency 'rake'
22
24
  s.add_development_dependency 'rspec'
23
25
  s.add_development_dependency 'rr'
24
26
  s.add_development_dependency 'fakeweb'
data/lib/cadun.rb CHANGED
@@ -1,12 +1,10 @@
1
- $:.push File.expand_path('lib', __FILE__)
2
-
3
- require 'uri'
4
- require 'cgi'
5
- require 'net/http'
6
- require 'nokogiri'
7
1
  require 'date'
8
2
  require 'yaml'
9
3
  require 'singleton'
10
- require 'cadun/gateway'
11
- require 'cadun/user'
12
- require 'cadun/config'
4
+ require 'rest_client'
5
+ require 'json'
6
+ require 'active_support/core_ext/hash'
7
+ require "#{File.dirname(__FILE__)}/cadun/gateway/authorization"
8
+ require "#{File.dirname(__FILE__)}/cadun/gateway/provisioning"
9
+ require "#{File.dirname(__FILE__)}/cadun/user"
10
+ require "#{File.dirname(__FILE__)}/cadun/config"
@@ -0,0 +1,43 @@
1
+ module Cadun
2
+ module Gateway
3
+ class Authorization
4
+ attr_reader :options, :connection
5
+
6
+ def initialize(options = {})
7
+ @options = options
8
+ end
9
+
10
+ def content
11
+ @content ||= Hash.from_xml(content_resource)["pessoa"]
12
+ end
13
+
14
+ def authorization
15
+ @authorization ||= Hash.from_xml(authorization_resource)["usuarioAutorizado"]
16
+ end
17
+
18
+ protected
19
+ def content_resource
20
+ subject = if options[:email]
21
+ "email/#{options[:email]}"
22
+
23
+ elsif options[:cadun_id]
24
+ options[:cadun_id]
25
+
26
+ else
27
+ raise RuntimeError.new "not authorized" unless authorization["status"] == "AUTORIZADO"
28
+ authorization["usuarioID"]
29
+ end
30
+
31
+ RestClient.get("#{Config.auth_url}/cadunii/ws/resources/pessoa/#{subject}", :content_type => "text/xml")
32
+ end
33
+
34
+ def authorization_resource
35
+ [:glb_id, :ip, :service_id].each { |arg| raise RuntimeError.new("#{arg} is missing") unless options[arg] }
36
+
37
+ authorization_data = { "glbId" => options[:glb_id], "ip" => options[:ip], "servicoID" => options[:service_id] }.to_xml(:root => "usuarioAutorizado", :indent => 0)
38
+
39
+ RestClient.put("#{Config.auth_url}/ws/rest/autorizacao", authorization_data, :content_type => "text/xml")
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,13 @@
1
+ module Cadun
2
+ module Gateway
3
+ class Provisioning < Authorization
4
+ def provision(user_id, service_id)
5
+ begin
6
+ RestClient.put("#{Config.restclient_url}/service/provisionamento", "{\"usuarioId\": \"#{user_id}\", \"servicoId\": \"#{service_id}\"}", :content_type => "text/javascript").code == 200
7
+ rescue RestClient::NotModified
8
+ false
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
data/lib/cadun/user.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Cadun
2
2
  class User
3
- attr_reader :gateway
3
+ attr_reader :authorization_gateway, :provisioning_gateway
4
4
 
5
5
  { "id" => "cadun_id",
6
6
  "nome" => "name",
@@ -8,12 +8,9 @@ module Cadun
8
8
  "tipoUsuario" => "user_type",
9
9
  "sexo" => "gender",
10
10
  "bairro" => "neighborhood",
11
- "cidade/nome" => "city",
12
- "estado/sigla" => "state",
13
- "pais/nome" => "country",
14
11
  "cep" => "zipcode",
15
12
  "complemento" => "complement" }.each do |path, method|
16
- define_method(method) { gateway.content.xpath(path).text }
13
+ define_method(method) { authorization_gateway.content[path] }
17
14
  end
18
15
 
19
16
  alias :id :cadun_id
@@ -28,7 +25,8 @@ module Cadun
28
25
  end
29
26
 
30
27
  def initialize(options = {})
31
- @gateway = Gateway.new(options)
28
+ @authorization_gateway = Gateway::Authorization.new(options)
29
+ @provisioning_gateway = Gateway::Provisioning.new(options)
32
30
  end
33
31
 
34
32
  def address
@@ -47,12 +45,28 @@ module Cadun
47
45
  "#{telefoneCelularDdd} #{telefoneCelular}"
48
46
  end
49
47
 
48
+ def country
49
+ pais['nome']
50
+ end
51
+
52
+ def city
53
+ cidade['nome']
54
+ end
55
+
56
+ def state
57
+ estado['sigla']
58
+ end
59
+
50
60
  def to_hash
51
61
  %w(cadun_id name email user_type gender neighborhood city state country address birthday phone mobile login cpf zipcode status complement).inject(Hash.new(0)) { |hash, method| hash[method.to_sym] = send(method); hash }
52
62
  end
53
63
 
64
+ def provision_to_service(service_id)
65
+ provisioning_gateway.provision(self.id, service_id)
66
+ end
67
+
54
68
  def method_missing(method)
55
- gateway.content.xpath(method.to_s).text
69
+ authorization_gateway.content[method.to_s]
56
70
  end
57
71
  end
58
72
  end
data/lib/cadun/version.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  module Cadun
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 3
5
- TINY = 3
4
+ MINOR = 5
5
+ PATCH = 4
6
6
 
7
- STRING = [MAJOR, MINOR, TINY] * '.'
7
+ STRING = [MAJOR, MINOR, PATCH] * '.'
8
8
  end
9
9
  end
@@ -1,35 +1,29 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Cadun::Config do
4
- include Cadun
5
-
6
4
  def self.verify_method(method, value)
7
5
  describe "##{method}" do
8
6
  subject { Cadun::Config.send(method) }
9
-
10
7
  specify { should == value }
11
8
  end
12
9
  end
13
10
 
14
11
  before { load_config }
15
12
 
16
- verify_method "login_url", "https://login.dev.globoi.com/login"
13
+ verify_method "login_url", "https://login.qa01.globoi.com/login"
17
14
 
18
- verify_method "logout_url", "https://login.dev.globoi.com/Servlet/do/logout"
15
+ verify_method "logout_url", "https://login.qa01.globoi.com/Servlet/do/logout"
19
16
 
20
- verify_method "auth_url", "isp-authenticator.dev.globoi.com"
21
-
22
- verify_method "auth_port", 8280
17
+ verify_method "auth_url", "http://isp-authenticator.qa01.globoi.com:8280"
23
18
 
24
19
  context "when the file changes" do
20
+
25
21
  before { load_another_config }
26
22
 
27
23
  verify_method "login_url", "https://login.globo.com/login"
28
24
 
29
25
  verify_method "logout_url", "https://login.globo.com/Servlet/do/logout"
30
26
 
31
- verify_method "auth_url", "autenticacao.globo.com"
32
-
33
- verify_method "auth_port", 8080
27
+ verify_method "auth_url", "http://autenticacao.globo.com:8080"
34
28
  end
35
29
  end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cadun::Gateway::Authorization do
4
+ let(:response) { mock }
5
+
6
+ before do
7
+ load_config
8
+ end
9
+
10
+ describe "#content" do
11
+ let(:gateway) { Cadun::Gateway::Authorization.new(:glb_id => "GLB_ID", :ip => "127.0.0.1", :service_id => 2626) }
12
+
13
+ context "when status not AUTORIZADO" do
14
+ before do
15
+ FakeWeb.register_uri(:put, "http://isp-authenticator.qa01.globoi.com:8280/ws/rest/autorizacao", :body => "<?xml version='1.0' encoding='utf-8'?><usuarioAutorizado><status>NAO_AUTORIZADO</status><usuarioID>1</usuarioID></usuarioAutorizado>")
16
+ end
17
+
18
+ it { proc { gateway.content }.should raise_error(RuntimeError, "not authorized") }
19
+ end
20
+
21
+ context "when status AUTORIZADO" do
22
+ before do
23
+ FakeWeb.register_uri(:put, "http://isp-authenticator.qa01.globoi.com:8280/ws/rest/autorizacao", :body => "<?xml version='1.0' encoding='utf-8'?><usuarioAutorizado><status>AUTORIZADO</status><usuarioID>1</usuarioID></usuarioAutorizado>")
24
+ FakeWeb.register_uri(:get, "http://isp-authenticator.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/1", :body => "<?xml version='1.0' encoding='utf-8'?><pessoa><nome>Barack Obama</nome></pessoa>")
25
+ end
26
+
27
+ it { proc { gateway.content }.should_not raise_error(RuntimeError, "not authorized") }
28
+
29
+ it "should parse the resource" do
30
+ gateway.content['nome'].should == 'Barack Obama'
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "#authorization" do
36
+ context "when all information is given" do
37
+ let(:gateway) { Cadun::Gateway::Authorization.new(:glb_id => "GLB_ID", :ip => "127.0.0.1", :service_id => 2626) }
38
+
39
+ before do
40
+ FakeWeb.register_uri(:put, "http://isp-authenticator.qa01.globoi.com:8280/ws/rest/autorizacao", :body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?><usuarioAutorizado><glbId>GLB_ID</glbId><ip>127.0.0.1</ip><servicoID type=\"integer\">2626</servicoID></usuarioAutorizado>", :body => "<?xml version='1.0' encoding='utf-8'?><usuarioAutorizado><status>AUTORIZADO</status><usuarioID>1</usuarioID></usuarioAutorizado>")
41
+ end
42
+
43
+ it "should parse the authorization request" do
44
+ gateway.authorization['usuarioID'].should == '1'
45
+ end
46
+
47
+ end
48
+
49
+ context "when glb_id is not given" do
50
+ let(:gateway) { Cadun::Gateway::Authorization.new }
51
+ it { proc { gateway.authorization }.should raise_error(RuntimeError, "glb_id is missing") }
52
+ end
53
+
54
+ context "when ip is not given" do
55
+ let(:gateway) { Cadun::Gateway::Authorization.new(:glb_id => "1") }
56
+ it { proc { gateway.authorization }.should raise_error(RuntimeError, "ip is missing") }
57
+ end
58
+
59
+ context "when service_id is not given" do
60
+ let(:gateway) { Cadun::Gateway::Authorization.new(:glb_id => "1", :ip => "1") }
61
+ it { proc { gateway.authorization }.should raise_error(RuntimeError, "service_id is missing") }
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cadun::Gateway::Provisioning do
4
+ before { load_config }
5
+
6
+ describe "#provision" do
7
+ let(:gateway) { Cadun::Gateway::Provisioning.new }
8
+
9
+ context "when the service is provisioned to the user" do
10
+ before do
11
+ FakeWeb.register_uri(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento", :status => 200)
12
+ end
13
+
14
+ subject { gateway.provision(123456, 2515) }
15
+ specify { should be_true }
16
+ end
17
+
18
+ context "when the service is provisioned to the user" do
19
+ before do
20
+ FakeWeb.register_uri(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento", :status => 304)
21
+ end
22
+
23
+ subject { gateway.provision(123456, 2515) }
24
+ specify { should be_false }
25
+ end
26
+ end
27
+ end
@@ -18,7 +18,7 @@ describe Cadun::User do
18
18
  subject { Cadun::User.new :ip => "127.0.0.1", :service_id => 2626, :glb_id => "GLB_ID" }
19
19
 
20
20
  it "should load the gateway" do
21
- mock(Cadun::Gateway).new(hash_including(:ip => "127.0.0.1", :service_id => 2626, :glb_id => "GLB_ID"))
21
+ mock(Cadun::Gateway::Authorization).new(hash_including(:ip => "127.0.0.1", :service_id => 2626, :glb_id => "GLB_ID"))
22
22
  subject
23
23
  end
24
24
 
@@ -81,4 +81,14 @@ describe Cadun::User do
81
81
  subject { Cadun::User.find_by_id("10001000") }
82
82
  verify_method "id", "10001000"
83
83
  end
84
+
85
+ describe "#provision_to_service" do
86
+ it "should call gateway's provision" do
87
+ mock(Cadun::Gateway::Provisioning).new(anything) { mock('gateway').provision(1, 6969) }
88
+
89
+ user = Cadun::User.new
90
+ mock(user).id { 1 }
91
+ user.provision_to_service(6969)
92
+ end
93
+ end
84
94
  end
data/spec/spec_helper.rb CHANGED
@@ -3,35 +3,29 @@ require 'fakeweb'
3
3
 
4
4
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
5
5
 
6
- RSpec.configure do |config|
7
- config.before :suite do
8
- FakeWeb.allow_net_connect = false
9
- end
10
-
11
- config.before :each do
12
- FakeWeb.clean_registry
13
- end
14
-
6
+ RSpec.configure do |config|
15
7
  config.mock_with :rr
16
8
  config.filter_run :focus => true
17
9
  config.run_all_when_everything_filtered = true
10
+
11
+ config.before(:suite) do
12
+ FakeWeb.allow_net_connect = false
13
+ end
18
14
  end
19
15
 
20
16
  def stub_requests
21
- FakeWeb.register_uri :put, "http://isp-authenticator.dev.globoi.com:8280/ws/rest/autorizacao",
22
- :body => "#{File.dirname(__FILE__)}/support/fixtures/autorizacao.xml"
23
-
24
- FakeWeb.register_uri :get, "http://isp-authenticator.dev.globoi.com:8280/cadunii/ws/resources/pessoa/21737810",
25
- :body => "#{File.dirname(__FILE__)}/support/fixtures/pessoa.xml"
26
-
27
- FakeWeb.register_uri :get, "http://isp-authenticator.dev.globoi.com:8280/cadunii/ws/resources/pessoa/10001000",
28
- :body => "#{File.dirname(__FILE__)}/support/fixtures/pessoa_2.xml"
29
-
30
- FakeWeb.register_uri :get, "http://isp-authenticator.dev.globoi.com:8280/cadunii/ws/resources/pessoa/email/silvano@globo.com",
31
- :body => "#{File.dirname(__FILE__)}/support/fixtures/email.xml"
32
-
33
- FakeWeb.register_uri :get, "http://isp-authenticator.dev.globoi.com:8280/cadunii/ws/resources/pessoa/email/silvano@corp.globo.com",
34
- :body => "#{File.dirname(__FILE__)}/support/fixtures/email.xml"
17
+ FakeWeb.register_uri(:put, "http://isp-authenticator.qa01.globoi.com:8280/ws/rest/autorizacao",
18
+ :body => "#{File.dirname(__FILE__)}/support/fixtures/autorizacao.xml")
19
+ FakeWeb.register_uri(:get, "http://isp-authenticator.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/21737810",
20
+ :body => "#{File.dirname(__FILE__)}/support/fixtures/pessoa.xml")
21
+ FakeWeb.register_uri(:get, "http://isp-authenticator.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/10001000",
22
+ :body => "#{File.dirname(__FILE__)}/support/fixtures/pessoa_2.xml")
23
+ FakeWeb.register_uri(:get, "http://isp-authenticator.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/email/silvano@globo.com",
24
+ :body => "#{File.dirname(__FILE__)}/support/fixtures/email.xml")
25
+ FakeWeb.register_uri(:get, "http://isp-authenticator.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/email/silvano@corp.globo.com",
26
+ :body => "#{File.dirname(__FILE__)}/support/fixtures/email.xml")
27
+ FakeWeb.register_uri(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento",
28
+ :body => "#{File.dirname(__FILE__)}/support/fixtures/provisionamento.json", :status => 200)
35
29
  end
36
30
 
37
31
  def load_config
@@ -1,5 +1,5 @@
1
1
  cadun:
2
2
  logout_url: https://login.globo.com/Servlet/do/logout
3
3
  login_url: https://login.globo.com/login
4
- auth_url: autenticacao.globo.com
5
- auth_port: 8080
4
+ auth_url: http://autenticacao.globo.com:8080
5
+ restclient_url: http://cadun-rest.globoi.com
@@ -1,5 +1,5 @@
1
1
  cadun:
2
- logout_url: https://login.dev.globoi.com/Servlet/do/logout
3
- login_url: https://login.dev.globoi.com/login
4
- auth_url: isp-authenticator.dev.globoi.com
5
- auth_port: 8280
2
+ logout_url: https://login.qa01.globoi.com/Servlet/do/logout
3
+ login_url: https://login.qa01.globoi.com/login
4
+ auth_url: http://isp-authenticator.qa01.globoi.com:8280
5
+ restclient_url: http://cadun-rest.qa01.globoi.com
@@ -0,0 +1 @@
1
+ {"usuarioId": "10001000", "servicoId": "2626" }
metadata CHANGED
@@ -1,84 +1,124 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cadun
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.4
4
5
  prerelease:
5
- version: 0.3.3
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Bruno
9
9
  - Azisaka
10
10
  - Maciel
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
-
15
- date: 2011-06-08 00:00:00 Z
16
- dependencies:
17
- - !ruby/object:Gem::Dependency
18
- name: nokogiri
14
+ date: 2011-07-27 00:00:00.000000000Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: activesupport
18
+ requirement: &2153540860 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: 3.0.0
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *2153540860
27
+ - !ruby/object:Gem::Dependency
28
+ name: builder
29
+ requirement: &2153540360 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: 2.1.2
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *2153540360
38
+ - !ruby/object:Gem::Dependency
39
+ name: rest-client
40
+ requirement: &2153539980 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *2153539980
49
+ - !ruby/object:Gem::Dependency
50
+ name: json
51
+ requirement: &2153539520 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ type: :runtime
19
58
  prerelease: false
20
- requirement: &id001 !ruby/object:Gem::Requirement
59
+ version_requirements: *2153539520
60
+ - !ruby/object:Gem::Dependency
61
+ name: i18n
62
+ requirement: &2153539100 !ruby/object:Gem::Requirement
21
63
  none: false
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
25
- version: "0"
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
26
68
  type: :runtime
27
- version_requirements: *id001
28
- - !ruby/object:Gem::Dependency
29
- name: rack
30
69
  prerelease: false
31
- requirement: &id002 !ruby/object:Gem::Requirement
70
+ version_requirements: *2153539100
71
+ - !ruby/object:Gem::Dependency
72
+ name: rake
73
+ requirement: &2153538680 !ruby/object:Gem::Requirement
32
74
  none: false
33
- requirements:
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: "0"
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
37
79
  type: :development
38
- version_requirements: *id002
39
- - !ruby/object:Gem::Dependency
40
- name: rspec
41
80
  prerelease: false
42
- requirement: &id003 !ruby/object:Gem::Requirement
81
+ version_requirements: *2153538680
82
+ - !ruby/object:Gem::Dependency
83
+ name: rspec
84
+ requirement: &2153538260 !ruby/object:Gem::Requirement
43
85
  none: false
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: "0"
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
48
90
  type: :development
49
- version_requirements: *id003
50
- - !ruby/object:Gem::Dependency
51
- name: rr
52
91
  prerelease: false
53
- requirement: &id004 !ruby/object:Gem::Requirement
92
+ version_requirements: *2153538260
93
+ - !ruby/object:Gem::Dependency
94
+ name: rr
95
+ requirement: &2153537840 !ruby/object:Gem::Requirement
54
96
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- version: "0"
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
59
101
  type: :development
60
- version_requirements: *id004
61
- - !ruby/object:Gem::Dependency
62
- name: fakeweb
63
102
  prerelease: false
64
- requirement: &id005 !ruby/object:Gem::Requirement
103
+ version_requirements: *2153537840
104
+ - !ruby/object:Gem::Dependency
105
+ name: fakeweb
106
+ requirement: &2153537420 !ruby/object:Gem::Requirement
65
107
  none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: "0"
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
70
112
  type: :development
71
- version_requirements: *id005
72
- description: A wrapper for the CadUn authentication/authorization API
73
- email:
113
+ prerelease: false
114
+ version_requirements: *2153537420
115
+ description: A wrapper for the Globo.com's authentication/authorization API
116
+ email:
74
117
  - bruno@azisaka.com.br
75
118
  executables: []
76
-
77
119
  extensions: []
78
-
79
120
  extra_rdoc_files: []
80
-
81
- files:
121
+ files:
82
122
  - .gitignore
83
123
  - .rspec
84
124
  - Gemfile
@@ -86,13 +126,15 @@ files:
86
126
  - cadun.gemspec
87
127
  - lib/cadun.rb
88
128
  - lib/cadun/config.rb
89
- - lib/cadun/gateway.rb
129
+ - lib/cadun/gateway/authorization.rb
130
+ - lib/cadun/gateway/provisioning.rb
90
131
  - lib/cadun/user.rb
91
132
  - lib/cadun/version.rb
92
133
  - script/console
93
134
  - script/loader.rb
94
135
  - spec/cadun/config_spec.rb
95
- - spec/cadun/gateway_spec.rb
136
+ - spec/cadun/gateway/authorization_spec.rb
137
+ - spec/cadun/gateway/provisioning_spec.rb
96
138
  - spec/cadun/user_spec.rb
97
139
  - spec/spec_helper.rb
98
140
  - spec/support/fixtures/another_config.yml
@@ -101,32 +143,29 @@ files:
101
143
  - spec/support/fixtures/email.xml
102
144
  - spec/support/fixtures/pessoa.xml
103
145
  - spec/support/fixtures/pessoa_2.xml
104
- homepage: https://github.com/azisaka/Cadun
146
+ - spec/support/fixtures/provisionamento.json
147
+ homepage: ''
105
148
  licenses: []
106
-
107
149
  post_install_message:
108
150
  rdoc_options: []
109
-
110
- require_paths:
151
+ require_paths:
111
152
  - lib
112
- required_ruby_version: !ruby/object:Gem::Requirement
153
+ required_ruby_version: !ruby/object:Gem::Requirement
113
154
  none: false
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: "0"
118
- required_rubygems_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
160
  none: false
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- version: "0"
161
+ requirements:
162
+ - - ! '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
124
165
  requirements: []
125
-
126
- rubyforge_project: cadun
127
- rubygems_version: 1.8.4
166
+ rubyforge_project:
167
+ rubygems_version: 1.8.6
128
168
  signing_key:
129
169
  specification_version: 3
130
- summary: A wrapper for the CadUn authentication/authorization API
170
+ summary: A wrapper for the Globo.com's authentication/authorization API
131
171
  test_files: []
132
-
data/lib/cadun/gateway.rb DELETED
@@ -1,49 +0,0 @@
1
- module Cadun
2
- class Gateway
3
- def initialize(options = {})
4
- @options = options
5
- end
6
-
7
- def content
8
- @content ||= Nokogiri::XML(content_resource).children
9
- end
10
-
11
- def authorization
12
- @authorization ||= Nokogiri::XML(authorization_resource).children
13
- end
14
-
15
- def connection
16
- @connection ||= Net::HTTP.new(Config.auth_url, Config.auth_port)
17
- end
18
-
19
- protected
20
- def content_resource
21
- subject = if @options[:email]
22
- "email/#{@options[:email]}"
23
- elsif @options[:cadun_id]
24
- @options[:cadun_id]
25
- else
26
- raise RuntimeError.new "not authorized" unless authorization.xpath("status").text == "AUTORIZADO"
27
- authorization.xpath("usuarioID").text
28
- end
29
-
30
- get "/cadunii/ws/resources/pessoa/#{subject}"
31
- end
32
-
33
- def get(path)
34
- connection.get(path, {'Content-Type' => 'text/xml'}).body
35
- end
36
-
37
- def authorization_resource
38
- [:glb_id, :ip, :service_id].each do |arg|
39
- raise RuntimeError.new("#{arg} is missing") unless @options[arg]
40
- end
41
-
42
- put "/ws/rest/autorizacao", "<usuarioAutorizado><glbId>#{@options[:glb_id]}</glbId><ip>#{@options[:ip]}</ip><servicoID>#{@options[:service_id]}</servicoID></usuarioAutorizado>"
43
- end
44
-
45
- def put(path, data)
46
- connection.put(path, data, {'Content-Type' => 'text/xml'}).body
47
- end
48
- end
49
- end
@@ -1,73 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Cadun::Gateway do
4
- let(:connection) { mock }
5
- let(:response) { mock }
6
-
7
- before { load_config }
8
-
9
- describe "#content" do
10
- let(:gateway) { Cadun::Gateway.new(:glb_id => "GLB_ID", :ip => "127.0.0.1", :service_id => 2626) }
11
-
12
- context "when status not AUTORIZADO" do
13
- before do
14
- mock(gateway).connection { connection }
15
-
16
- mock(response).body { "<?xml version='1.0' encoding='utf-8'?><usuarioAutorizado><status>NAO_AUTORIZADO</status><usuarioID>1</usuarioID></usuarioAutorizado>" }
17
- mock(connection).put("/ws/rest/autorizacao", "<usuarioAutorizado><glbId>GLB_ID</glbId><ip>127.0.0.1</ip><servicoID>2626</servicoID></usuarioAutorizado>", {'Content-Type' => 'text/xml'}) { response }
18
- end
19
-
20
- it { proc { gateway.content }.should raise_error(RuntimeError, "not authorized") }
21
- end
22
-
23
- context "when status AUTORIZADO" do
24
- before do
25
- mock(gateway).connection.twice { connection }
26
-
27
- mock(response).body { "<?xml version='1.0' encoding='utf-8'?><usuarioAutorizado><status>AUTORIZADO</status><usuarioID>1</usuarioID></usuarioAutorizado>" }
28
- mock(connection).put("/ws/rest/autorizacao", "<usuarioAutorizado><glbId>GLB_ID</glbId><ip>127.0.0.1</ip><servicoID>2626</servicoID></usuarioAutorizado>", {'Content-Type' => 'text/xml'}) { response }
29
- mock(response).body { "<?xml version='1.0' encoding='utf-8'?><pessoa><nome>Barack Obama</nome></pessoa>" }
30
- mock(connection).get("/cadunii/ws/resources/pessoa/1", {'Content-Type' => 'text/xml'}) { response }
31
- end
32
-
33
- it { proc { gateway.content }.should_not raise_error(RuntimeError, "not authorized") }
34
-
35
- it "should parse the resource" do
36
- gateway.content.xpath('nome').text.should == 'Barack Obama'
37
- end
38
- end
39
- end
40
-
41
- describe "#authorization" do
42
- context "when all information is given" do
43
- let(:gateway) { Cadun::Gateway.new(:glb_id => "GLB_ID", :ip => "127.0.0.1", :service_id => 2626) }
44
-
45
- before do
46
- mock(gateway).connection { connection }
47
-
48
- mock(response).body { "<?xml version='1.0' encoding='utf-8'?><pessoa><usuarioID>1</id></usuarioID>" }
49
- mock(connection).put("/ws/rest/autorizacao", "<usuarioAutorizado><glbId>GLB_ID</glbId><ip>127.0.0.1</ip><servicoID>2626</servicoID></usuarioAutorizado>", {'Content-Type' => 'text/xml'}) { response }
50
- end
51
-
52
- it "should parse the authorization request" do
53
- gateway.authorization.xpath('usuarioID').text.should == '1'
54
- end
55
-
56
- end
57
-
58
- context "when glb_id is not given" do
59
- let(:gateway) { Cadun::Gateway.new }
60
- it { proc { gateway.authorization }.should raise_error(RuntimeError, "glb_id is missing") }
61
- end
62
-
63
- context "when ip is not given" do
64
- let(:gateway) { Cadun::Gateway.new(:glb_id => "1") }
65
- it { proc { gateway.authorization }.should raise_error(RuntimeError, "ip is missing") }
66
- end
67
-
68
- context "when service_id is not given" do
69
- let(:gateway) { Cadun::Gateway.new(:glb_id => "1", :ip => "1") }
70
- it { proc { gateway.authorization }.should raise_error(RuntimeError, "service_id is missing") }
71
- end
72
- end
73
- end