cadun 0.3.0 → 0.3.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/lib/cadun/gateway.rb +6 -1
- data/lib/cadun/version.rb +2 -2
- data/script/console +3 -0
- data/script/loader.rb +3 -0
- data/spec/cadun/gateway_spec.rb +56 -19
- data/spec/cadun/user_spec.rb +0 -20
- metadata +4 -2
data/lib/cadun/gateway.rb
CHANGED
@@ -23,6 +23,7 @@ module Cadun
|
|
23
23
|
elsif @options[:cadun_id]
|
24
24
|
@options[:cadun_id]
|
25
25
|
else
|
26
|
+
raise RuntimeError.new "not authorized" unless authorization.xpath("status").text == "AUTORIZADO"
|
26
27
|
authorization.xpath("usuarioID").text
|
27
28
|
end
|
28
29
|
|
@@ -34,6 +35,10 @@ module Cadun
|
|
34
35
|
end
|
35
36
|
|
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
|
+
|
37
42
|
put "/ws/rest/autorizacao", "<usuarioAutorizado><glbId>#{@options[:glb_id]}</glbId><ip>#{@options[:ip]}</ip><servicoID>#{@options[:service_id]}</servicoID></usuarioAutorizado>"
|
38
43
|
end
|
39
44
|
|
@@ -41,4 +46,4 @@ module Cadun
|
|
41
46
|
connection.put(path, data, {'Content-Type' => 'text/xml'}).body
|
42
47
|
end
|
43
48
|
end
|
44
|
-
end
|
49
|
+
end
|
data/lib/cadun/version.rb
CHANGED
data/script/console
ADDED
data/script/loader.rb
ADDED
data/spec/cadun/gateway_spec.rb
CHANGED
@@ -4,33 +4,70 @@ describe Cadun::Gateway do
|
|
4
4
|
let(:connection) { mock }
|
5
5
|
let(:response) { mock }
|
6
6
|
|
7
|
-
before
|
8
|
-
load_config
|
9
|
-
mock(subject).connection { connection }
|
10
|
-
end
|
11
|
-
|
12
|
-
subject { Cadun::Gateway.new(:glb_id => "GLB_ID", :ip => "127.0.0.1", :service_id => 2626) }
|
7
|
+
before { load_config }
|
13
8
|
|
14
9
|
describe "#content" do
|
15
|
-
|
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
|
10
|
+
let(:gateway) { Cadun::Gateway.new(:glb_id => "GLB_ID", :ip => "127.0.0.1", :service_id => 2626) }
|
20
11
|
|
21
|
-
|
22
|
-
|
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
|
23
38
|
end
|
24
39
|
end
|
25
40
|
|
26
41
|
describe "#authorization" do
|
27
|
-
|
28
|
-
|
29
|
-
|
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") }
|
30
66
|
end
|
31
67
|
|
32
|
-
|
33
|
-
|
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") }
|
34
71
|
end
|
35
72
|
end
|
36
|
-
end
|
73
|
+
end
|
data/spec/cadun/user_spec.rb
CHANGED
@@ -23,39 +23,22 @@ describe Cadun::User do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
verify_method "id", "21737810"
|
26
|
-
|
27
26
|
verify_method "name", "Fabricio Rodrigo Lopes"
|
28
|
-
|
29
27
|
verify_method "birthday", Date.new(1983, 02, 22)
|
30
|
-
|
31
28
|
verify_method "phone", "21 22881060"
|
32
|
-
|
33
29
|
verify_method "mobile", "21 99999999"
|
34
|
-
|
35
30
|
verify_method "email", "fab1@spam.la"
|
36
|
-
|
37
31
|
verify_method "gender", "MASCULINO"
|
38
|
-
|
39
32
|
verify_method "city", "Rio de Janeiro"
|
40
|
-
|
41
33
|
verify_method "state", "RJ"
|
42
|
-
|
43
34
|
verify_method "status", "ATIVO"
|
44
|
-
|
45
35
|
verify_method "address", "Rua Uruguai, 59"
|
46
|
-
|
47
36
|
verify_method "neighborhood", "Andaraí"
|
48
|
-
|
49
37
|
verify_method "cpf", "09532034765"
|
50
|
-
|
51
38
|
verify_method "login", "fabricio_fab1"
|
52
|
-
|
53
39
|
verify_method "country", "Brasil"
|
54
|
-
|
55
40
|
verify_method "user_type", "NAO_ASSINANTE"
|
56
|
-
|
57
41
|
verify_method "cadun_id", "21737810"
|
58
|
-
|
59
42
|
verify_method "complement", "807"
|
60
43
|
end
|
61
44
|
|
@@ -85,20 +68,17 @@ describe Cadun::User do
|
|
85
68
|
describe ".find_by_email" do
|
86
69
|
context "given an email without domain" do
|
87
70
|
subject { Cadun::User.find_by_email("silvano") }
|
88
|
-
|
89
71
|
verify_method "id", "24510533"
|
90
72
|
end
|
91
73
|
|
92
74
|
context "given an email with domain" do
|
93
75
|
subject { Cadun::User.find_by_email("silvano@corp.globo.com") }
|
94
|
-
|
95
76
|
verify_method "id", "24510533"
|
96
77
|
end
|
97
78
|
end
|
98
79
|
|
99
80
|
describe ".find_by_id" do
|
100
81
|
subject { Cadun::User.find_by_id("10001000") }
|
101
|
-
|
102
82
|
verify_method "id", "10001000"
|
103
83
|
end
|
104
84
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: cadun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Bruno
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2011-
|
15
|
+
date: 2011-06-08 00:00:00 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: nokogiri
|
@@ -89,6 +89,8 @@ files:
|
|
89
89
|
- lib/cadun/gateway.rb
|
90
90
|
- lib/cadun/user.rb
|
91
91
|
- lib/cadun/version.rb
|
92
|
+
- script/console
|
93
|
+
- script/loader.rb
|
92
94
|
- spec/cadun/config_spec.rb
|
93
95
|
- spec/cadun/gateway_spec.rb
|
94
96
|
- spec/cadun/user_spec.rb
|