cadun 0.6.1 → 0.6.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/{bench → benchmark}/curl_x_restclient.rb +0 -0
- data/lib/cadun/gateway.rb +14 -8
- data/lib/cadun/user.rb +1 -1
- data/lib/cadun/version.rb +1 -1
- data/spec/cadun/config_spec.rb +8 -19
- data/spec/cadun/gateway_spec.rb +19 -42
- data/spec/cadun/user_spec.rb +45 -51
- metadata +20 -22
- data/script/console +0 -3
- data/script/loader.rb +0 -3
File without changes
|
data/lib/cadun/gateway.rb
CHANGED
@@ -19,15 +19,20 @@ module Cadun
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def content_resource
|
22
|
-
|
23
|
-
|
24
|
-
else
|
25
|
-
raise Exception.new(authorization["status"]) unless authorization["status"] == "AUTORIZADO"
|
26
|
-
authorization["usuarioID"]
|
27
|
-
end
|
22
|
+
Curl::Easy.perform("#{Config.auth_url}/cadunii/ws/resources/pessoa/#{subject}").body_str
|
23
|
+
end
|
28
24
|
|
29
|
-
|
30
|
-
|
25
|
+
def subject
|
26
|
+
if opts[:email]; "email/#{opts[:email]}"
|
27
|
+
elsif opts[:cadun_id]; opts[:cadun_id]
|
28
|
+
else
|
29
|
+
raise Exception.new(authorization["status"]) unless authorized?
|
30
|
+
authorization["usuarioID"]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def authorized?
|
35
|
+
authorization["status"] == "AUTORIZADO"
|
31
36
|
end
|
32
37
|
|
33
38
|
def authorization
|
@@ -36,6 +41,7 @@ module Cadun
|
|
36
41
|
|
37
42
|
def authorization_resource
|
38
43
|
%w(glb_id ip service_id).each { |i| raise ArgumentError.new("#{i} is missing") unless opts[i.to_sym] }
|
44
|
+
|
39
45
|
authorization_data = { "glbId" => opts[:glb_id], "ip" => opts[:ip], "servicoID" => opts[:service_id] }.to_xml(:root => "usuarioAutorizado", :indent => 0)
|
40
46
|
|
41
47
|
request = Curl::Easy.http_put("#{Config.auth_url}/ws/rest/autorizacao", authorization_data) do |curl|
|
data/lib/cadun/user.rb
CHANGED
data/lib/cadun/version.rb
CHANGED
data/spec/cadun/config_spec.rb
CHANGED
@@ -1,29 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Cadun::Config do
|
4
|
-
def self.verify_method(method, value)
|
5
|
-
describe "##{method}" do
|
6
|
-
subject { Cadun::Config.send(method) }
|
7
|
-
specify { should == value }
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
4
|
before { load_config }
|
5
|
+
subject { Cadun::Config }
|
12
6
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
verify_method "auth_url", "http://isp-authenticator.qa01.globoi.com:8280"
|
7
|
+
its(:login_url) { should == "https://login.qa01.globoi.com/login" }
|
8
|
+
its(:logout_url) { should == "https://login.qa01.globoi.com/Servlet/do/logout" }
|
9
|
+
its(:auth_url) { should == "http://isp-authenticator.qa01.globoi.com:8280" }
|
18
10
|
|
19
11
|
context "when the file changes" do
|
20
|
-
|
21
12
|
before { load_another_config }
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
verify_method "auth_url", "http://autenticacao.globo.com:8080"
|
13
|
+
|
14
|
+
its(:login_url) { should == "https://login.globo.com/login" }
|
15
|
+
its(:logout_url) { should == "https://login.globo.com/Servlet/do/logout" }
|
16
|
+
its(:auth_url) { should == "http://autenticacao.globo.com:8080" }
|
28
17
|
end
|
29
18
|
end
|
data/spec/cadun/gateway_spec.rb
CHANGED
@@ -3,46 +3,32 @@ require 'spec_helper'
|
|
3
3
|
describe Cadun::Gateway do
|
4
4
|
before { load_config }
|
5
5
|
|
6
|
-
describe "#provision" do
|
6
|
+
describe "#provision" do
|
7
|
+
subject { Cadun::Gateway.provision(123456, 2515) }
|
8
|
+
|
7
9
|
context "when the service is provisioned to the user" do
|
8
10
|
before { stub_request(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento").to_return(:status => [200]) }
|
9
|
-
|
10
|
-
subject { Cadun::Gateway.provision(123456, 2515) }
|
11
|
-
specify { should be_true }
|
11
|
+
it { should be_true }
|
12
12
|
end
|
13
13
|
|
14
|
-
context "when the service
|
14
|
+
context "when the service has been provisioned to the user" do
|
15
15
|
before { stub_request(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento").to_return(:status => [304]) }
|
16
|
-
|
17
|
-
subject { Cadun::Gateway.provision(123456, 2515) }
|
18
|
-
it { subject.should be_false }
|
16
|
+
it { should be_false }
|
19
17
|
end
|
20
18
|
|
21
19
|
context "when the service is not found" do
|
22
20
|
before { stub_request(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento").to_return(:status => [404]) }
|
23
|
-
|
24
|
-
subject { Cadun::Gateway.provision(123456, 2515) }
|
25
|
-
it { subject.should be_false }
|
21
|
+
it { should be_false }
|
26
22
|
end
|
27
|
-
|
28
|
-
context "when the service is not found" do
|
29
|
-
before { stub_request(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento").to_return(:status => [503]) }
|
30
|
-
|
31
|
-
subject { Cadun::Gateway.provision(123456, 2515) }
|
32
|
-
it { subject.should be_false }
|
33
|
-
end
|
34
|
-
|
35
23
|
end
|
36
24
|
|
37
25
|
describe "#content" do
|
38
26
|
let(:gateway) { Cadun::Gateway.new(:glb_id => "GLB_ID", :ip => "127.0.0.1", :service_id => 2626) }
|
27
|
+
subject { gateway.content }
|
39
28
|
|
40
29
|
context "when status not AUTORIZADO" do
|
41
|
-
before
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
it { proc { gateway.content }.should raise_error(Exception) }
|
30
|
+
before { stub_request(:put, "http://isp-authenticator.qa01.globoi.com:8280/ws/rest/autorizacao").to_return(:body => "<?xml version='1.0' encoding='utf-8'?><usuarioAutorizado><status>NAO_AUTORIZADO</status><usuarioID>1</usuarioID></usuarioAutorizado>") }
|
31
|
+
it { expect { subject }.to raise_error(Exception) }
|
46
32
|
end
|
47
33
|
|
48
34
|
context "when status AUTORIZADO" do
|
@@ -50,42 +36,33 @@ describe Cadun::Gateway do
|
|
50
36
|
stub_request(:put, "http://isp-authenticator.qa01.globoi.com:8280/ws/rest/autorizacao").to_return(:body => "<?xml version='1.0' encoding='utf-8'?><usuarioAutorizado><status>AUTORIZADO</status><usuarioID>1</usuarioID></usuarioAutorizado>")
|
51
37
|
stub_request(:get, "http://isp-authenticator.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/1").to_return(:body => "<?xml version='1.0' encoding='utf-8'?><pessoa><nome>Barack Obama</nome></pessoa>")
|
52
38
|
end
|
53
|
-
|
54
|
-
it {
|
55
|
-
|
56
|
-
it "should parse the resource" do
|
57
|
-
gateway.content['nome'].should == 'Barack Obama'
|
58
|
-
end
|
39
|
+
|
40
|
+
it { should include('nome' => 'Barack Obama') }
|
59
41
|
end
|
60
42
|
end
|
61
43
|
|
62
44
|
describe "#authorization" do
|
45
|
+
subject { gateway.authorization }
|
46
|
+
|
63
47
|
context "when all information is given" do
|
64
48
|
let(:gateway) { Cadun::Gateway.new(:glb_id => "GLB_ID", :ip => "127.0.0.1", :service_id => 2626) }
|
65
|
-
|
66
|
-
|
67
|
-
stub_request(:put, "http://isp-authenticator.qa01.globoi.com:8280/ws/rest/autorizacao").to_return(: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>")
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should parse the authorization request" do
|
71
|
-
gateway.authorization['usuarioID'].should == '1'
|
72
|
-
end
|
73
|
-
|
49
|
+
before { stub_request(:put, "http://isp-authenticator.qa01.globoi.com:8280/ws/rest/autorizacao").to_return(: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>") }
|
50
|
+
it { subject.should include('usuarioID' => '1') }
|
74
51
|
end
|
75
52
|
|
76
53
|
context "when glb_id is not given" do
|
77
54
|
let(:gateway) { Cadun::Gateway.new }
|
78
|
-
it {
|
55
|
+
it { expect { subject }.to raise_error(ArgumentError, "glb_id is missing") }
|
79
56
|
end
|
80
57
|
|
81
58
|
context "when ip is not given" do
|
82
59
|
let(:gateway) { Cadun::Gateway.new(:glb_id => "1") }
|
83
|
-
it {
|
60
|
+
it { expect { subject }.to raise_error(ArgumentError, "ip is missing") }
|
84
61
|
end
|
85
62
|
|
86
63
|
context "when service_id is not given" do
|
87
64
|
let(:gateway) { Cadun::Gateway.new(:glb_id => "1", :ip => "1") }
|
88
|
-
it {
|
65
|
+
it { expect { subject }.to raise_error(ArgumentError, "service_id is missing") }
|
89
66
|
end
|
90
67
|
end
|
91
68
|
end
|
data/spec/cadun/user_spec.rb
CHANGED
@@ -2,13 +2,6 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Cadun::User do
|
5
|
-
|
6
|
-
def self.verify_method(method, value)
|
7
|
-
describe "##{method}" do
|
8
|
-
specify { subject.send(method).should == value }
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
5
|
before do
|
13
6
|
load_config
|
14
7
|
stub_requests
|
@@ -30,74 +23,75 @@ describe Cadun::User do
|
|
30
23
|
subject
|
31
24
|
end
|
32
25
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
26
|
+
its(:id) { should == "21737810" }
|
27
|
+
its(:name) { should == "Fabricio Rodrigo Lopes" }
|
28
|
+
its(:birthday) { should == Date.new(1983, 02, 22) }
|
29
|
+
its(:phone) { should == "21 22881060" }
|
30
|
+
its(:mobile) { should == "21 99999999" }
|
31
|
+
its(:email) { should == "fab1@spam.la" }
|
32
|
+
its(:gender) { should == "MASCULINO" }
|
33
|
+
its(:city) { should == "Rio de Janeiro" }
|
34
|
+
its(:state) { should == "RJ" }
|
35
|
+
its(:status) { should == "ATIVO" }
|
36
|
+
its(:address) { should == "Rua Uruguai, 59" }
|
37
|
+
its(:neighborhood) { should == "Andaraí" }
|
38
|
+
its(:cpf) { should == "09532034765" }
|
39
|
+
its(:login) { should == "fabricio_fab1" }
|
40
|
+
its(:country) { should == "Brasil" }
|
41
|
+
its(:user_type) { should == "NAO_ASSINANTE" }
|
42
|
+
its(:cadun_id) { should == "21737810" }
|
43
|
+
its(:complement) { should == "807" }
|
51
44
|
end
|
52
45
|
|
53
46
|
describe "#to_hash" do
|
54
47
|
context "when the user has all data" do
|
55
48
|
subject { Cadun::User.new(:cadun_id => "10001000").to_hash }
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
49
|
+
|
50
|
+
it { should include :cadun_id => "10001000" }
|
51
|
+
it { should include :name => "Guilherme Chico" }
|
52
|
+
it { should include :email => "fab1@spam.la" }
|
53
|
+
it { should include :user_type => "NAO_ASSINANTE" }
|
54
|
+
it { should include :gender => "MASCULINO" }
|
55
|
+
it { should include :neighborhood => "Andaraí" }
|
56
|
+
it { should include :city => "Rio de Janeiro" }
|
57
|
+
it { should include :state => "RJ" }
|
58
|
+
it { should include :country => "Brasil" }
|
59
|
+
it { should include :address => "Rua Uruguai, 59" }
|
60
|
+
it { should include :birthday => Date.new(1983, 02, 22) }
|
61
|
+
it { should include :phone => "21 22881060" }
|
62
|
+
it { should include :mobile => "21 99999999" }
|
63
|
+
it { should include :login => "fabricio_fab1" }
|
64
|
+
it { should include :cpf => "09532034765" }
|
65
|
+
it { should include :zipcode => "20510060" }
|
66
|
+
it { should include :status => "ATIVO" }
|
67
|
+
it { should include :complement => "807" }
|
75
68
|
end
|
76
69
|
|
77
70
|
context "when the user has minimal data" do
|
78
71
|
subject { Cadun::User.find_by_email("fulano_adm_campanha@globomail.com") }
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
72
|
+
|
73
|
+
its(:id) { should == "23370159" }
|
74
|
+
its(:city) { should be_nil }
|
75
|
+
its(:state) { should be_nil }
|
76
|
+
its(:country) { should be_nil }
|
83
77
|
end
|
84
78
|
end
|
85
79
|
|
86
80
|
describe ".find_by_email" do
|
87
81
|
context "given an email without domain" do
|
88
82
|
subject { Cadun::User.find_by_email("silvano") }
|
89
|
-
|
83
|
+
its(:id) { should == "24510533" }
|
90
84
|
end
|
91
85
|
|
92
86
|
context "given an email with domain" do
|
93
87
|
subject { Cadun::User.find_by_email("silvano@corp.globo.com") }
|
94
|
-
|
88
|
+
its(:id) { should == "24510533" }
|
95
89
|
end
|
96
90
|
end
|
97
91
|
|
98
92
|
describe ".find_by_id" do
|
99
93
|
subject { Cadun::User.find_by_id("10001000") }
|
100
|
-
|
94
|
+
its(:id) { should == "10001000" }
|
101
95
|
end
|
102
96
|
|
103
97
|
describe "#provision_to_service" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cadun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,11 +11,11 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2011-
|
14
|
+
date: 2011-11-24 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: i18n
|
18
|
-
requirement: &
|
18
|
+
requirement: &70300104786900 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ! '>='
|
@@ -23,10 +23,10 @@ dependencies:
|
|
23
23
|
version: '0'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *70300104786900
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
|
-
requirement: &
|
29
|
+
requirement: &70300104779400 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ! '>='
|
@@ -34,10 +34,10 @@ dependencies:
|
|
34
34
|
version: 3.0.0
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *70300104779400
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: builder
|
40
|
-
requirement: &
|
40
|
+
requirement: &70300104778780 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
@@ -45,10 +45,10 @@ dependencies:
|
|
45
45
|
version: 2.1.2
|
46
46
|
type: :runtime
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *
|
48
|
+
version_requirements: *70300104778780
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: curb
|
51
|
-
requirement: &
|
51
|
+
requirement: &70300104636920 !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: :runtime
|
58
58
|
prerelease: false
|
59
|
-
version_requirements: *
|
59
|
+
version_requirements: *70300104636920
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: rake
|
62
|
-
requirement: &
|
62
|
+
requirement: &70300104634980 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
64
|
requirements:
|
65
65
|
- - ! '>='
|
@@ -67,10 +67,10 @@ dependencies:
|
|
67
67
|
version: '0'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
|
-
version_requirements: *
|
70
|
+
version_requirements: *70300104634980
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: rspec
|
73
|
-
requirement: &
|
73
|
+
requirement: &70300104633980 !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
75
75
|
requirements:
|
76
76
|
- - ! '>='
|
@@ -78,10 +78,10 @@ dependencies:
|
|
78
78
|
version: '0'
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
|
-
version_requirements: *
|
81
|
+
version_requirements: *70300104633980
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: rr
|
84
|
-
requirement: &
|
84
|
+
requirement: &70300104633280 !ruby/object:Gem::Requirement
|
85
85
|
none: false
|
86
86
|
requirements:
|
87
87
|
- - ! '>='
|
@@ -89,10 +89,10 @@ dependencies:
|
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
|
-
version_requirements: *
|
92
|
+
version_requirements: *70300104633280
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
name: webmock
|
95
|
-
requirement: &
|
95
|
+
requirement: &70300104632720 !ruby/object:Gem::Requirement
|
96
96
|
none: false
|
97
97
|
requirements:
|
98
98
|
- - ! '>='
|
@@ -100,7 +100,7 @@ dependencies:
|
|
100
100
|
version: '0'
|
101
101
|
type: :development
|
102
102
|
prerelease: false
|
103
|
-
version_requirements: *
|
103
|
+
version_requirements: *70300104632720
|
104
104
|
description: A wrapper for the Globo.com's authentication/authorization API
|
105
105
|
email:
|
106
106
|
- bruno@azisaka.com.br
|
@@ -112,15 +112,13 @@ files:
|
|
112
112
|
- .rspec
|
113
113
|
- Gemfile
|
114
114
|
- Rakefile
|
115
|
-
-
|
115
|
+
- benchmark/curl_x_restclient.rb
|
116
116
|
- cadun.gemspec
|
117
117
|
- lib/cadun.rb
|
118
118
|
- lib/cadun/config.rb
|
119
119
|
- lib/cadun/gateway.rb
|
120
120
|
- lib/cadun/user.rb
|
121
121
|
- lib/cadun/version.rb
|
122
|
-
- script/console
|
123
|
-
- script/loader.rb
|
124
122
|
- spec/cadun/config_spec.rb
|
125
123
|
- spec/cadun/gateway_spec.rb
|
126
124
|
- spec/cadun/user_spec.rb
|
@@ -153,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
151
|
version: '0'
|
154
152
|
requirements: []
|
155
153
|
rubyforge_project:
|
156
|
-
rubygems_version: 1.8.
|
154
|
+
rubygems_version: 1.8.10
|
157
155
|
signing_key:
|
158
156
|
specification_version: 3
|
159
157
|
summary: A wrapper for the Globo.com's authentication/authorization API
|
data/script/console
DELETED
data/script/loader.rb
DELETED