savon-SU 2.11.1b

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.travis.yml +15 -0
  4. data/.yardopts +6 -0
  5. data/CHANGELOG.md +1098 -0
  6. data/CONTRIBUTING.md +46 -0
  7. data/Gemfile +18 -0
  8. data/LICENSE +20 -0
  9. data/README.md +69 -0
  10. data/Rakefile +14 -0
  11. data/donate.png +0 -0
  12. data/lib/savon.rb +27 -0
  13. data/lib/savon/block_interface.rb +26 -0
  14. data/lib/savon/builder.rb +205 -0
  15. data/lib/savon/client.rb +102 -0
  16. data/lib/savon/core_ext/string.rb +29 -0
  17. data/lib/savon/header.rb +93 -0
  18. data/lib/savon/http_error.rb +27 -0
  19. data/lib/savon/log_message.rb +52 -0
  20. data/lib/savon/message.rb +37 -0
  21. data/lib/savon/mock.rb +5 -0
  22. data/lib/savon/mock/expectation.rb +80 -0
  23. data/lib/savon/mock/spec_helper.rb +62 -0
  24. data/lib/savon/model.rb +84 -0
  25. data/lib/savon/operation.rb +144 -0
  26. data/lib/savon/options.rb +410 -0
  27. data/lib/savon/qualified_message.rb +50 -0
  28. data/lib/savon/request.rb +97 -0
  29. data/lib/savon/request_logger.rb +48 -0
  30. data/lib/savon/response.rb +113 -0
  31. data/lib/savon/soap_fault.rb +50 -0
  32. data/lib/savon/version.rb +3 -0
  33. data/savon-SU.gemspec +46 -0
  34. data/spec/fixtures/gzip/message.gz +0 -0
  35. data/spec/fixtures/response/another_soap_fault.xml +14 -0
  36. data/spec/fixtures/response/authentication.xml +14 -0
  37. data/spec/fixtures/response/f5.xml +39 -0
  38. data/spec/fixtures/response/header.xml +13 -0
  39. data/spec/fixtures/response/list.xml +18 -0
  40. data/spec/fixtures/response/multi_ref.xml +39 -0
  41. data/spec/fixtures/response/soap_fault.xml +8 -0
  42. data/spec/fixtures/response/soap_fault12.xml +18 -0
  43. data/spec/fixtures/response/soap_fault_funky.xml +8 -0
  44. data/spec/fixtures/response/taxcloud.xml +1 -0
  45. data/spec/fixtures/ssl/client_cert.pem +16 -0
  46. data/spec/fixtures/ssl/client_encrypted_key.pem +30 -0
  47. data/spec/fixtures/ssl/client_encrypted_key_cert.pem +24 -0
  48. data/spec/fixtures/ssl/client_key.pem +15 -0
  49. data/spec/fixtures/wsdl/authentication.xml +63 -0
  50. data/spec/fixtures/wsdl/betfair.xml +2981 -0
  51. data/spec/fixtures/wsdl/edialog.xml +15416 -0
  52. data/spec/fixtures/wsdl/interhome.xml +2137 -0
  53. data/spec/fixtures/wsdl/lower_camel.xml +52 -0
  54. data/spec/fixtures/wsdl/multiple_namespaces.xml +92 -0
  55. data/spec/fixtures/wsdl/multiple_types.xml +60 -0
  56. data/spec/fixtures/wsdl/no_message_tag.xml +1267 -0
  57. data/spec/fixtures/wsdl/taxcloud.xml +934 -0
  58. data/spec/fixtures/wsdl/team_software.xml +1 -0
  59. data/spec/fixtures/wsdl/vies.xml +176 -0
  60. data/spec/fixtures/wsdl/wasmuth.xml +153 -0
  61. data/spec/integration/centra_spec.rb +66 -0
  62. data/spec/integration/email_example_spec.rb +32 -0
  63. data/spec/integration/random_quote_spec.rb +23 -0
  64. data/spec/integration/ratp_example_spec.rb +28 -0
  65. data/spec/integration/stockquote_example_spec.rb +28 -0
  66. data/spec/integration/support/application.rb +82 -0
  67. data/spec/integration/support/server.rb +84 -0
  68. data/spec/integration/temperature_example_spec.rb +46 -0
  69. data/spec/integration/zipcode_example_spec.rb +42 -0
  70. data/spec/savon/builder_spec.rb +137 -0
  71. data/spec/savon/client_spec.rb +271 -0
  72. data/spec/savon/core_ext/string_spec.rb +37 -0
  73. data/spec/savon/features/message_tag_spec.rb +61 -0
  74. data/spec/savon/http_error_spec.rb +49 -0
  75. data/spec/savon/log_message_spec.rb +44 -0
  76. data/spec/savon/message_spec.rb +70 -0
  77. data/spec/savon/mock_spec.rb +174 -0
  78. data/spec/savon/model_spec.rb +182 -0
  79. data/spec/savon/observers_spec.rb +92 -0
  80. data/spec/savon/operation_spec.rb +230 -0
  81. data/spec/savon/options_spec.rb +1064 -0
  82. data/spec/savon/qualified_message_spec.rb +20 -0
  83. data/spec/savon/request_logger_spec.rb +37 -0
  84. data/spec/savon/request_spec.rb +496 -0
  85. data/spec/savon/response_spec.rb +270 -0
  86. data/spec/savon/soap_fault_spec.rb +131 -0
  87. data/spec/spec_helper.rb +30 -0
  88. data/spec/support/adapters.rb +48 -0
  89. data/spec/support/endpoint.rb +25 -0
  90. data/spec/support/fixture.rb +39 -0
  91. data/spec/support/integration.rb +9 -0
  92. data/spec/support/stdout.rb +25 -0
  93. metadata +317 -0
@@ -0,0 +1,271 @@
1
+ require "spec_helper"
2
+ require "integration/support/server"
3
+
4
+ describe Savon::Client do
5
+
6
+ before :all do
7
+ @server = IntegrationServer.run
8
+ end
9
+
10
+ after :all do
11
+ @server.stop
12
+ end
13
+
14
+ describe ".new" do
15
+ it "supports a block without arguments to create a client with global options" do
16
+ client = Savon.client do
17
+ wsdl Fixture.wsdl(:authentication)
18
+ end
19
+
20
+ expect(client.globals[:wsdl]).to eq(Fixture.wsdl(:authentication))
21
+ end
22
+
23
+ it "supports a block with one argument to create a client with global options" do
24
+ client = Savon.client do |globals|
25
+ globals.wsdl Fixture.wsdl(:authentication)
26
+ end
27
+
28
+ expect(client.globals[:wsdl]).to eq(Fixture.wsdl(:authentication))
29
+ end
30
+
31
+ it "builds an HTTPI request for Wasabi" do
32
+ http_request = mock
33
+ wsdl_request = mock(:build => http_request)
34
+ Savon::WSDLRequest.expects(:new).with(instance_of(Savon::GlobalOptions)).returns(wsdl_request)
35
+
36
+ Wasabi::Document.any_instance.expects(:request=).with(http_request)
37
+ Savon.client(:wsdl => "http://example.com")
38
+ end
39
+
40
+ it "raises if initialized with anything other than a Hash" do
41
+ expect { Savon.client("http://example.com") }.
42
+ to raise_error(Savon::InitializationError, /Some code tries to initialize Savon with the "http:\/\/example\.com" \(String\)/)
43
+ end
44
+
45
+ it "raises if not initialized with either a :wsdl or both :endpoint and :namespace options" do
46
+ expect { Savon.client(:endpoint => "http://example.com") }.
47
+ to raise_error(Savon::InitializationError, /Expected either a WSDL document or the SOAP endpoint and target namespace options/)
48
+ end
49
+
50
+ it "raises a when given an unknown option via the Hash syntax" do
51
+ expect { Savon.client(:invalid_global_option => true) }.
52
+ to raise_error(Savon::UnknownOptionError, "Unknown global option: :invalid_global_option")
53
+ end
54
+
55
+ it "raises a when given an unknown option via the block syntax" do
56
+ expect { Savon.client { another_invalid_global_option true } }.
57
+ to raise_error(Savon::UnknownOptionError, "Unknown global option: :another_invalid_global_option")
58
+ end
59
+ end
60
+
61
+ describe "#globals" do
62
+ it "returns the current set of global options" do
63
+ expect(new_client.globals).to be_an_instance_of(Savon::GlobalOptions)
64
+ end
65
+
66
+ fit "defaults :log to false" do
67
+ client = Savon.client(:wsdl => Fixture.wsdl(:authentication))
68
+ expect(client.globals[:log]).to be_falsey
69
+ end
70
+ end
71
+
72
+ describe "#service_name" do
73
+ it "returns the name of the service" do
74
+ expect(new_client.service_name).to eq('AuthenticationWebServiceImplService')
75
+ end
76
+ end
77
+
78
+ describe "#operations" do
79
+ it "returns all operation names" do
80
+ operations = new_client.operations
81
+ expect(operations).to eq([:authenticate])
82
+ end
83
+
84
+ it "raises when there is no WSDL document" do
85
+ expect { new_client_without_wsdl.operations }.to raise_error("Unable to inspect the service without a WSDL document.")
86
+ end
87
+ end
88
+
89
+ describe "#operation" do
90
+ it "returns a new SOAP operation" do
91
+ operation = new_client.operation(:authenticate)
92
+ expect(operation).to be_a(Savon::Operation)
93
+ end
94
+
95
+ it "raises if there's no such SOAP operation" do
96
+ expect { new_client.operation(:does_not_exist) }.
97
+ to raise_error(Savon::UnknownOperationError)
98
+ end
99
+
100
+ it "does not raise when there is no WSDL document" do
101
+ new_client_without_wsdl.operation(:does_not_exist)
102
+ end
103
+ end
104
+
105
+ describe "#call" do
106
+ it "calls a new SOAP operation" do
107
+ locals = { :message => { :symbol => "AAPL" } }
108
+ soap_response = new_soap_response
109
+
110
+ wsdl = Wasabi::Document.new('http://example.com')
111
+ operation = Savon::Operation.new(:authenticate, wsdl, Savon::GlobalOptions.new)
112
+ operation.expects(:call).with(locals).returns(soap_response)
113
+
114
+ Savon::Operation.expects(:create).with(
115
+ :authenticate,
116
+ instance_of(Wasabi::Document),
117
+ instance_of(Savon::GlobalOptions)
118
+ ).returns(operation)
119
+
120
+ response = new_client.call(:authenticate, locals)
121
+ expect(response).to eq(soap_response)
122
+ end
123
+
124
+ it "supports a block without arguments to call an operation with local options" do
125
+ client = new_client(:endpoint => @server.url(:repeat))
126
+
127
+ response = client.call(:authenticate) do
128
+ message(:symbol => "AAPL" )
129
+ end
130
+
131
+ expect(response.http.body).to include("<symbol>AAPL</symbol>")
132
+ end
133
+
134
+ it "supports a block with one argument to call an operation with local options" do
135
+ client = new_client(:endpoint => @server.url(:repeat))
136
+
137
+ # supports instance variables!
138
+ @instance_variable = { :symbol => "AAPL" }
139
+
140
+ response = client.call(:authenticate) do |locals|
141
+ locals.message(@instance_variable)
142
+ end
143
+
144
+ expect(response.http.body).to include("<symbol>AAPL</symbol>")
145
+ end
146
+
147
+ it "accepts arguments for the message tag" do
148
+ client = new_client(:endpoint => @server.url(:repeat))
149
+ response = client.call(:authenticate, :attributes => { "ID" => "ABC321"})
150
+
151
+ expect(response.http.body).to include('<tns:authenticate ID="ABC321">')
152
+ end
153
+
154
+ it "raises when the operation name is not a symbol" do
155
+ expect { new_client.call("not a symbol") }.to raise_error(
156
+ ArgumentError,
157
+ "Expected the first parameter (the name of the operation to call) to be a symbol\n" \
158
+ "Actual: \"not a symbol\" (String)"
159
+ )
160
+ end
161
+
162
+ it "raises a when given an unknown option via the Hash syntax" do
163
+ expect { new_client.call(:authenticate, :invalid_local_option => true) }.
164
+ to raise_error(Savon::UnknownOptionError, "Unknown local option: :invalid_local_option")
165
+ end
166
+
167
+ it "raises a when given an unknown option via the block syntax" do
168
+ expect { new_client.call(:authenticate) { another_invalid_local_option true } }.
169
+ to raise_error(Savon::UnknownOptionError, "Unknown local option: :another_invalid_local_option")
170
+ end
171
+ end
172
+
173
+ describe "#build_request" do
174
+ it "returns the request without making an actual call" do
175
+ expected_request = mock('request')
176
+ wsdl = Wasabi::Document.new('http://example.com')
177
+
178
+ operation = Savon::Operation.new(
179
+ :authenticate,
180
+ wsdl,
181
+ Savon::GlobalOptions.new
182
+ )
183
+ operation.expects(:request).returns(expected_request)
184
+
185
+ Savon::Operation.expects(:create).with(
186
+ :authenticate,
187
+ instance_of(Wasabi::Document),
188
+ instance_of(Savon::GlobalOptions)
189
+ ).returns(operation)
190
+
191
+ operation.expects(:call).never
192
+
193
+ client = new_client(:endpoint => @server.url(:repeat))
194
+ request = client.build_request(:authenticate) do
195
+ message(:symbol => "AAPL" )
196
+ end
197
+
198
+ expect(request).to eq expected_request
199
+ end
200
+
201
+ it "accepts a block without arguments" do
202
+ client = new_client(:endpoint => @server.url(:repeat))
203
+ request = client.build_request(:authenticate) do
204
+ message(:symbol => "AAPL" )
205
+ end
206
+
207
+ expect(request.body).
208
+ to include('<tns:authenticate><symbol>AAPL</symbol></tns:authenticate>')
209
+ end
210
+
211
+ it "accepts a block with one argument" do
212
+ client = new_client(:endpoint => @server.url(:repeat))
213
+
214
+ # supports instance variables!
215
+ @instance_variable = { :symbol => "AAPL" }
216
+
217
+ request = client.build_request(:authenticate) do |locals|
218
+ locals.message(@instance_variable)
219
+ end
220
+
221
+ expect(request.body).
222
+ to include("<tns:authenticate><symbol>AAPL</symbol></tns:authenticate>")
223
+ end
224
+
225
+ it "accepts argument for the message tag" do
226
+ client = new_client(:endpoint => @server.url(:repeat))
227
+ request = client.build_request(:authenticate, :attributes => { "ID" => "ABC321" })
228
+
229
+ expect(request.body).
230
+ to include("<tns:authenticate ID=\"ABC321\"></tns:authenticate>")
231
+ end
232
+
233
+ it "raises when the operation name is not a symbol" do
234
+ expect { new_client.build_request("not a symbol") }.to raise_error
235
+ end
236
+
237
+ it "raises when given an unknown option via the Hash syntax" do
238
+ expect { new_client.build_request(:authenticate, :invalid_local_option => true) }.to raise_error
239
+ end
240
+
241
+ it "raises when given an unknown option via the block syntax" do
242
+ expect { new_client.build_request(:authenticate) { another_invalid_local_option true } }.to raise_error
243
+ end
244
+ end
245
+
246
+ def new_http_response(options = {})
247
+ defaults = { :code => 200, :headers => {}, :body => Fixture.response(:authentication) }
248
+ response = defaults.merge options
249
+
250
+ HTTPI::Response.new response[:code], response[:headers], response[:body]
251
+ end
252
+
253
+ def new_soap_response(options = {})
254
+ http = new_http_response(options)
255
+ globals = Savon::GlobalOptions.new
256
+ locals = Savon::LocalOptions.new
257
+
258
+ Savon::Response.new(http, globals, locals)
259
+ end
260
+
261
+ def new_client(globals = {})
262
+ globals = { :wsdl => Fixture.wsdl(:authentication), :log => false }.merge(globals)
263
+ Savon.client(globals)
264
+ end
265
+
266
+ def new_client_without_wsdl(globals = {})
267
+ globals = { :endpoint => "http://example.co", :namespace => "http://v1.example.com", :log => false }.merge(globals)
268
+ Savon.client(globals)
269
+ end
270
+
271
+ end
@@ -0,0 +1,37 @@
1
+ require "spec_helper"
2
+
3
+ describe String do
4
+
5
+ describe "snakecase" do
6
+ it "lowercases one word CamelCase" do
7
+ expect("Merb".snakecase).to eq("merb")
8
+ end
9
+
10
+ it "makes one underscore snakecase two word CamelCase" do
11
+ expect("MerbCore".snakecase).to eq("merb_core")
12
+ end
13
+
14
+ it "handles CamelCase with more than 2 words" do
15
+ expect("SoYouWantContributeToMerbCore".snakecase).to eq("so_you_want_contribute_to_merb_core")
16
+ end
17
+
18
+ it "handles CamelCase with more than 2 capital letter in a row" do
19
+ expect("CNN".snakecase).to eq("cnn")
20
+ expect("CNNNews".snakecase).to eq("cnn_news")
21
+ expect("HeadlineCNNNews".snakecase).to eq("headline_cnn_news")
22
+ end
23
+
24
+ it "does NOT change one word lowercase" do
25
+ expect("merb".snakecase).to eq("merb")
26
+ end
27
+
28
+ it "leaves snake_case as is" do
29
+ expect("merb_core".snakecase).to eq("merb_core")
30
+ end
31
+
32
+ it "converts period characters to underscores" do
33
+ expect("User.GetEmail".snakecase).to eq("user_get_email")
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe Savon do
4
+
5
+ it 'knows the message tag for :authentication' do
6
+ message_tag = message_tag_for(:authentication, :authenticate)
7
+ expect(message_tag).to eq(['http://v1_0.ws.auth.order.example.com/', 'authenticate'])
8
+ end
9
+
10
+ it 'knows the message tag for :taxcloud' do
11
+ message_tag = message_tag_for(:taxcloud, :verify_address)
12
+ expect(message_tag).to eq(['http://taxcloud.net', 'VerifyAddress'])
13
+ end
14
+
15
+ it 'knows the message tag for :team_software' do
16
+ message_tag = message_tag_for(:team_software, :login)
17
+ expect(message_tag).to eq(['http://tempuri.org/', 'Login'])
18
+ end
19
+
20
+ it 'knows the message tag for :interhome' do
21
+ message_tag = message_tag_for(:interhome, :price_list)
22
+ expect(message_tag).to eq(['http://www.interhome.com/webservice', 'PriceList'])
23
+ end
24
+
25
+ it 'knows the message tag for :betfair' do
26
+ message_tag = message_tag_for(:betfair, :get_bet)
27
+ expect(message_tag).to eq(['http://www.betfair.com/publicapi/v5/BFExchangeService/', 'getBet'])
28
+ end
29
+
30
+ it 'knows the message tag for :vies' do
31
+ message_tag = message_tag_for(:vies, :check_vat)
32
+ expect(message_tag).to eq(['urn:ec.europa.eu:taxud:vies:services:checkVat:types', 'checkVat'])
33
+ end
34
+
35
+ it 'knows the message tag for :wasmuth' do
36
+ message_tag = message_tag_for(:wasmuth, :get_st_tables)
37
+ expect(message_tag).to eq(['http://ws.online.msw/', 'getStTables'])
38
+ end
39
+
40
+ def message_tag_for(fixture, operation_name)
41
+ globals = Savon::GlobalOptions.new(:log => false)
42
+ wsdl = Wasabi::Document.new Fixture.wsdl(fixture)
43
+ operation = Savon::Operation.create(operation_name, wsdl, globals)
44
+ request_xml = operation.build.to_s
45
+
46
+ nsid, local = extract_message_tag_from_request(request_xml)
47
+ namespace = extract_namespace_from_request(nsid, request_xml)
48
+
49
+ [namespace, local]
50
+ end
51
+
52
+ def extract_message_tag_from_request(xml)
53
+ match = xml.match(/<\w+?:Body><(.+?):(.+?)>/)
54
+ [ match[1], match[2] ]
55
+ end
56
+
57
+ def extract_namespace_from_request(nsid, xml)
58
+ xml.match(/xmlns:#{nsid}="(.+?)"/)[1]
59
+ end
60
+
61
+ end
@@ -0,0 +1,49 @@
1
+ require "spec_helper"
2
+
3
+ describe Savon::HTTPError do
4
+ let(:http_error) { Savon::HTTPError.new new_response(:code => 404, :body => "Not Found") }
5
+ let(:no_error) { Savon::HTTPError.new new_response }
6
+
7
+ it "inherits from Savon::Error" do
8
+ expect(Savon::HTTPError.ancestors).to include(Savon::Error)
9
+ end
10
+
11
+ describe ".present?" do
12
+ it "returns true if there was an HTTP error" do
13
+ http = new_response(:code => 404, :body => "Not Found")
14
+ expect(Savon::HTTPError.present? http).to be_truthy
15
+ end
16
+
17
+ it "returns false unless there was an HTTP error" do
18
+ expect(Savon::HTTPError.present? new_response).to be_falsey
19
+ end
20
+ end
21
+
22
+ describe "#http" do
23
+ it "returns the HTTPI::Response" do
24
+ expect(http_error.http).to be_a(HTTPI::Response)
25
+ end
26
+ end
27
+
28
+ [:message, :to_s].each do |method|
29
+ describe "##{method}" do
30
+ it "returns the HTTP error message" do
31
+ expect(http_error.send method).to eq("HTTP error (404): Not Found")
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "#to_hash" do
37
+ it "returns the HTTP response details as a Hash" do
38
+ expect(http_error.to_hash).to eq(:code => 404, :headers => {}, :body => "Not Found")
39
+ end
40
+ end
41
+
42
+ def new_response(options = {})
43
+ defaults = { :code => 200, :headers => {}, :body => Fixture.response(:authentication) }
44
+ response = defaults.merge options
45
+
46
+ HTTPI::Response.new response[:code], response[:headers], response[:body]
47
+ end
48
+
49
+ end
@@ -0,0 +1,44 @@
1
+ require "spec_helper"
2
+
3
+ describe Savon::LogMessage do
4
+
5
+ it "returns the message if it's not XML" do
6
+ message = log_message("hello", [:password], :pretty_print).to_s
7
+ expect(message).to eq("hello")
8
+ end
9
+
10
+ it "returns the message if it shouldn't be filtered or pretty printed" do
11
+ Nokogiri.expects(:XML).never
12
+
13
+ message = log_message("<hello/>", [], false).to_s
14
+ expect(message).to eq("<hello/>")
15
+ end
16
+
17
+ it "pretty prints a given message" do
18
+ message = log_message("<envelope><body>hello</body></envelope>", [], :pretty_print).to_s
19
+
20
+ expect(message).to include("\n<envelope>")
21
+ expect(message).to include("\n <body>")
22
+ end
23
+
24
+ it "filters tags in a given message" do
25
+ message = log_message("<root><password>secret</password></root>", [:password], false).to_s
26
+ expect(message).to include("<password>***FILTERED***</password>")
27
+ end
28
+
29
+ it "properly applies Proc filter" do
30
+ filter = Proc.new do |document|
31
+ document.xpath('//password').each do |node|
32
+ node.content = "FILTERED"
33
+ end
34
+ end
35
+
36
+ message = log_message("<root><password>secret</password></root>", [filter], false).to_s
37
+ expect(message).to include("<password>FILTERED</password>")
38
+ end
39
+
40
+ def log_message(*args)
41
+ Savon::LogMessage.new(*args)
42
+ end
43
+
44
+ end