cadun 0.6.3 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -2
- data/.rvmrc +6 -0
- data/Gemfile.lock +58 -0
- data/{benchmark → bench}/curl_x_restclient.rb +1 -1
- data/cadun.gemspec +4 -4
- data/lib/cadun.rb +2 -1
- data/lib/cadun/error.rb +9 -0
- data/lib/cadun/gateway.rb +55 -29
- data/lib/cadun/user.rb +33 -26
- data/lib/cadun/version.rb +1 -1
- data/script/console +3 -0
- data/script/loader.rb +3 -0
- data/spec/cadun/config_spec.rb +23 -11
- data/spec/cadun/gateway_spec.rb +68 -33
- data/spec/cadun/user_spec.rb +77 -59
- data/spec/spec_helper.rb +11 -9
- data/spec/support/fixtures/another_config.yml +3 -1
- data/spec/support/fixtures/config.yml +4 -2
- metadata +63 -38
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 399f65d6c228bfd42251428d958eef3b70d4e9ed
|
4
|
+
data.tar.gz: 8fe58a64bbc8c0122e9c007bc6b46fd1dfbe3a1f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b841555e589ba6e287a992667cda4be58b764f28fabe1508bb4d8046a210e74753c0f06a2fa09706100ba69a2e0af59261dd4b2f22ad84dfcd323b59ed961a77
|
7
|
+
data.tar.gz: 6eab8517c5641d4f4ff0bf431201c886b1dd284b2caf4e454d95df07133a357bc75023dd687b052606d9fb9c90aab73f779eca78d21fefb32927ac732d1474a4
|
data/.gitignore
CHANGED
data/.rvmrc
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cadun (0.8.3)
|
5
|
+
activesupport (>= 3.0.0)
|
6
|
+
builder (>= 2.1.2)
|
7
|
+
i18n
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (3.2.9)
|
13
|
+
i18n (~> 0.6)
|
14
|
+
multi_json (~> 1.0)
|
15
|
+
addressable (2.3.2)
|
16
|
+
archive-tar-minitar (0.5.2)
|
17
|
+
builder (3.1.4)
|
18
|
+
columnize (0.3.6)
|
19
|
+
crack (0.3.1)
|
20
|
+
diff-lcs (1.1.3)
|
21
|
+
i18n (0.6.1)
|
22
|
+
linecache19 (0.5.12)
|
23
|
+
ruby_core_source (>= 0.1.4)
|
24
|
+
multi_json (1.4.0)
|
25
|
+
rake (10.0.2)
|
26
|
+
rr (1.0.4)
|
27
|
+
rspec (2.12.0)
|
28
|
+
rspec-core (~> 2.12.0)
|
29
|
+
rspec-expectations (~> 2.12.0)
|
30
|
+
rspec-mocks (~> 2.12.0)
|
31
|
+
rspec-core (2.12.1)
|
32
|
+
rspec-expectations (2.12.0)
|
33
|
+
diff-lcs (~> 1.1.3)
|
34
|
+
rspec-mocks (2.12.0)
|
35
|
+
ruby-debug-base19 (0.11.25)
|
36
|
+
columnize (>= 0.3.1)
|
37
|
+
linecache19 (>= 0.5.11)
|
38
|
+
ruby_core_source (>= 0.1.4)
|
39
|
+
ruby-debug19 (0.11.6)
|
40
|
+
columnize (>= 0.3.1)
|
41
|
+
linecache19 (>= 0.5.11)
|
42
|
+
ruby-debug-base19 (>= 0.11.19)
|
43
|
+
ruby_core_source (0.1.5)
|
44
|
+
archive-tar-minitar (>= 0.5.2)
|
45
|
+
webmock (1.9.0)
|
46
|
+
addressable (>= 2.2.7)
|
47
|
+
crack (>= 0.1.7)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
cadun!
|
54
|
+
rake
|
55
|
+
rr
|
56
|
+
rspec
|
57
|
+
ruby-debug19
|
58
|
+
webmock
|
@@ -4,7 +4,7 @@ require 'curb'
|
|
4
4
|
require 'restclient'
|
5
5
|
|
6
6
|
n = 100
|
7
|
-
url = "http://
|
7
|
+
url = "http://autenticacao.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/email/fab1@spam.la"
|
8
8
|
|
9
9
|
Benchmark.bm do |x|
|
10
10
|
x.report("restclient") { n.times { RestClient.get(url) } }
|
data/cadun.gemspec
CHANGED
@@ -5,8 +5,8 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.name = 'cadun'
|
6
6
|
s.version = Cadun::VERSION::STRING
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
|
-
s.authors = %w(
|
9
|
-
s.email = %w(
|
8
|
+
s.authors = %w(Cadun)
|
9
|
+
s.email = %w(cadun@corp.globo.com)
|
10
10
|
s.homepage = ''
|
11
11
|
s.summary = "A wrapper for the Globo.com's authentication/authorization API"
|
12
12
|
s.description = "A wrapper for the Globo.com's authentication/authorization API"
|
@@ -14,11 +14,11 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.files = `git ls-files`.split("\n")
|
15
15
|
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
16
16
|
s.require_paths = %w(lib)
|
17
|
-
|
17
|
+
|
18
18
|
s.add_dependency 'i18n'
|
19
19
|
s.add_dependency 'activesupport', '>= 3.0.0'
|
20
20
|
s.add_dependency 'builder', '>= 2.1.2'
|
21
|
-
s.
|
21
|
+
s.add_development_dependency "ruby-debug19"
|
22
22
|
s.add_development_dependency 'rake'
|
23
23
|
s.add_development_dependency 'rspec'
|
24
24
|
s.add_development_dependency 'rr'
|
data/lib/cadun.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'date'
|
2
2
|
require 'yaml'
|
3
|
-
require '
|
3
|
+
require 'net/http'
|
4
4
|
require 'active_support/core_ext/hash'
|
5
5
|
require 'active_support/core_ext/object'
|
6
6
|
require "#{File.dirname(__FILE__)}/cadun/gateway"
|
7
7
|
require "#{File.dirname(__FILE__)}/cadun/user"
|
8
8
|
require "#{File.dirname(__FILE__)}/cadun/config"
|
9
|
+
require "#{File.dirname(__FILE__)}/cadun/error"
|
data/lib/cadun/error.rb
ADDED
data/lib/cadun/gateway.rb
CHANGED
@@ -1,54 +1,80 @@
|
|
1
1
|
module Cadun
|
2
2
|
class Gateway
|
3
3
|
attr_reader :opts
|
4
|
-
|
4
|
+
|
5
5
|
def self.provision(user_id, service_id)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
uri = URI("#{Config.restclient_url}/service/provisionamento")
|
7
|
+
|
8
|
+
req = Net::HTTP::Put.new(uri.request_uri)
|
9
|
+
req.content_type = 'application/json'
|
10
|
+
|
11
|
+
res = Gateway.http_request uri, req, %|{"usuarioId":"#{user_id}","servicoId":"#{service_id}"}|
|
12
|
+
res.code == "200"
|
11
13
|
end
|
12
|
-
|
14
|
+
|
13
15
|
def initialize(opts = {})
|
14
16
|
@opts = opts
|
15
17
|
end
|
16
|
-
|
18
|
+
|
17
19
|
def content
|
18
|
-
@content
|
20
|
+
unless @content
|
21
|
+
content = content_resource
|
22
|
+
@content = (Hash.from_xml(content)["pessoa"] if content.present?) || {}
|
23
|
+
end
|
24
|
+
@content
|
19
25
|
end
|
20
|
-
|
26
|
+
|
21
27
|
def content_resource
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
if opts[:email]; "email/#{opts[:email]}"
|
27
|
-
elsif opts[:cadun_id]; opts[:cadun_id]
|
28
|
+
subject = if opts[:email]
|
29
|
+
"email/#{opts[:email]}"
|
30
|
+
elsif opts[:cadun_id]
|
31
|
+
opts[:cadun_id]
|
28
32
|
else
|
29
|
-
raise
|
33
|
+
raise Cadun::Error::NotAuthorized.new(authorization["status"]) unless authorization["status"] == "AUTORIZADO"
|
30
34
|
authorization["usuarioID"]
|
31
35
|
end
|
36
|
+
|
37
|
+
uri = URI("#{Config.auth_url}/cadunii/ws/resources/pessoa/#{subject}")
|
38
|
+
|
39
|
+
req = Net::HTTP::Get.new(uri.request_uri)
|
40
|
+
|
41
|
+
res = Gateway.http_request uri, req
|
42
|
+
res.body
|
43
|
+
|
32
44
|
end
|
33
|
-
|
34
|
-
def authorized?
|
35
|
-
authorization["status"] == "AUTORIZADO"
|
36
|
-
end
|
37
|
-
|
45
|
+
|
38
46
|
def authorization
|
39
47
|
@authorization ||= Hash.from_xml(authorization_resource)["usuarioAutorizado"]
|
40
48
|
end
|
41
|
-
|
49
|
+
|
42
50
|
def authorization_resource
|
43
51
|
%w(glb_id ip service_id).each { |i| raise ArgumentError.new("#{i} is missing") unless opts[i.to_sym] }
|
44
|
-
|
45
52
|
authorization_data = { "glbId" => opts[:glb_id], "ip" => opts[:ip], "servicoID" => opts[:service_id] }.to_xml(:root => "usuarioAutorizado", :indent => 0)
|
46
|
-
|
47
|
-
|
48
|
-
|
53
|
+
|
54
|
+
uri = URI("#{Config.auth_url}/ws/rest/autorizacao")
|
55
|
+
|
56
|
+
req = Net::HTTP::Put.new(uri.request_uri)
|
57
|
+
req.content_type = 'text/xml'
|
58
|
+
|
59
|
+
res = Gateway.http_request uri, req, authorization_data
|
60
|
+
res.body
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def self.http_request(uri, req, body=nil)
|
67
|
+
begin
|
68
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
69
|
+
|
70
|
+
http.open_timeout = Config.open_timeout if Config.respond_to? :open_timeout
|
71
|
+
http.read_timeout = Config.read_timeout if Config.respond_to? :read_timeout
|
72
|
+
|
73
|
+
http.request req, body
|
74
|
+
rescue Timeout::Error
|
75
|
+
raise Cadun::Error::Timeout.new("timeout to #{req.class.name} resource #{uri.host + uri.path}")
|
49
76
|
end
|
50
77
|
|
51
|
-
request.body_str
|
52
78
|
end
|
53
79
|
end
|
54
|
-
end
|
80
|
+
end
|
data/lib/cadun/user.rb
CHANGED
@@ -1,71 +1,78 @@
|
|
1
1
|
module Cadun
|
2
|
-
class User
|
3
|
-
{ "id" => "cadun_id",
|
4
|
-
"nome" => "name",
|
5
|
-
"
|
6
|
-
"tipoUsuario" => "user_type",
|
2
|
+
class User
|
3
|
+
{ "id" => "cadun_id",
|
4
|
+
"nome" => "name",
|
5
|
+
"tipoUsuario" => "user_type",
|
7
6
|
"sexo" => "gender",
|
8
|
-
"bairro" => "neighborhood",
|
7
|
+
"bairro" => "neighborhood",
|
9
8
|
"cep" => "zipcode",
|
10
9
|
"complemento" => "complement" }.each { |path, method| define_method(method) { gateway.content[path] } }
|
11
|
-
|
10
|
+
|
12
11
|
alias :id :cadun_id
|
13
|
-
|
12
|
+
|
14
13
|
def self.find_by_email(email)
|
15
|
-
email = "#{email}@
|
14
|
+
email = "#{email}@globo.com" unless email =~ /^.*@.*$/
|
16
15
|
new(:email => email)
|
17
16
|
end
|
18
|
-
|
17
|
+
|
19
18
|
def self.find_by_id(cadun_id)
|
20
19
|
new(:cadun_id => cadun_id)
|
21
20
|
end
|
22
|
-
|
21
|
+
|
23
22
|
def initialize(options = {})
|
24
23
|
@options = options
|
25
24
|
end
|
26
25
|
|
26
|
+
def email
|
27
|
+
emailPrincipal || emailAlternativo
|
28
|
+
end
|
29
|
+
|
27
30
|
def address
|
28
|
-
"#{endereco}, #{numero}"
|
31
|
+
"#{endereco}, #{numero}" if endereco and numero
|
29
32
|
end
|
30
|
-
|
33
|
+
|
31
34
|
def birthday
|
32
|
-
Date.parse(dataNascimento)
|
35
|
+
Date.parse(dataNascimento) if dataNascimento
|
33
36
|
end
|
34
|
-
|
37
|
+
|
35
38
|
def phone
|
36
|
-
"#{telefoneResidencialDdd} #{telefoneResidencial}"
|
39
|
+
"#{telefoneResidencialDdd} #{telefoneResidencial}" if telefoneResidencial and telefoneResidencialDdd
|
37
40
|
end
|
38
|
-
|
41
|
+
|
39
42
|
def mobile
|
40
|
-
"#{telefoneCelularDdd} #{telefoneCelular}"
|
43
|
+
"#{telefoneCelularDdd} #{telefoneCelular}" if telefoneCelularDdd and telefoneCelular
|
41
44
|
end
|
42
|
-
|
45
|
+
|
43
46
|
def country
|
44
47
|
pais['nome'] if pais.present?
|
45
48
|
end
|
46
|
-
|
49
|
+
|
47
50
|
def city
|
48
51
|
cidade['nome'] if cidade.present?
|
49
52
|
end
|
50
|
-
|
53
|
+
|
51
54
|
def state
|
52
55
|
estado['sigla'] if estado.present?
|
53
56
|
end
|
54
|
-
|
57
|
+
|
55
58
|
def to_hash
|
56
59
|
%w(address birthday cadun_id city complement country cpf email gender login mobile name neighborhood phone state status user_type zipcode).inject(Hash.new(0)) { |hash, method| hash[method.to_sym] = (send(method) rescue nil); hash }
|
57
60
|
end
|
58
|
-
|
61
|
+
|
59
62
|
def provision_to_service(service_id)
|
60
63
|
Gateway.provision(id, service_id)
|
61
64
|
end
|
62
|
-
|
65
|
+
|
63
66
|
def method_missing(method)
|
64
67
|
gateway.content[method.to_s]
|
65
68
|
end
|
66
|
-
|
69
|
+
|
70
|
+
def assinante?
|
71
|
+
Hash.from_xml(gateway.authorization_resource)['usuarioAutorizado']['tipoUsuario'] == 'ASSINANTE'
|
72
|
+
end
|
73
|
+
|
67
74
|
def gateway
|
68
75
|
@gateway ||= Gateway.new(@options)
|
69
76
|
end
|
70
77
|
end
|
71
|
-
end
|
78
|
+
end
|
data/lib/cadun/version.rb
CHANGED
data/script/console
ADDED
data/script/loader.rb
ADDED
data/spec/cadun/config_spec.rb
CHANGED
@@ -1,18 +1,30 @@
|
|
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
|
+
|
4
11
|
before { load_config }
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
12
|
+
|
13
|
+
verify_method "login_url" , "https://login.qa01.globoi.com/login"
|
14
|
+
verify_method "logout_url", "https://login.qa01.globoi.com/Servlet/do/logout"
|
15
|
+
verify_method "auth_url" , "http://autenticacao.qa01.globoi.com:8280"
|
16
|
+
|
17
|
+
verify_method "open_timeout", 0.3
|
18
|
+
verify_method "read_timeout", 0.4
|
19
|
+
|
11
20
|
context "when the file changes" do
|
12
21
|
before { load_another_config }
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
22
|
+
|
23
|
+
verify_method "login_url", "https://login.globo.com/login"
|
24
|
+
verify_method "logout_url", "https://login.globo.com/Servlet/do/logout"
|
25
|
+
verify_method "auth_url", "http://autenticacao.globo.com:8080"
|
26
|
+
|
27
|
+
verify_method "open_timeout", 0.5
|
28
|
+
verify_method "read_timeout", 0.6
|
17
29
|
end
|
18
|
-
end
|
30
|
+
end
|
data/spec/cadun/gateway_spec.rb
CHANGED
@@ -1,68 +1,103 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Cadun::Gateway do
|
4
|
+
let(:autorizacao_service_url) { "http://autenticacao.qa01.globoi.com:8280/ws/rest/autorizacao" }
|
5
|
+
|
4
6
|
before { load_config }
|
5
|
-
|
6
|
-
describe "#provision" do
|
7
|
-
|
8
|
-
|
7
|
+
|
8
|
+
describe "#provision" do
|
9
|
+
let(:service_url) { "http://cadun-rest.qa01.globoi.com/service/provisionamento" }
|
9
10
|
context "when the service is provisioned to the user" do
|
10
|
-
before { stub_request(:put,
|
11
|
-
|
11
|
+
before { stub_request(:put, service_url).to_return(:status => [200]) }
|
12
|
+
|
13
|
+
subject { Cadun::Gateway.provision(123456, 2515) }
|
14
|
+
specify { should be_true }
|
12
15
|
end
|
13
|
-
|
14
|
-
context "when the service
|
15
|
-
before { stub_request(:put,
|
16
|
-
|
16
|
+
|
17
|
+
context "when the service is provisioned to the user" do
|
18
|
+
before { stub_request(:put, service_url).to_return(:status => [304]) }
|
19
|
+
|
20
|
+
subject { Cadun::Gateway.provision(123456, 2515) }
|
21
|
+
it { subject.should be_false }
|
17
22
|
end
|
18
|
-
|
23
|
+
|
19
24
|
context "when the service is not found" do
|
20
|
-
before { stub_request(:put,
|
21
|
-
|
25
|
+
before { stub_request(:put, service_url).to_return(:status => [404]) }
|
26
|
+
|
27
|
+
subject { Cadun::Gateway.provision(123456, 2515) }
|
28
|
+
it { subject.should be_false }
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when the service returns HTTP 50x error" do
|
32
|
+
before { stub_request(:put, service_url).to_return(:status => [503]) }
|
33
|
+
|
34
|
+
subject { Cadun::Gateway.provision(123456, 2515) }
|
35
|
+
it { subject.should be_false }
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when the request timed out" do
|
39
|
+
before { stub_request(:put, service_url).to_timeout }
|
40
|
+
|
41
|
+
subject { Cadun::Gateway.provision(123456, 2515) }
|
42
|
+
|
43
|
+
it "should raise an exception" do
|
44
|
+
-> { subject }.should raise_error(TimeoutError)
|
45
|
+
end
|
22
46
|
end
|
23
47
|
end
|
24
|
-
|
48
|
+
|
25
49
|
describe "#content" do
|
50
|
+
let(:service_url) { "http://autenticacao.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/1" }
|
26
51
|
let(:gateway) { Cadun::Gateway.new(:glb_id => "GLB_ID", :ip => "127.0.0.1", :service_id => 2626) }
|
27
|
-
|
28
|
-
|
52
|
+
|
29
53
|
context "when status not AUTORIZADO" do
|
30
|
-
before
|
31
|
-
|
54
|
+
before do
|
55
|
+
stub_request(:put, autorizacao_service_url).to_return(:body => "<?xml version='1.0' encoding='utf-8'?><usuarioAutorizado><status>NAO_AUTORIZADO</status><usuarioID>1</usuarioID></usuarioAutorizado>")
|
56
|
+
end
|
57
|
+
|
58
|
+
it { proc { gateway.content }.should raise_error(Cadun::Error::NotAuthorized) }
|
32
59
|
end
|
33
60
|
|
34
61
|
context "when status AUTORIZADO" do
|
35
62
|
before do
|
36
|
-
stub_request(:put,
|
37
|
-
stub_request(:get,
|
63
|
+
stub_request(:put, autorizacao_service_url).to_return(:body => "<?xml version='1.0' encoding='utf-8'?><usuarioAutorizado><status>AUTORIZADO</status><usuarioID>1</usuarioID></usuarioAutorizado>")
|
64
|
+
stub_request(:get, service_url).to_return(:body => "<?xml version='1.0' encoding='utf-8'?><pessoa><nome>Barack Obama</nome></pessoa>")
|
38
65
|
end
|
39
66
|
|
40
|
-
it {
|
67
|
+
it { proc { gateway.content }.should_not raise_error(Cadun::Error::NotAuthorized) }
|
68
|
+
|
69
|
+
it "should parse the resource" do
|
70
|
+
gateway.content['nome'].should == 'Barack Obama'
|
71
|
+
end
|
41
72
|
end
|
42
73
|
end
|
43
|
-
|
74
|
+
|
44
75
|
describe "#authorization" do
|
45
|
-
subject { gateway.authorization }
|
46
|
-
|
47
76
|
context "when all information is given" do
|
48
77
|
let(:gateway) { Cadun::Gateway.new(:glb_id => "GLB_ID", :ip => "127.0.0.1", :service_id => 2626) }
|
49
|
-
|
50
|
-
|
78
|
+
|
79
|
+
before do
|
80
|
+
stub_request(:put, autorizacao_service_url).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>")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should parse the authorization request" do
|
84
|
+
gateway.authorization['usuarioID'].should == '1'
|
85
|
+
end
|
51
86
|
end
|
52
|
-
|
87
|
+
|
53
88
|
context "when glb_id is not given" do
|
54
89
|
let(:gateway) { Cadun::Gateway.new }
|
55
|
-
it {
|
90
|
+
it { proc { gateway.authorization }.should raise_error(ArgumentError, "glb_id is missing") }
|
56
91
|
end
|
57
|
-
|
92
|
+
|
58
93
|
context "when ip is not given" do
|
59
94
|
let(:gateway) { Cadun::Gateway.new(:glb_id => "1") }
|
60
|
-
it {
|
95
|
+
it { proc { gateway.authorization }.should raise_error(ArgumentError, "ip is missing") }
|
61
96
|
end
|
62
|
-
|
97
|
+
|
63
98
|
context "when service_id is not given" do
|
64
99
|
let(:gateway) { Cadun::Gateway.new(:glb_id => "1", :ip => "1") }
|
65
|
-
it {
|
100
|
+
it { proc { gateway.authorization }.should raise_error(ArgumentError, "service_id is missing") }
|
66
101
|
end
|
67
102
|
end
|
68
|
-
end
|
103
|
+
end
|
data/spec/cadun/user_spec.rb
CHANGED
@@ -2,105 +2,123 @@
|
|
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
|
+
|
5
12
|
before do
|
6
13
|
load_config
|
7
14
|
stub_requests
|
8
15
|
end
|
9
|
-
|
16
|
+
|
10
17
|
context "when the user id is not given" do
|
11
18
|
subject { Cadun::User.new :ip => "127.0.0.1", :service_id => 2626, :glb_id => "GLB_ID" }
|
12
|
-
|
19
|
+
|
13
20
|
it "should load the gateway only when it's needed" do
|
14
|
-
mock(Cadun::Gateway).new(
|
21
|
+
mock(Cadun::Gateway).new(:ip => "127.0.0.1", :service_id => 2626, :glb_id => "GLB_ID") do
|
15
22
|
mock(Cadun::Gateway).content { Hash.new }
|
16
23
|
end
|
17
|
-
|
24
|
+
|
18
25
|
subject.login
|
19
26
|
end
|
20
|
-
|
27
|
+
|
21
28
|
it "should not load the gateway when the user is initialized" do
|
22
29
|
dont_allow(Cadun::Gateway).new
|
23
30
|
subject
|
24
31
|
end
|
25
32
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
33
|
+
verify_method "id", "21737810"
|
34
|
+
verify_method "name", "Fabricio Rodrigo Lopes"
|
35
|
+
verify_method "birthday", Date.new(1983, 02, 22)
|
36
|
+
verify_method "phone", "21 22881060"
|
37
|
+
verify_method "mobile", "21 99999999"
|
38
|
+
verify_method "email", "fab1@spam.la"
|
39
|
+
verify_method "gender", "MASCULINO"
|
40
|
+
verify_method "city", "Rio de Janeiro"
|
41
|
+
verify_method "state", "RJ"
|
42
|
+
verify_method "status", "ATIVO"
|
43
|
+
verify_method "address", "Rua Uruguai, 59"
|
44
|
+
verify_method "neighborhood", "Andaraí"
|
45
|
+
verify_method "cpf", "09532034765"
|
46
|
+
verify_method "login", "fabricio_fab1"
|
47
|
+
verify_method "country", "Brasil"
|
48
|
+
verify_method "user_type", "NAO_ASSINANTE"
|
49
|
+
verify_method "cadun_id", "21737810"
|
50
|
+
verify_method "complement", "807"
|
44
51
|
end
|
45
|
-
|
52
|
+
|
46
53
|
describe "#to_hash" do
|
47
54
|
context "when the user has all data" do
|
48
55
|
subject { Cadun::User.new(:cadun_id => "10001000").to_hash }
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
56
|
+
|
57
|
+
specify { should include(:cadun_id => "10001000") }
|
58
|
+
specify { should include(:name => "Guilherme Chico") }
|
59
|
+
specify { should include(:email => "fab1@spam.la") }
|
60
|
+
specify { should include(:user_type => "NAO_ASSINANTE") }
|
61
|
+
specify { should include(:gender => "MASCULINO") }
|
62
|
+
specify { should include(:neighborhood => "Andaraí") }
|
63
|
+
specify { should include(:city => "Rio de Janeiro") }
|
64
|
+
specify { should include(:state => "RJ") }
|
65
|
+
specify { should include(:country => "Brasil") }
|
66
|
+
specify { should include(:address => "Rua Uruguai, 59") }
|
67
|
+
specify { should include(:birthday => Date.new(1983, 02, 22)) }
|
68
|
+
specify { should include(:phone => "21 22881060") }
|
69
|
+
specify { should include(:mobile => "21 99999999") }
|
70
|
+
specify { should include(:login => "fabricio_fab1") }
|
71
|
+
specify { should include(:cpf => "09532034765") }
|
72
|
+
specify { should include(:zipcode => "20510060") }
|
73
|
+
specify { should include(:status => "ATIVO") }
|
74
|
+
specify { should include(:complement => "807") }
|
68
75
|
end
|
69
|
-
|
76
|
+
|
70
77
|
context "when the user has minimal data" do
|
71
78
|
subject { Cadun::User.find_by_email("fulano_adm_campanha@globomail.com") }
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
its(:country) { should be_nil }
|
79
|
+
specify { subject.id.should == "23370159" }
|
80
|
+
specify { subject.city.should == nil }
|
81
|
+
specify { subject.state.should == nil }
|
82
|
+
specify { subject.country.should == nil }
|
77
83
|
end
|
78
84
|
end
|
79
|
-
|
85
|
+
|
80
86
|
describe ".find_by_email" do
|
81
87
|
context "given an email without domain" do
|
82
88
|
subject { Cadun::User.find_by_email("silvano") }
|
83
|
-
|
89
|
+
verify_method "id", "24510533"
|
84
90
|
end
|
85
|
-
|
91
|
+
|
86
92
|
context "given an email with domain" do
|
87
93
|
subject { Cadun::User.find_by_email("silvano@corp.globo.com") }
|
88
|
-
|
94
|
+
verify_method "id", "24510533"
|
89
95
|
end
|
90
96
|
end
|
91
|
-
|
97
|
+
|
92
98
|
describe ".find_by_id" do
|
93
|
-
|
94
|
-
|
99
|
+
context "when the user exists" do
|
100
|
+
subject { Cadun::User.find_by_id("10001000") }
|
101
|
+
verify_method "id", "10001000"
|
102
|
+
end
|
103
|
+
|
104
|
+
context "when the user doesn't exists" do
|
105
|
+
subject { Cadun::User.find_by_id("999999") }
|
106
|
+
|
107
|
+
%w{ id name birthday phone mobile email gender city state status
|
108
|
+
address neighborhood cpf login country user_type cadun_id
|
109
|
+
complement }.each do |method|
|
110
|
+
verify_method method, nil
|
111
|
+
end
|
112
|
+
end
|
95
113
|
end
|
96
|
-
|
114
|
+
|
97
115
|
describe "#provision_to_service" do
|
98
116
|
it "should call gateway's provision" do
|
99
117
|
mock(Cadun::Gateway).provision(1, 6969)
|
100
|
-
|
118
|
+
|
101
119
|
user = Cadun::User.new
|
102
120
|
mock(user).id { 1 }
|
103
121
|
user.provision_to_service(6969)
|
104
122
|
end
|
105
123
|
end
|
106
|
-
end
|
124
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,25 +1,27 @@
|
|
1
1
|
require "#{File.dirname(__FILE__)}/../lib/cadun"
|
2
2
|
require 'webmock/rspec'
|
3
|
+
require 'ruby-debug'
|
3
4
|
|
4
5
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
5
6
|
|
6
|
-
RSpec.configure do |config|
|
7
|
+
RSpec.configure do |config|
|
7
8
|
config.mock_with :rr
|
8
9
|
config.filter_run :focus => true
|
9
10
|
config.run_all_when_everything_filtered = true
|
10
|
-
|
11
|
+
|
11
12
|
config.before(:suite) do
|
12
13
|
WebMock.disable_net_connect!(:allow_localhost => true)
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
17
|
def stub_requests
|
17
|
-
stub_request(:put, "http://
|
18
|
-
stub_request(:get, "http://
|
19
|
-
stub_request(:get, "http://
|
20
|
-
stub_request(:get, "http://
|
21
|
-
stub_request(:get, "http://
|
22
|
-
stub_request(:get, "http://
|
18
|
+
stub_request(:put, "http://autenticacao.qa01.globoi.com:8280/ws/rest/autorizacao").to_return(:body => File.new("#{File.dirname(__FILE__)}/support/fixtures/autorizacao.xml"))
|
19
|
+
stub_request(:get, "http://autenticacao.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/21737810").to_return(:body => File.new("#{File.dirname(__FILE__)}/support/fixtures/pessoa.xml"))
|
20
|
+
stub_request(:get, "http://autenticacao.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/999999").to_return(:status => 302)
|
21
|
+
stub_request(:get, "http://autenticacao.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/10001000").to_return(:body => File.new("#{File.dirname(__FILE__)}/support/fixtures/pessoa_2.xml"))
|
22
|
+
stub_request(:get, "http://autenticacao.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/email/silvano@globo.com").to_return(:body => File.new("#{File.dirname(__FILE__)}/support/fixtures/email.xml"))
|
23
|
+
stub_request(:get, "http://autenticacao.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/email/silvano@corp.globo.com").to_return(:body => File.new("#{File.dirname(__FILE__)}/support/fixtures/email.xml"))
|
24
|
+
stub_request(:get, "http://autenticacao.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/email/fulano_adm_campanha@globomail.com").to_return(:body => File.new("#{File.dirname(__FILE__)}/support/fixtures/email2.xml"))
|
23
25
|
stub_request(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento").to_return(:body => File.new("#{File.dirname(__FILE__)}/support/fixtures/provisionamento.json"))
|
24
26
|
end
|
25
27
|
|
@@ -29,4 +31,4 @@ end
|
|
29
31
|
|
30
32
|
def load_another_config
|
31
33
|
Cadun::Config.load_file "#{File.dirname(__FILE__)}/support/fixtures/another_config.yml"
|
32
|
-
end
|
34
|
+
end
|
@@ -2,4 +2,6 @@ cadun:
|
|
2
2
|
logout_url: https://login.globo.com/Servlet/do/logout
|
3
3
|
login_url: https://login.globo.com/login
|
4
4
|
auth_url: http://autenticacao.globo.com:8080
|
5
|
-
restclient_url: http://cadun-rest.globoi.com
|
5
|
+
restclient_url: http://cadun-rest.globoi.com
|
6
|
+
open_timeout: 0.5 # in seconds
|
7
|
+
read_timeout: 0.6 # in seconds
|
@@ -1,5 +1,7 @@
|
|
1
1
|
cadun:
|
2
2
|
logout_url: https://login.qa01.globoi.com/Servlet/do/logout
|
3
3
|
login_url: https://login.qa01.globoi.com/login
|
4
|
-
auth_url: http://
|
5
|
-
restclient_url: http://cadun-rest.qa01.globoi.com
|
4
|
+
auth_url: http://autenticacao.qa01.globoi.com:8280
|
5
|
+
restclient_url: http://cadun-rest.qa01.globoi.com
|
6
|
+
open_timeout: 0.3 # in seconds
|
7
|
+
read_timeout: 0.4 # in seconds
|
metadata
CHANGED
@@ -1,124 +1,150 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cadun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.8.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
|
-
-
|
9
|
-
- Azisaka
|
10
|
-
- Maciel
|
7
|
+
- Cadun
|
11
8
|
autorequire:
|
12
9
|
bindir: bin
|
13
10
|
cert_chain: []
|
14
|
-
date:
|
11
|
+
date: 2014-09-25 00:00:00.000000000 Z
|
15
12
|
dependencies:
|
16
13
|
- !ruby/object:Gem::Dependency
|
17
14
|
name: i18n
|
18
|
-
requirement:
|
19
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
20
16
|
requirements:
|
21
17
|
- - ! '>='
|
22
18
|
- !ruby/object:Gem::Version
|
23
19
|
version: '0'
|
24
20
|
type: :runtime
|
25
21
|
prerelease: false
|
26
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
|
-
requirement:
|
30
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
31
30
|
requirements:
|
32
31
|
- - ! '>='
|
33
32
|
- !ruby/object:Gem::Version
|
34
33
|
version: 3.0.0
|
35
34
|
type: :runtime
|
36
35
|
prerelease: false
|
37
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.0
|
38
41
|
- !ruby/object:Gem::Dependency
|
39
42
|
name: builder
|
40
|
-
requirement:
|
41
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
42
44
|
requirements:
|
43
45
|
- - ! '>='
|
44
46
|
- !ruby/object:Gem::Version
|
45
47
|
version: 2.1.2
|
46
48
|
type: :runtime
|
47
49
|
prerelease: false
|
48
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.1.2
|
49
55
|
- !ruby/object:Gem::Dependency
|
50
|
-
name:
|
51
|
-
requirement:
|
52
|
-
none: false
|
56
|
+
name: ruby-debug19
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
53
58
|
requirements:
|
54
59
|
- - ! '>='
|
55
60
|
- !ruby/object:Gem::Version
|
56
61
|
version: '0'
|
57
|
-
type: :
|
62
|
+
type: :development
|
58
63
|
prerelease: false
|
59
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
60
69
|
- !ruby/object:Gem::Dependency
|
61
70
|
name: rake
|
62
|
-
requirement:
|
63
|
-
none: false
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
64
72
|
requirements:
|
65
73
|
- - ! '>='
|
66
74
|
- !ruby/object:Gem::Version
|
67
75
|
version: '0'
|
68
76
|
type: :development
|
69
77
|
prerelease: false
|
70
|
-
version_requirements:
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
71
83
|
- !ruby/object:Gem::Dependency
|
72
84
|
name: rspec
|
73
|
-
requirement:
|
74
|
-
none: false
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
75
86
|
requirements:
|
76
87
|
- - ! '>='
|
77
88
|
- !ruby/object:Gem::Version
|
78
89
|
version: '0'
|
79
90
|
type: :development
|
80
91
|
prerelease: false
|
81
|
-
version_requirements:
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
82
97
|
- !ruby/object:Gem::Dependency
|
83
98
|
name: rr
|
84
|
-
requirement:
|
85
|
-
none: false
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - ! '>='
|
88
102
|
- !ruby/object:Gem::Version
|
89
103
|
version: '0'
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
|
-
version_requirements:
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
93
111
|
- !ruby/object:Gem::Dependency
|
94
112
|
name: webmock
|
95
|
-
requirement:
|
96
|
-
none: false
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
97
114
|
requirements:
|
98
115
|
- - ! '>='
|
99
116
|
- !ruby/object:Gem::Version
|
100
117
|
version: '0'
|
101
118
|
type: :development
|
102
119
|
prerelease: false
|
103
|
-
version_requirements:
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
104
125
|
description: A wrapper for the Globo.com's authentication/authorization API
|
105
126
|
email:
|
106
|
-
-
|
127
|
+
- cadun@corp.globo.com
|
107
128
|
executables: []
|
108
129
|
extensions: []
|
109
130
|
extra_rdoc_files: []
|
110
131
|
files:
|
111
132
|
- .gitignore
|
112
133
|
- .rspec
|
134
|
+
- .rvmrc
|
113
135
|
- Gemfile
|
136
|
+
- Gemfile.lock
|
114
137
|
- Rakefile
|
115
|
-
-
|
138
|
+
- bench/curl_x_restclient.rb
|
116
139
|
- cadun.gemspec
|
117
140
|
- lib/cadun.rb
|
118
141
|
- lib/cadun/config.rb
|
142
|
+
- lib/cadun/error.rb
|
119
143
|
- lib/cadun/gateway.rb
|
120
144
|
- lib/cadun/user.rb
|
121
145
|
- lib/cadun/version.rb
|
146
|
+
- script/console
|
147
|
+
- script/loader.rb
|
122
148
|
- spec/cadun/config_spec.rb
|
123
149
|
- spec/cadun/gateway_spec.rb
|
124
150
|
- spec/cadun/user_spec.rb
|
@@ -133,26 +159,25 @@ files:
|
|
133
159
|
- spec/support/fixtures/provisionamento.json
|
134
160
|
homepage: ''
|
135
161
|
licenses: []
|
162
|
+
metadata: {}
|
136
163
|
post_install_message:
|
137
164
|
rdoc_options: []
|
138
165
|
require_paths:
|
139
166
|
- lib
|
140
167
|
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
-
none: false
|
142
168
|
requirements:
|
143
169
|
- - ! '>='
|
144
170
|
- !ruby/object:Gem::Version
|
145
171
|
version: '0'
|
146
172
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
-
none: false
|
148
173
|
requirements:
|
149
174
|
- - ! '>='
|
150
175
|
- !ruby/object:Gem::Version
|
151
176
|
version: '0'
|
152
177
|
requirements: []
|
153
178
|
rubyforge_project:
|
154
|
-
rubygems_version:
|
179
|
+
rubygems_version: 2.4.1
|
155
180
|
signing_key:
|
156
|
-
specification_version:
|
181
|
+
specification_version: 4
|
157
182
|
summary: A wrapper for the Globo.com's authentication/authorization API
|
158
183
|
test_files: []
|