tictoc-savon 0.7.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.autotest +5 -0
  2. data/CHANGELOG +176 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +64 -0
  5. data/Rakefile +50 -0
  6. data/lib/savon.rb +35 -0
  7. data/lib/savon/client.rb +131 -0
  8. data/lib/savon/core_ext.rb +8 -0
  9. data/lib/savon/core_ext/array.rb +31 -0
  10. data/lib/savon/core_ext/datetime.rb +10 -0
  11. data/lib/savon/core_ext/hash.rb +107 -0
  12. data/lib/savon/core_ext/net_http.rb +19 -0
  13. data/lib/savon/core_ext/object.rb +16 -0
  14. data/lib/savon/core_ext/string.rb +69 -0
  15. data/lib/savon/core_ext/symbol.rb +8 -0
  16. data/lib/savon/core_ext/uri.rb +10 -0
  17. data/lib/savon/logger.rb +56 -0
  18. data/lib/savon/request.rb +138 -0
  19. data/lib/savon/response.rb +174 -0
  20. data/lib/savon/soap.rb +302 -0
  21. data/lib/savon/version.rb +5 -0
  22. data/lib/savon/wsdl.rb +137 -0
  23. data/lib/savon/wsdl_stream.rb +85 -0
  24. data/lib/savon/wsse.rb +163 -0
  25. data/spec/basic_spec_helper.rb +11 -0
  26. data/spec/endpoint_helper.rb +23 -0
  27. data/spec/fixtures/gzip/gzip_response_fixture.rb +7 -0
  28. data/spec/fixtures/gzip/message.gz +0 -0
  29. data/spec/fixtures/response/response_fixture.rb +36 -0
  30. data/spec/fixtures/response/xml/authentication.xml +14 -0
  31. data/spec/fixtures/response/xml/multi_ref.xml +39 -0
  32. data/spec/fixtures/response/xml/soap_fault.xml +8 -0
  33. data/spec/fixtures/response/xml/soap_fault12.xml +18 -0
  34. data/spec/fixtures/wsdl/wsdl_fixture.rb +37 -0
  35. data/spec/fixtures/wsdl/wsdl_fixture.yml +42 -0
  36. data/spec/fixtures/wsdl/xml/authentication.xml +63 -0
  37. data/spec/fixtures/wsdl/xml/geotrust.xml +156 -0
  38. data/spec/fixtures/wsdl/xml/namespaced_actions.xml +307 -0
  39. data/spec/fixtures/wsdl/xml/no_namespace.xml +115 -0
  40. data/spec/http_stubs.rb +26 -0
  41. data/spec/integration/http_basic_auth_spec.rb +16 -0
  42. data/spec/integration/server.rb +51 -0
  43. data/spec/savon/client_spec.rb +86 -0
  44. data/spec/savon/core_ext/array_spec.rb +49 -0
  45. data/spec/savon/core_ext/datetime_spec.rb +21 -0
  46. data/spec/savon/core_ext/hash_spec.rb +190 -0
  47. data/spec/savon/core_ext/net_http_spec.rb +38 -0
  48. data/spec/savon/core_ext/object_spec.rb +34 -0
  49. data/spec/savon/core_ext/string_spec.rb +99 -0
  50. data/spec/savon/core_ext/symbol_spec.rb +12 -0
  51. data/spec/savon/core_ext/uri_spec.rb +19 -0
  52. data/spec/savon/request_spec.rb +117 -0
  53. data/spec/savon/response_spec.rb +179 -0
  54. data/spec/savon/soap_spec.rb +202 -0
  55. data/spec/savon/wsdl_spec.rb +107 -0
  56. data/spec/savon/wsse_spec.rb +132 -0
  57. data/spec/spec.opts +4 -0
  58. data/spec/spec_helper.rb +5 -0
  59. metadata +229 -0
