cadun 0.2.0 → 0.2.1
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/.gitignore +1 -0
- data/Gemfile +1 -3
- data/cadun.gemspec +13 -15
- data/lib/cadun/gateway.rb +19 -6
- data/lib/cadun/user.rb +1 -1
- data/lib/cadun/version.rb +1 -1
- data/spec/cadun/config_spec.rb +23 -49
- data/spec/cadun/gateway_spec.rb +17 -30
- data/spec/cadun/user_spec.rb +43 -66
- data/spec/spec_helper.rb +7 -3
- metadata +9 -15
- data/.rvmrc +0 -1
data/Gemfile
CHANGED
data/cadun.gemspec
CHANGED
@@ -1,23 +1,21 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require "cadun/version"
|
2
|
+
require "#{File.dirname(__FILE__)}/lib/cadun/version"
|
4
3
|
|
5
4
|
Gem::Specification.new do |s|
|
6
|
-
s.name
|
7
|
-
s.version
|
8
|
-
s.platform
|
9
|
-
s.authors
|
10
|
-
s.email
|
11
|
-
s.homepage
|
12
|
-
s.summary
|
13
|
-
s.description
|
5
|
+
s.name = 'cadun'
|
6
|
+
s.version = Cadun::VERSION::STRING
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = %w(Bruno Azisaka Maciel)
|
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'
|
14
13
|
|
15
|
-
s.rubyforge_project =
|
14
|
+
s.rubyforge_project = 'cadun'
|
16
15
|
|
17
|
-
s.files
|
18
|
-
s.test_files
|
19
|
-
s.
|
20
|
-
s.require_paths = ["lib"]
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
18
|
+
s.require_paths = %w(lib)
|
21
19
|
|
22
20
|
s.add_dependency 'nokogiri'
|
23
21
|
s.add_development_dependency 'rack'
|
data/lib/cadun/gateway.rb
CHANGED
@@ -5,19 +5,32 @@ module Cadun
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def content
|
8
|
-
@content ||= Nokogiri::XML(
|
8
|
+
@content ||= Nokogiri::XML(content_resource).children
|
9
9
|
end
|
10
10
|
|
11
11
|
def authorization
|
12
|
-
@authorization ||= Nokogiri::XML(
|
12
|
+
@authorization ||= Nokogiri::XML(authorization_resource).children
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
@
|
15
|
+
def connection
|
16
|
+
@connection ||= Net::HTTP.new(Config.auth_url, Config.auth_port)
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
def content_resource
|
21
|
+
get "/cadunii/ws/resources/pessoa/#{authorization.xpath("usuarioID").text}"
|
17
22
|
end
|
18
23
|
|
19
|
-
def
|
20
|
-
|
24
|
+
def get(path)
|
25
|
+
connection.get(path, {'Content-Type' => 'text/xml'}).body
|
26
|
+
end
|
27
|
+
|
28
|
+
def authorization_resource
|
29
|
+
put "/ws/rest/autorizacao", "<usuarioAutorizado><glbId>#{@glb_id}</glbId><ip>#{@ip}</ip><servicoID>#{@service_id}</servicoID></usuarioAutorizado>"
|
30
|
+
end
|
31
|
+
|
32
|
+
def put(path, data)
|
33
|
+
connection.put(path, data, {'Content-Type' => 'text/xml'}).body
|
21
34
|
end
|
22
35
|
end
|
23
36
|
end
|
data/lib/cadun/user.rb
CHANGED
data/lib/cadun/version.rb
CHANGED
data/spec/cadun/config_spec.rb
CHANGED
@@ -1,61 +1,35 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Cadun::Config do
|
4
|
-
|
5
|
-
Cadun::Config.load_file File.join(File.dirname(__FILE__), "..", "support", "fixtures", "config.yml")
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "#login_url" do
|
9
|
-
subject { Cadun::Config.login_url }
|
4
|
+
include Cadun
|
10
5
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
describe "#logout_url" do
|
15
|
-
subject { Cadun::Config.logout_url }
|
6
|
+
def self.verify_method(method, value)
|
7
|
+
describe "##{method}" do
|
8
|
+
subject { Cadun::Config.send(method) }
|
16
9
|
|
17
|
-
|
10
|
+
specify { should == value }
|
11
|
+
end
|
18
12
|
end
|
19
13
|
|
20
|
-
|
21
|
-
subject { Cadun::Config.auth_url }
|
22
|
-
|
23
|
-
specify { should == "isp-authenticator.dev.globoi.com" }
|
24
|
-
end
|
14
|
+
before { load_config }
|
25
15
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
16
|
+
verify_method "login_url", "https://login.dev.globoi.com/login"
|
17
|
+
|
18
|
+
verify_method "logout_url", "https://login.dev.globoi.com/Servlet/do/logout"
|
19
|
+
|
20
|
+
verify_method "auth_url", "isp-authenticator.dev.globoi.com"
|
21
|
+
|
22
|
+
verify_method "auth_port", 8280
|
31
23
|
|
32
24
|
context "when the file changes" do
|
33
|
-
before
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
describe "#logout_url" do
|
44
|
-
subject { Cadun::Config.logout_url }
|
45
|
-
|
46
|
-
specify { should == "https://login.globo.com/Servlet/do/logout" }
|
47
|
-
end
|
48
|
-
|
49
|
-
describe "#auth_url" do
|
50
|
-
subject { Cadun::Config.auth_url }
|
51
|
-
|
52
|
-
specify { should == "autenticacao.globo.com" }
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "#auth_port" do
|
56
|
-
subject { Cadun::Config.auth_port }
|
57
|
-
|
58
|
-
specify { should == 8080 }
|
59
|
-
end
|
25
|
+
before { load_another_config }
|
26
|
+
|
27
|
+
verify_method "login_url", "https://login.globo.com/login"
|
28
|
+
|
29
|
+
verify_method "logout_url", "https://login.globo.com/Servlet/do/logout"
|
30
|
+
|
31
|
+
verify_method "auth_url", "autenticacao.globo.com"
|
32
|
+
|
33
|
+
verify_method "auth_port", 8080
|
60
34
|
end
|
61
35
|
end
|
data/spec/cadun/gateway_spec.rb
CHANGED
@@ -1,49 +1,36 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Cadun::Gateway do
|
4
|
-
|
4
|
+
let(:connection) { mock }
|
5
|
+
let(:response) { mock }
|
6
|
+
|
7
|
+
before do
|
8
|
+
load_config
|
9
|
+
mock(subject).connection { connection }
|
10
|
+
end
|
5
11
|
|
6
12
|
subject { Cadun::Gateway.new("GLB_ID", "127.0.0.1", 2626) }
|
7
13
|
|
8
14
|
describe "#content" do
|
15
|
+
before do
|
16
|
+
mock(subject).authorization { mock(mock).xpath("usuarioID") { mock(mock).text { "1" } } }
|
17
|
+
mock(response).body { "<?xml version='1.0' encoding='utf-8'?><pessoa><nome>Barack Obama</nome></pessoa>" }
|
18
|
+
mock(connection).get("/cadunii/ws/resources/pessoa/1", { 'Content-Type' => 'text/xml' }) { response }
|
19
|
+
end
|
20
|
+
|
9
21
|
it "should parse the resource" do
|
10
|
-
connection = mock
|
11
|
-
response = mock
|
12
|
-
body = "<?xml version='1.0' encoding='utf-8'?><pessoa><nome>Barack Obama</nome></pessoa>"
|
13
|
-
mock(response).body { body }
|
14
|
-
|
15
|
-
mock(subject).authorization { Nokogiri::XML("<?xml version='1.0' encoding='utf-8'?><pessoa><usuarioID>1</usuarioID></pessoa>").children }
|
16
|
-
mock(connection).get("/cadunii/ws/resources/pessoa/1", {'Content-Type' => 'text/xml'}) { response }
|
17
|
-
mock(subject).connection { connection }
|
18
|
-
|
19
22
|
subject.content.xpath('nome').text.should == 'Barack Obama'
|
20
23
|
end
|
21
24
|
end
|
22
25
|
|
23
26
|
describe "#authorization" do
|
24
|
-
|
25
|
-
connection = mock
|
26
|
-
response = mock
|
27
|
+
before do
|
27
28
|
mock(response).body { "<?xml version='1.0' encoding='utf-8'?><pessoa><usuarioID>1</id></usuarioID>" }
|
28
29
|
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(subject).connection { connection }
|
30
|
-
|
31
|
-
subject.authorization.xpath('usuarioID').text.should == '1'
|
32
30
|
end
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
it "should parse the resource request" do
|
37
|
-
connection = mock
|
38
|
-
response = mock
|
39
|
-
body = "<?xml version='1.0' encoding='utf-8'?><pessoa><nome>Barack Obama</nome></pessoa>"
|
40
|
-
mock(response).body { body }
|
41
|
-
|
42
|
-
mock(subject).authorization { Nokogiri::XML("<?xml version='1.0' encoding='utf-8'?><pessoa><usuarioID>1</usuarioID></pessoa>").children }
|
43
|
-
mock(connection).get("/cadunii/ws/resources/pessoa/1", {'Content-Type' => 'text/xml'}) { response }
|
44
|
-
mock(subject).connection { connection }
|
45
|
-
|
46
|
-
subject.resource.should == body
|
31
|
+
|
32
|
+
it "should parse the authorization request" do
|
33
|
+
subject.authorization.xpath('usuarioID').text.should == '1'
|
47
34
|
end
|
48
35
|
end
|
49
36
|
end
|
data/spec/cadun/user_spec.rb
CHANGED
@@ -2,76 +2,53 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Cadun::User do
|
5
|
+
include Cadun
|
5
6
|
|
6
|
-
|
7
|
-
load_config
|
8
|
-
stub_requests
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should load a gateway" do
|
12
|
-
mock(Cadun::Gateway).new("GLB_ID", "127.0.0.1", 2626)
|
13
|
-
Cadun::User.new("GLB_ID", "127.0.0.1", 2626)
|
14
|
-
end
|
15
|
-
|
16
|
-
subject { Cadun::User.new("GLB_ID", "127.0.0.1", 2626) }
|
17
|
-
|
18
|
-
describe "#id" do
|
19
|
-
it { subject.id.should == "21737810" }
|
20
|
-
end
|
7
|
+
subject { User.new "GLB_ID", "127.0.0.1", 2626 }
|
21
8
|
|
22
|
-
|
23
|
-
|
9
|
+
def self.verify_method(method, value)
|
10
|
+
describe "##{method}" do
|
11
|
+
specify { subject.send(method).should == value }
|
12
|
+
end
|
24
13
|
end
|
25
14
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
describe "#phone" do
|
31
|
-
it { subject.phone.should == "21 22881060" }
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "#mobile" do
|
35
|
-
it { subject.mobile.should == "21 99999999" }
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "#email" do
|
39
|
-
it { subject.email.should == "fab1@spam.la"}
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "#gender" do
|
43
|
-
it { subject.gender.should == "MASCULINO" }
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#city" do
|
47
|
-
it { subject.city.should == "Rio de Janeiro"}
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "#state" do
|
51
|
-
it { subject.state.should == "RJ" }
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "#status" do
|
55
|
-
it { subject.status.should == "ATIVO" }
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "#address" do
|
59
|
-
it { subject.address.should == "Rua Uruguai, 59"}
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "#suburb" do
|
63
|
-
it { subject.suburb.should == "Andaraí" }
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "#cpf" do
|
67
|
-
it { subject.cpf.should == "09532034765" }
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "#login" do
|
71
|
-
it { subject.login.should == "fabricio_fab1" }
|
15
|
+
before do
|
16
|
+
load_config
|
17
|
+
stub_requests
|
72
18
|
end
|
73
19
|
|
74
|
-
|
75
|
-
|
76
|
-
|
20
|
+
it "should load the gateway" do
|
21
|
+
mock(Gateway).new "GLB_ID", "127.0.0.1", 2626
|
22
|
+
subject
|
23
|
+
end
|
24
|
+
|
25
|
+
verify_method "id", "21737810"
|
26
|
+
|
27
|
+
verify_method "name", "Fabricio Rodrigo Lopes"
|
28
|
+
|
29
|
+
verify_method "birthday", Date.new(1983, 02, 22)
|
30
|
+
|
31
|
+
verify_method "phone", "21 22881060"
|
32
|
+
|
33
|
+
verify_method "mobile", "21 99999999"
|
34
|
+
|
35
|
+
verify_method "email", "fab1@spam.la"
|
36
|
+
|
37
|
+
verify_method "gender", "MASCULINO"
|
38
|
+
|
39
|
+
verify_method "city", "Rio de Janeiro"
|
40
|
+
|
41
|
+
verify_method "state", "RJ"
|
42
|
+
|
43
|
+
verify_method "status", "ATIVO"
|
44
|
+
|
45
|
+
verify_method "address", "Rua Uruguai, 59"
|
46
|
+
|
47
|
+
verify_method "neighborhood", "Andaraí"
|
48
|
+
|
49
|
+
verify_method "cpf", "09532034765"
|
50
|
+
|
51
|
+
verify_method "login", "fabricio_fab1"
|
52
|
+
|
53
|
+
verify_method "country", "Brasil"
|
77
54
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -19,12 +19,16 @@ end
|
|
19
19
|
|
20
20
|
def stub_requests
|
21
21
|
FakeWeb.register_uri :put, "http://isp-authenticator.dev.globoi.com:8280/ws/rest/autorizacao",
|
22
|
-
:body => File.
|
22
|
+
:body => "#{File.dirname(__FILE__)}/support/fixtures/autorizacao.xml"
|
23
23
|
|
24
24
|
FakeWeb.register_uri :get, "http://isp-authenticator.dev.globoi.com:8280/cadunii/ws/resources/pessoa/21737810",
|
25
|
-
:body => File.
|
25
|
+
:body => "#{File.dirname(__FILE__)}/support/fixtures/pessoa.xml"
|
26
26
|
end
|
27
27
|
|
28
28
|
def load_config
|
29
|
-
Cadun::Config.load_file File.
|
29
|
+
Cadun::Config.load_file "#{File.dirname(__FILE__)}/support/fixtures/config.yml"
|
30
|
+
end
|
31
|
+
|
32
|
+
def load_another_config
|
33
|
+
Cadun::Config.load_file "#{File.dirname(__FILE__)}/support/fixtures/another_config.yml"
|
30
34
|
end
|
metadata
CHANGED
@@ -2,10 +2,12 @@
|
|
2
2
|
name: cadun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
- Bruno
|
8
|
+
- Bruno
|
9
|
+
- Azisaka
|
10
|
+
- Maciel
|
9
11
|
autorequire:
|
10
12
|
bindir: bin
|
11
13
|
cert_chain: []
|
@@ -68,7 +70,7 @@ dependencies:
|
|
68
70
|
version: "0"
|
69
71
|
type: :development
|
70
72
|
version_requirements: *id005
|
71
|
-
description:
|
73
|
+
description: A wrapper for the CadUn authentication/authorization API
|
72
74
|
email:
|
73
75
|
- bruno@azisaka.com.br
|
74
76
|
executables: []
|
@@ -80,7 +82,6 @@ extra_rdoc_files: []
|
|
80
82
|
files:
|
81
83
|
- .gitignore
|
82
84
|
- .rspec
|
83
|
-
- .rvmrc
|
84
85
|
- Gemfile
|
85
86
|
- Rakefile
|
86
87
|
- cadun.gemspec
|
@@ -98,7 +99,7 @@ files:
|
|
98
99
|
- spec/support/fixtures/config.yml
|
99
100
|
- spec/support/fixtures/pessoa.xml
|
100
101
|
has_rdoc: true
|
101
|
-
homepage:
|
102
|
+
homepage: https://github.com/azisaka/Cadun
|
102
103
|
licenses: []
|
103
104
|
|
104
105
|
post_install_message:
|
@@ -124,13 +125,6 @@ rubyforge_project: cadun
|
|
124
125
|
rubygems_version: 1.6.2
|
125
126
|
signing_key:
|
126
127
|
specification_version: 3
|
127
|
-
summary:
|
128
|
-
test_files:
|
129
|
-
|
130
|
-
- spec/cadun/gateway_spec.rb
|
131
|
-
- spec/cadun/user_spec.rb
|
132
|
-
- spec/spec_helper.rb
|
133
|
-
- spec/support/fixtures/another_config.yml
|
134
|
-
- spec/support/fixtures/autorizacao.xml
|
135
|
-
- spec/support/fixtures/config.yml
|
136
|
-
- spec/support/fixtures/pessoa.xml
|
128
|
+
summary: A wrapper for the CadUn authentication/authorization API
|
129
|
+
test_files: []
|
130
|
+
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm 1.9.2@cadun
|