@@ -0,0 +1,202 @@
1
+ require "spec_helper"
2
+
3
+ describe Savon::SOAP do
4
+ before do
5
+ @operation = WSDLFixture.authentication(:operations)[:authenticate]
6
+ @action, @input = @operation[:action], @operation[:input]
7
+ @soap = Savon::SOAP.new @action, @input, EndpointHelper.soap_endpoint
8
+ end
9
+
10
+ it "should contain the SOAP namespace for each supported SOAP version" do
11
+ Savon::SOAP::Versions.each do |soap_version|
12
+ Savon::SOAP::Namespace[soap_version].should be_a(String)
13
+ Savon::SOAP::Namespace[soap_version].should_not be_empty
14
+ end
15
+ end
16
+
17
+ it "should contain the Content-Types for each supported SOAP version" do
18
+ Savon::SOAP::Versions.each do |soap_version|
19
+ Savon::SOAP::ContentType[soap_version].should be_a(String)
20
+ Savon::SOAP::ContentType[soap_version].should_not be_empty
21
+ end
22
+ end
23
+
24
+ it "should contain an Array of supported SOAP versions" do
25
+ Savon::SOAP::Versions.should be_an(Array)
26
+ Savon::SOAP::Versions.should_not be_empty
27
+ end
28
+
29
+ it "should contain the xs:dateTime format" do
30
+ Savon::SOAP::DateTimeFormat.should be_a(String)
31
+ Savon::SOAP::DateTimeFormat.should_not be_empty
32
+
33
+ DateTime.new(2012, 03, 22, 16, 22, 33).strftime(Savon::SOAP::DateTimeFormat).
34
+ should == "2012-03-22T16:22:33Z"
35
+ end
36
+
37
+ it "should contain a Regexp matching the xs:dateTime format" do
38
+ Savon::SOAP::DateTimeRegexp.should be_a(Regexp)
39
+ (Savon::SOAP::DateTimeRegexp === "2012-03-22T16:22:33").should be_true
40
+ end
41
+
42
+ it "should default to SOAP 1.1" do
43
+ Savon::SOAP.version.should == 1
44
+ end
45
+
46
+ describe "xml returned via to_xml" do
47
+ before do
48
+ @xml_declaration = '<?xml version="1.0" encoding="UTF-8"?>'
49
+ @namespace = { "xmlns:ns" => "http://example.com" }
50
+ @namespace_string = 'xmlns:ns="http://example.com"'
51
+ @namespaces = { "xmlns:ns" => "http://ns.example.com", "xmlns:ns2" => "http://ns2.example.com" }
52
+
53
+ # reset to defaults
54
+ Savon::SOAP.version = 1
55
+ Savon::SOAP.header = {}
56
+ Savon::SOAP.namespaces = {}
57
+ end
58
+
59
+ it "should contain an xml declaration" do
60
+ @soap.to_xml.should include(@xml_declaration)
61
+ end
62
+
63
+ # namespaces
64
+
65
+ it "should contain the namespace for SOAP 1.1" do
66
+ @soap.to_xml.should include('xmlns:env="' + Savon::SOAP::Namespace[1] + '"')
67
+ end
68
+
69
+ it "should contain the namespace for SOAP 1.2 when defined globally" do
70
+ Savon::SOAP.version = 2
71
+ @soap.to_xml.should include('xmlns:env="' + Savon::SOAP::Namespace[2] + '"')
72
+ end
73
+
74
+ it "should contain the namespace for SOAP 1.2 when defined per request" do
75
+ @soap.version = 2
76
+ @soap.to_xml.should include('xmlns:env="' + Savon::SOAP::Namespace[2] + '"')
77
+ end
78
+
79
+ it "should containg a xmlns:wsdl namespace defined via the :namespace shortcut method" do
80
+ @soap.namespace = "http://wsdl.example.com"
81
+ @soap.to_xml.should include('xmlns:wsdl="http://wsdl.example.com"')
82
+ end
83
+
84
+ it "should accept custom namespaces when defined globally" do
85
+ Savon::SOAP.namespaces = @namespace
86
+ @soap.to_xml.should include("<env:Envelope " + @namespace_string)
87
+ end
88
+
89
+ it "should accept custom namespaces when defined per request" do
90
+ @soap.namespaces = @namespace
91
+ @soap.to_xml.should include("<env:Envelope " + @namespace_string)
92
+ end
93
+
94
+ it "should merge global and per request namespaces" do
95
+ Savon::SOAP.namespaces = @namespaces
96
+ @soap.namespaces = @namespace
97
+ @soap.to_xml.should include(
98
+ 'xmlns:ns="http://example.com"',
99
+ 'xmlns:ns2="http://ns2.example.com"'
100
+ )
101
+ end
102
+
103
+ # header
104
+
105
+ it "should not contain a header tag unless specified" do
106
+ @soap.to_xml.should_not include("<env:Header>")
107
+ end
108
+
109
+ it "should accept a custom (String) header defined globally" do
110
+ Savon::SOAP.header = "<key>value</key>"
111
+ @soap.to_xml.should include("<env:Header><key>value</key></env:Header>")
112
+ end
113
+
114
+ it "should accept a custom (Hash) header defined globally" do
115
+ Savon::SOAP.header[:key] = "value"
116
+ @soap.to_xml.should include("<env:Header><key>value</key></env:Header>")
117
+ end
118
+
119
+ it "should accept a custom (String) header defined per request" do
120
+ @soap.header = "<key>value</key>"
121
+ @soap.to_xml.should include("<env:Header><key>value</key></env:Header>")
122
+ end
123
+
124
+ it "should accept a custom (Hash) header defined per request" do
125
+ @soap.header[:key] = "value"
126
+ @soap.to_xml.should include("<env:Header><key>value</key></env:Header>")
127
+ end
128
+
129
+ it "should merge global and per request headers defined as Strings" do
130
+ Savon::SOAP.header = "<key2>other value</key2>"
131
+ @soap.header = "<key>value</key>"
132
+ @soap.to_xml.should include(
133
+ "<env:Header><key2>other value</key2><key>value</key></env:Header>"
134
+ )
135
+ end
136
+
137
+ it "should merge global and per request headers defined as Hashes" do
138
+ Savon::SOAP.header = { :key => "value", :key2 => "global value" }
139
+ @soap.header[:key2] = "request value"
140
+ @soap.to_xml.should match(
141
+ /<env:Header>(<key>value<\/key><key2>request value<\/key2>|<key2>request value<\/key2><key>value<\/key>)<\/env:Header>/
142
+ )
143
+ end
144
+
145
+ it "should use the :header method from a given WSSE object to include a WSSE header" do
146
+ wsse = "some compliant object"
147
+ wsse.stubs(:header).returns("<wsse>authentication</wsse>")
148
+
149
+ @soap.wsse = wsse
150
+ @soap.to_xml.should include("<env:Header><wsse>authentication</wsse></env:Header>")
151
+ end
152
+
153
+ # input tag
154
+
155
+ it "should contain a :wsdl namespaced input tag matching the :input property on instantiation" do
156
+ @soap = Savon::SOAP.new "someAction", "someInput", EndpointHelper.soap_endpoint
157
+ @soap.to_xml.should include('<wsdl:someInput>')
158
+ end
159
+
160
+ it "should fall back to using the :action property whem :input is blank" do
161
+ @soap = Savon::SOAP.new "someAction", "", EndpointHelper.soap_endpoint
162
+ @soap.to_xml.should include('<wsdl:someAction>')
163
+ end
164
+
165
+ it "should containg namespaces defined via an input tag Array containing the tag name and a Hash of namespaces" do
166
+ input = ["someInput", { "otherNs" => "http://otherns.example.com" }]
167
+ @soap = Savon::SOAP.new "someAction", input, EndpointHelper.soap_endpoint
168
+ @soap.to_xml.should include('<wsdl:someInput otherNs="http://otherns.example.com">')
169
+ end
170
+
171
+ # xml body
172
+
173
+ it "should contain the SOAP body defined as a Hash" do
174
+ @soap.body = { :someTag => "some value" }
175
+ @soap.to_xml.should include("<someTag>some value</someTag>")
176
+ end
177
+
178
+ it "should contain the SOAP body defined as an Object responding to :to_s" do
179
+ @soap.body = "<someTag>some value</someTag>"
180
+ @soap.to_xml.should include(@soap.body)
181
+ end
182
+
183
+ # xml
184
+
185
+ it "should be a completely custom XML when specified" do
186
+ @soap.xml = "custom SOAP body"
187
+ @soap.to_xml.should == @soap.xml
188
+ end
189
+
190
+ # safety check
191
+
192
+ it "should be a valid SOAP request" do
193
+ @soap.to_xml.should include(
194
+ @xml_declaration +
195
+ '<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">' <<
196
+ '<env:Body><wsdl:authenticate></wsdl:authenticate></env:Body>' <<
197
+ '</env:Envelope>'
198
+ )
199
+ end
200
+ end
201
+ end
202
+
@@ -0,0 +1,107 @@
1
+ require "spec_helper"
2
+
3
+ describe Savon::WSDL do
4
+ describe "a common WSDL document" do
5
+ before { @wsdl = new_wsdl }
6
+
7
+ it "is initialized with a Savon::Request object" do
8
+ Savon::WSDL.new Savon::Request.new(EndpointHelper.wsdl_endpoint)
9
+ end
10
+
11
+ it "it accepts a custom SOAP endpoint" do
12
+ wsdl = Savon::WSDL.new Savon::Request.new(EndpointHelper.wsdl_endpoint), "http://localhost"
13
+ wsdl.soap_endpoint.should == "http://localhost"
14
+ end
15
+
16
+ it "is enabled by default" do
17
+ @wsdl.enabled?.should be_true
18
+ end
19
+
20
+ it "has a getter for the namespace URI" do
21
+ @wsdl.namespace_uri.should == WSDLFixture.authentication(:namespace_uri)
22
+ end
23
+
24
+ it "has a getter for returning an Array of available SOAP actions" do
25
+ WSDLFixture.authentication(:operations).keys.each do |soap_action|
26
+ @wsdl.soap_actions.should include(soap_action)
27
+ end
28
+ end
29
+
30
+ it "has a getter for returning a Hash of available SOAP operations" do
31
+ @wsdl.operations.should == WSDLFixture.authentication(:operations)
32
+ end
33
+
34
+ it "responds to SOAP actions while still behaving as usual otherwise" do
35
+ WSDLFixture.authentication(:operations).keys.each do |soap_action|
36
+ @wsdl.respond_to?(soap_action).should be_true
37
+ end
38
+
39
+ @wsdl.respond_to?(:object_id).should be_true
40
+ @wsdl.respond_to?(:some_undefined_method).should be_false
41
+ end
42
+
43
+ it "returns the raw WSDL document for to_s" do
44
+ @wsdl.to_s.should == WSDLFixture.authentication
45
+ end
46
+ end
47
+
48
+ describe "a WSDL document having core sections without a namespace" do
49
+ before { @wsdl = new_wsdl :no_namespace }
50
+
51
+ it "returns the namespace URI" do
52
+ @wsdl.namespace_uri.should == WSDLFixture.no_namespace(:namespace_uri)
53
+ end
54
+
55
+ it "returns an Array of available SOAP actions" do
56
+ WSDLFixture.no_namespace(:operations).keys.each do |soap_action|
57
+ @wsdl.soap_actions.should include(soap_action)
58
+ end
59
+ end
60
+
61
+ it "returns a Hash of SOAP operations" do
62
+ @wsdl.operations.should == WSDLFixture.no_namespace(:operations)
63
+ end
64
+ end
65
+
66
+ describe "a WSDL document with namespaced SOAP actions" do
67
+ before { @wsdl = new_wsdl :namespaced_actions }
68
+
69
+ it "returns the namespace URI" do
70
+ @wsdl.namespace_uri.should == WSDLFixture.namespaced_actions(:namespace_uri)
71
+ end
72
+
73
+ it "returns an Array of available SOAP actions" do
74
+ WSDLFixture.namespaced_actions(:operations).keys.each do |soap_action|
75
+ @wsdl.soap_actions.should include(soap_action)
76
+ end
77
+ end
78
+
79
+ it "returns a Hash of SOAP operations" do
80
+ @wsdl.operations.should == WSDLFixture.namespaced_actions(:operations)
81
+ end
82
+ end
83
+
84
+ describe "a WSDL document from geotrust" do
85
+ before { @wsdl = new_wsdl :geotrust }
86
+
87
+ it "returns the namespace URI" do
88
+ @wsdl.namespace_uri.should == WSDLFixture.geotrust(:namespace_uri)
89
+ end
90
+
91
+ it "returns an Array of available SOAP actions" do
92
+ WSDLFixture.geotrust(:operations).keys.each do |soap_action|
93
+ @wsdl.soap_actions.should include(soap_action)
94
+ end
95
+ end
96
+
97
+ it "returns a Hash of SOAP operations" do
98
+ @wsdl.operations.should == WSDLFixture.geotrust(:operations)
99
+ end
100
+ end
101
+
102
+ def new_wsdl(fixture = nil)
103
+ endpoint = fixture ? EndpointHelper.wsdl_endpoint(fixture) : EndpointHelper.wsdl_endpoint
104
+ Savon::WSDL.new Savon::Request.new(endpoint)
105
+ end
106
+
107
+ end
@@ -0,0 +1,132 @@
1
+ require "spec_helper"
2
+
3
+ describe Savon::WSSE do
4
+ before do
5
+ Savon::WSSE.username, Savon::WSSE.password, Savon::WSSE.digest = nil, nil, false
6
+ @wsse, @username, @password = Savon::WSSE.new, "gorilla", "secret"
7
+ end
8
+
9
+ it "contains the namespace for WS Security Secext" do
10
+ Savon::WSSE::WSENamespace.should be_a(String)
11
+ Savon::WSSE::WSENamespace.should_not be_empty
12
+ end
13
+
14
+ it "contains the namespace for WS Security Utility" do
15
+ Savon::WSSE::WSUNamespace.should be_a(String)
16
+ Savon::WSSE::WSUNamespace.should_not be_empty
17
+ end
18
+
19
+ it "defaults to nil for the WSSE username (global setting)" do
20
+ Savon::WSSE.username.should be_nil
21
+ end
22
+
23
+ it "has both getter and setter for the WSSE username (global setting)" do
24
+ Savon::WSSE.username = "gorilla"
25
+ Savon::WSSE.username.should == "gorilla"
26
+ end
27
+
28
+ it "defaults to nil for the WSSE password (global setting)" do
29
+ Savon::WSSE.password.should be_nil
30
+ end
31
+
32
+ it "has both getter and setter for the WSSE password (global setting)" do
33
+ Savon::WSSE.password = "secret"
34
+ Savon::WSSE.password.should == "secret"
35
+ end
36
+
37
+ it "defaults to nil for whether to use WSSE digest (global setting)" do
38
+ Savon::WSSE.digest?.should be_false
39
+ end
40
+
41
+ it "has both getter and setter for whether to use WSSE digest (global setting)" do
42
+ Savon::WSSE.digest = true
43
+ Savon::WSSE.digest?.should == true
44
+ end
45
+
46
+ it "defaults to nil for the WSSE username" do
47
+ @wsse.username.should be_nil
48
+ end
49
+
50
+ it "has both getter and setter for the WSSE username" do
51
+ @wsse.username = "gorilla"
52
+ @wsse.username.should == "gorilla"
53
+ end
54
+
55
+ it "defaults to nil for the WSSE password" do
56
+ @wsse.password.should be_nil
57
+ end
58
+
59
+ it "has both getter and setter for the WSSE password" do
60
+ @wsse.password = "secret"
61
+ @wsse.password.should == "secret"
62
+ end
63
+
64
+ it "defaults to nil for whether to use WSSE digest" do
65
+ @wsse.digest?.should be_false
66
+ end
67
+
68
+ it "has both getter and setter for whether to use WSSE digest" do
69
+ @wsse.digest = true
70
+ @wsse.digest?.should == true
71
+ end
72
+
73
+ describe "header" do
74
+ describe "returns the XML for a WSSE authentication header" do
75
+ it "with WSSE credentials specified" do
76
+ @wsse.username = @username
77
+ @wsse.password = @password
78
+ header = @wsse.header
79
+
80
+ header.should include_security_namespaces
81
+ header.should include(@username)
82
+ header.should include(@password)
83
+ header.should include(Savon::WSSE::PasswordTextURI)
84
+ end
85
+
86
+ it "with WSSE credentials specified via defaults" do
87
+ Savon::WSSE.username = @username
88
+ Savon::WSSE.password = @password
89
+ header = @wsse.header
90
+
91
+ header.should include_security_namespaces
92
+ header.should include(@username)
93
+ header.should include(@password)
94
+ header.should include(Savon::WSSE::PasswordTextURI)
95
+ end
96
+ end
97
+
98
+ describe "returns the XML for a WSSE digest header if specified" do
99
+ it "via accessors" do
100
+ @wsse.username = @username
101
+ @wsse.password = @password
102
+ @wsse.digest = true
103
+ header = @wsse.header
104
+
105
+ header.should include_security_namespaces
106
+ header.should include(@username)
107
+ header.should_not include(@password)
108
+ header.should include(Savon::WSSE::PasswordDigestURI)
109
+ end
110
+
111
+ it "via defaults" do
112
+ @wsse.username = @username
113
+ @wsse.password = @password
114
+ Savon::WSSE.digest = true
115
+ header = @wsse.header
116
+
117
+ header.should include_security_namespaces
118
+ header.should include(@username)
119
+ header.should_not include(@password)
120
+ header.should include(Savon::WSSE::PasswordDigestURI)
121
+ end
122
+ end
123
+
124
+ def include_security_namespaces
125
+ simple_matcher("include security namespaces") do |given|
126
+ given.should include(Savon::WSSE::WSENamespace)
127
+ given.should include(Savon::WSSE::WSUNamespace)
128
+ end
129
+ end
130
+ end
131
+
132
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse