wash_out 0.9.2 → 0.11.0
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +35 -4
- data/Appraisals +8 -12
- data/Gemfile +1 -1
- data/README.md +85 -7
- data/Rakefile +15 -5
- data/app/helpers/wash_out_helper.rb +59 -24
- data/app/views/{wash_with_soap → wash_out}/document/error.builder +0 -0
- data/app/views/{wash_with_soap → wash_out}/document/response.builder +7 -0
- data/app/views/{wash_with_soap → wash_out}/document/wsdl.builder +14 -14
- data/app/views/{wash_with_soap → wash_out}/rpc/error.builder +0 -0
- data/app/views/{wash_with_soap → wash_out}/rpc/response.builder +8 -1
- data/app/views/{wash_with_soap → wash_out}/rpc/wsdl.builder +15 -15
- data/gemfiles/rails_3.2.13.gemfile +21 -0
- data/gemfiles/rails_4.0.0.gemfile +20 -0
- data/gemfiles/rails_4.1.0.gemfile +20 -0
- data/gemfiles/rails_4.2.0.gemfile +20 -0
- data/gemfiles/rails_5.0.0.beta2.gemfile +19 -0
- data/gemfiles/rails_5.0.0.gemfile +19 -0
- data/lib/wash_out/dispatcher.rb +96 -39
- data/lib/wash_out/param.rb +14 -2
- data/lib/wash_out/router.rb +52 -22
- data/lib/wash_out/soap.rb +11 -0
- data/lib/wash_out/version.rb +1 -1
- data/lib/wash_out/wsse.rb +3 -3
- data/lib/wash_out.rb +32 -5
- data/spec/dummy/config/environments/test.rb +1 -0
- data/spec/fixtures/nested_refs_to_arrays.xml +19 -0
- data/spec/fixtures/ref_to_one_array.xml +11 -0
- data/spec/fixtures/refs_to_arrays.xml +16 -0
- data/spec/lib/wash_out/dispatcher_spec.rb +124 -17
- data/spec/lib/wash_out/middleware_spec.rb +8 -8
- data/spec/lib/wash_out/param_spec.rb +43 -11
- data/spec/lib/wash_out/router_spec.rb +33 -5
- data/spec/lib/wash_out/type_spec.rb +9 -9
- data/spec/lib/wash_out_spec.rb +361 -103
- data/spec/spec_helper.rb +26 -4
- metadata +18 -9
data/spec/lib/wash_out_spec.rb
CHANGED
@@ -12,35 +12,37 @@ describe WashOut do
|
|
12
12
|
)
|
13
13
|
end
|
14
14
|
|
15
|
-
def savon(method, message={}, &block)
|
15
|
+
def savon(method, message={}, hashify=true, &block)
|
16
16
|
message = {:value => message} unless message.is_a?(Hash)
|
17
17
|
|
18
|
-
savon
|
19
|
-
savon.call(method, :message => message)
|
18
|
+
savon = Savon::Client.new(:log => false, :wsdl => 'http://app/route/api/wsdl', &block)
|
19
|
+
result = savon.call(method, :message => message)
|
20
|
+
result = result.to_hash if hashify
|
21
|
+
result
|
20
22
|
end
|
21
23
|
|
22
24
|
def savon!(method, message={}, &block)
|
23
25
|
message = {:value => message} unless message.is_a?(Hash)
|
24
26
|
|
25
|
-
savon = Savon::Client.new(:log => true, :wsdl => 'http://app/api/wsdl', &block)
|
27
|
+
savon = Savon::Client.new(:log => true, :wsdl => 'http://app/route/api/wsdl', &block)
|
26
28
|
savon.call(method, :message => message).to_hash
|
27
29
|
end
|
28
30
|
|
29
31
|
describe "Module" do
|
30
32
|
it "includes" do
|
31
|
-
|
33
|
+
expect {
|
32
34
|
mock_controller do
|
33
35
|
# nothing
|
34
36
|
end
|
35
|
-
}.
|
37
|
+
}.not_to raise_exception
|
36
38
|
end
|
37
39
|
|
38
40
|
it "allows definition of a simple action" do
|
39
|
-
|
41
|
+
expect {
|
40
42
|
mock_controller do
|
41
43
|
soap_action "answer", :args => nil, :return => :integer
|
42
44
|
end
|
43
|
-
}.
|
45
|
+
}.not_to raise_exception
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
@@ -59,7 +61,7 @@ describe WashOut do
|
|
59
61
|
:return => { :circle2 => { :y => :integer } }
|
60
62
|
end
|
61
63
|
|
62
|
-
HTTPI.get("http://app/api/wsdl").body
|
64
|
+
HTTPI.get("http://app/route/api/wsdl").body
|
63
65
|
end
|
64
66
|
|
65
67
|
let :xml do
|
@@ -68,13 +70,13 @@ describe WashOut do
|
|
68
70
|
|
69
71
|
it "lists operations" do
|
70
72
|
operations = xml[:definitions][:binding][:operation]
|
71
|
-
operations.
|
73
|
+
expect(operations).to be_a_kind_of(Array)
|
72
74
|
|
73
|
-
operations.map{|e| e[:'@name']}.sort.
|
75
|
+
expect(operations.map{|e| e[:'@name']}.sort).to eq ['Result', 'getArea', 'rocky'].sort
|
74
76
|
end
|
75
77
|
|
76
78
|
it "defines complex types" do
|
77
|
-
wsdl.include?('<xsd:complexType name="Circle1">').
|
79
|
+
expect(wsdl.include?('<xsd:complexType name="Circle1">')).to be true
|
78
80
|
end
|
79
81
|
|
80
82
|
it "defines arrays" do
|
@@ -82,8 +84,15 @@ describe WashOut do
|
|
82
84
|
find{|x| x[:'@name'] == 'Center'}[:sequence][:element].
|
83
85
|
find{|x| x[:'@name'] == 'X'}
|
84
86
|
|
85
|
-
x[:'@min_occurs'].
|
86
|
-
x[:'@max_occurs'].
|
87
|
+
expect(x[:'@min_occurs']).to eq "0"
|
88
|
+
expect(x[:'@max_occurs']).to eq "unbounded"
|
89
|
+
expect(x[:'@nillable']).to eq "true"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "adds nillable to all type definitions" do
|
93
|
+
types = xml[:definitions][:message].map { |d| d[:part] }.compact
|
94
|
+
nillable = types.map { |t| t[:"@xsi:nillable"] }
|
95
|
+
expect(nillable.all? { |v| v == "true" }).to be true
|
87
96
|
end
|
88
97
|
end
|
89
98
|
|
@@ -109,7 +118,7 @@ describe WashOut do
|
|
109
118
|
</env:Envelope>
|
110
119
|
XML
|
111
120
|
|
112
|
-
HTTPI.post("http://app/api/action", request).body.
|
121
|
+
expect(HTTPI.post("http://app/route/api/action", request).body).to eq <<-XML
|
113
122
|
<?xml version="1.0" encoding="UTF-8"?>
|
114
123
|
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="false">
|
115
124
|
<soap:Body>
|
@@ -121,6 +130,37 @@ describe WashOut do
|
|
121
130
|
XML
|
122
131
|
end
|
123
132
|
|
133
|
+
it "accepts requests with no HTTP header with alias" do
|
134
|
+
mock_controller do
|
135
|
+
soap_action "answer", :as => 'whatever', :args => nil, :return => :int
|
136
|
+
def answer
|
137
|
+
render :soap => "42"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
request = <<-XML
|
142
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
143
|
+
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="false" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
|
144
|
+
<env:Body>
|
145
|
+
<tns:whatever>
|
146
|
+
<value>42</value>
|
147
|
+
</tns:whatever>
|
148
|
+
</env:Body>
|
149
|
+
</env:Envelope>
|
150
|
+
XML
|
151
|
+
|
152
|
+
expect(HTTPI.post("http://app/route/api/action", request).body).to eq <<-XML
|
153
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
154
|
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="false">
|
155
|
+
<soap:Body>
|
156
|
+
<tns:whateverResponse>
|
157
|
+
<Value xsi:type="xsd:int">42</Value>
|
158
|
+
</tns:whateverResponse>
|
159
|
+
</soap:Body>
|
160
|
+
</soap:Envelope>
|
161
|
+
XML
|
162
|
+
end
|
163
|
+
|
124
164
|
it "accept no parameters" do
|
125
165
|
mock_controller do
|
126
166
|
soap_action "answer", :args => nil, :return => :int
|
@@ -129,8 +169,8 @@ describe WashOut do
|
|
129
169
|
end
|
130
170
|
end
|
131
171
|
|
132
|
-
savon(:answer)[:answer_response][:value].
|
133
|
-
|
172
|
+
expect(savon(:answer)[:answer_response][:value]).
|
173
|
+
to eq "42"
|
134
174
|
end
|
135
175
|
|
136
176
|
it "accept insufficient parameters" do
|
@@ -141,8 +181,19 @@ describe WashOut do
|
|
141
181
|
end
|
142
182
|
end
|
143
183
|
|
144
|
-
savon(:answer)[:answer_response][:value].
|
145
|
-
|
184
|
+
expect(savon(:answer)[:answer_response][:value]).
|
185
|
+
to eq "42"
|
186
|
+
end
|
187
|
+
|
188
|
+
it "shows date in correct format" do
|
189
|
+
mock_controller do
|
190
|
+
soap_action "answer", :args => {}, :return => {:a => :date}
|
191
|
+
def answer
|
192
|
+
render :soap => {:a => DateTime.new(2000, 1, 1)}
|
193
|
+
end
|
194
|
+
end
|
195
|
+
result = Hash.from_xml savon(:answer, {}, false).http.body
|
196
|
+
expect(result['Envelope']['Body']['answerResponse']['A']).to eq '2000-01-01T00:00:00+00:00'
|
146
197
|
end
|
147
198
|
|
148
199
|
it "accept empty parameter" do
|
@@ -152,8 +203,7 @@ describe WashOut do
|
|
152
203
|
render :soap => {:a => params[:a]}
|
153
204
|
end
|
154
205
|
end
|
155
|
-
savon(:answer, :a => '')[:answer_response][:a].
|
156
|
-
should == {:"@xsi:type"=>"xsd:string"}
|
206
|
+
expect(savon(:answer, :a => '')[:answer_response][:a]).to be_nil
|
157
207
|
end
|
158
208
|
|
159
209
|
it "accept one parameter" do
|
@@ -164,8 +214,8 @@ describe WashOut do
|
|
164
214
|
end
|
165
215
|
end
|
166
216
|
|
167
|
-
savon(:check_answer, 42)[:check_answer_response][:value].
|
168
|
-
savon(:check_answer, 13)[:check_answer_response][:value].
|
217
|
+
expect(savon(:check_answer, 42)[:check_answer_response][:value]).to be true
|
218
|
+
expect(savon(:check_answer, 13)[:check_answer_response][:value]).to be false
|
169
219
|
end
|
170
220
|
|
171
221
|
it "accept two parameters" do
|
@@ -176,7 +226,7 @@ describe WashOut do
|
|
176
226
|
end
|
177
227
|
end
|
178
228
|
|
179
|
-
savon(:funky, :a => 42, :b => 'k')[:funky_response][:value].
|
229
|
+
expect(savon(:funky, :a => 42, :b => 'k')[:funky_response][:value]).to eq '420k'
|
180
230
|
end
|
181
231
|
end
|
182
232
|
|
@@ -199,8 +249,8 @@ describe WashOut do
|
|
199
249
|
message = { :circle => { :center => { :x => 3, :y => 4 },
|
200
250
|
:radius => 5 } }
|
201
251
|
|
202
|
-
savon(:get_area, message)[:get_area_response].
|
203
|
-
|
252
|
+
expect(savon(:get_area, message)[:get_area_response]).
|
253
|
+
to eq ({ :area => (Math::PI * 25).to_s, :distance_from_o => (5.0).to_s })
|
204
254
|
end
|
205
255
|
|
206
256
|
it "accept arrays" do
|
@@ -211,7 +261,7 @@ describe WashOut do
|
|
211
261
|
},
|
212
262
|
:return => nil
|
213
263
|
def rumba
|
214
|
-
params.
|
264
|
+
expect(params).to eq({"rumbas" => [1, 2, 3]})
|
215
265
|
render :soap => nil
|
216
266
|
end
|
217
267
|
end
|
@@ -227,7 +277,7 @@ describe WashOut do
|
|
227
277
|
},
|
228
278
|
:return => nil
|
229
279
|
def rumba
|
230
|
-
params.
|
280
|
+
expect(params).to eq({})
|
231
281
|
render :soap => nil
|
232
282
|
end
|
233
283
|
end
|
@@ -242,7 +292,7 @@ describe WashOut do
|
|
242
292
|
},
|
243
293
|
:return => nil
|
244
294
|
def rumba
|
245
|
-
params.
|
295
|
+
expect(params).to eq({"nested" => {}})
|
246
296
|
render :soap => nil
|
247
297
|
end
|
248
298
|
end
|
@@ -260,12 +310,12 @@ describe WashOut do
|
|
260
310
|
},
|
261
311
|
:return => nil
|
262
312
|
def rumba
|
263
|
-
params.
|
313
|
+
expect(params).to eq({
|
264
314
|
"rumbas" => [
|
265
315
|
{"zombies" => 'suck', "puppies" => 'rock'},
|
266
316
|
{"zombies" => 'slow', "puppies" => 'fast'}
|
267
317
|
]
|
268
|
-
}
|
318
|
+
})
|
269
319
|
render :soap => nil
|
270
320
|
end
|
271
321
|
end
|
@@ -292,8 +342,15 @@ describe WashOut do
|
|
292
342
|
end
|
293
343
|
end
|
294
344
|
|
295
|
-
savon(:gogogo)[:gogogo_response].
|
296
|
-
|
345
|
+
expect(savon(:gogogo)[:gogogo_response]).
|
346
|
+
to eq({
|
347
|
+
:zoo=>"zoo",
|
348
|
+
:boo=>{
|
349
|
+
:moo=>"moo",
|
350
|
+
:doo=>"doo",
|
351
|
+
:"@xsi:type"=>"tns:Boo"
|
352
|
+
}
|
353
|
+
})
|
297
354
|
end
|
298
355
|
|
299
356
|
it "respond with arrays" do
|
@@ -306,7 +363,9 @@ describe WashOut do
|
|
306
363
|
end
|
307
364
|
end
|
308
365
|
|
309
|
-
savon(:rumba)[:rumba_response].
|
366
|
+
expect(savon(:rumba)[:rumba_response]).to eq({
|
367
|
+
:value => ["1", "2", "3"]
|
368
|
+
})
|
310
369
|
end
|
311
370
|
|
312
371
|
it "respond with complex structures inside arrays" do
|
@@ -314,55 +373,57 @@ describe WashOut do
|
|
314
373
|
soap_action "rumba",
|
315
374
|
:args => nil,
|
316
375
|
:return => {
|
317
|
-
:rumbas => [{:zombies => :string, :puppies => :string}]
|
376
|
+
:rumbas => [{:@level => :integer, :zombies => :string, :puppies => :string}]
|
318
377
|
}
|
319
378
|
def rumba
|
320
379
|
render :soap =>
|
321
380
|
{:rumbas => [
|
322
|
-
{:zombies => "suck1", :puppies => "rock1" },
|
381
|
+
{:@level => 80, :zombies => "suck1", :puppies => "rock1" },
|
323
382
|
{:zombies => "suck2", :puppies => "rock2" }
|
324
383
|
]
|
325
384
|
}
|
326
385
|
end
|
327
386
|
end
|
328
387
|
|
329
|
-
savon(:rumba)[:rumba_response].
|
388
|
+
expect(savon(:rumba)[:rumba_response]).to eq({
|
330
389
|
:rumbas => [
|
331
|
-
{:zombies => "suck1",:puppies => "rock1", :"@xsi:type"=>"tns:Rumbas"},
|
390
|
+
{:zombies => "suck1",:puppies => "rock1", :"@xsi:type"=>"tns:Rumbas", :@level => "80"},
|
332
391
|
{:zombies => "suck2", :puppies => "rock2", :"@xsi:type"=>"tns:Rumbas" }
|
333
392
|
]
|
334
|
-
}
|
393
|
+
})
|
335
394
|
end
|
336
395
|
|
337
396
|
it "respond with structs in structs in arrays" do
|
338
397
|
mock_controller do
|
339
398
|
soap_action "rumba",
|
340
399
|
:args => nil,
|
341
|
-
:return => [{:rumbas => {:zombies => :integer}}]
|
400
|
+
:return => [{:rumbas => {:@level => :integer, :zombies => :integer}}]
|
342
401
|
|
343
402
|
def rumba
|
344
|
-
render :soap => [{:rumbas => {:zombies => 100000}}, {:rumbas => {:zombies => 2}}]
|
403
|
+
render :soap => [{:rumbas => {:@level => 80, :zombies => 100000}}, {:rumbas => {:@level => 90, :zombies => 2}}]
|
345
404
|
end
|
346
405
|
end
|
347
406
|
|
348
|
-
savon(:rumba)[:rumba_response].
|
407
|
+
expect(savon(:rumba)[:rumba_response]).to eq({
|
349
408
|
:value => [
|
350
409
|
{
|
351
410
|
:rumbas => {
|
352
411
|
:zombies => "100000",
|
353
|
-
:"@xsi:type" => "tns:Rumbas"
|
412
|
+
:"@xsi:type" => "tns:Rumbas",
|
413
|
+
:"@level" => "80"
|
354
414
|
},
|
355
415
|
:"@xsi:type" => "tns:Value"
|
356
416
|
},
|
357
417
|
{
|
358
418
|
:rumbas => {
|
359
419
|
:zombies => "2",
|
360
|
-
:"@xsi:type" => "tns:Rumbas"
|
420
|
+
:"@xsi:type" => "tns:Rumbas",
|
421
|
+
:@level => "90",
|
361
422
|
},
|
362
423
|
:"@xsi:type"=>"tns:Value"
|
363
424
|
}
|
364
425
|
]
|
365
|
-
}
|
426
|
+
})
|
366
427
|
end
|
367
428
|
|
368
429
|
context "with arrays missing" do
|
@@ -375,7 +436,7 @@ describe WashOut do
|
|
375
436
|
end
|
376
437
|
end
|
377
438
|
|
378
|
-
savon(:rocknroll)[:rocknroll_response].
|
439
|
+
expect(savon(:rocknroll)[:rocknroll_response]).to be nil
|
379
440
|
end
|
380
441
|
|
381
442
|
it "respond with complext definition" do
|
@@ -387,7 +448,7 @@ describe WashOut do
|
|
387
448
|
end
|
388
449
|
end
|
389
450
|
|
390
|
-
savon(:rocknroll)[:rocknroll_response].
|
451
|
+
expect(savon(:rocknroll)[:rocknroll_response]).to be nil
|
391
452
|
end
|
392
453
|
|
393
454
|
it "respond with nested simple definition" do
|
@@ -399,8 +460,20 @@ describe WashOut do
|
|
399
460
|
end
|
400
461
|
end
|
401
462
|
|
402
|
-
savon(:rocknroll)[:rocknroll_response][:my_value].
|
403
|
-
|
463
|
+
expect(savon(:rocknroll)[:rocknroll_response][:my_value]).to be_nil
|
464
|
+
end
|
465
|
+
|
466
|
+
it "responds with missing parameters" do
|
467
|
+
mock_controller do
|
468
|
+
soap_action "rocknroll",
|
469
|
+
args: nil,
|
470
|
+
return: {my_value: :integer}
|
471
|
+
def rocknroll
|
472
|
+
render soap: {my_value: nil}
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
476
|
+
expect(savon(:rocknroll)[:rocknroll_response][:my_value]).to be_nil
|
404
477
|
end
|
405
478
|
|
406
479
|
it "handles incomplete array response" do
|
@@ -417,18 +490,187 @@ describe WashOut do
|
|
417
490
|
end
|
418
491
|
end
|
419
492
|
|
493
|
+
context "SOAP header" do
|
494
|
+
it "accepts requests with a simple header" do
|
495
|
+
mock_controller do
|
496
|
+
soap_action "answer", :args => nil, :return => :int, :header_args => :string
|
497
|
+
def answer
|
498
|
+
render :soap => "42"
|
499
|
+
end
|
500
|
+
end
|
501
|
+
|
502
|
+
request = <<-XML
|
503
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
504
|
+
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="false" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
|
505
|
+
<env:Header>
|
506
|
+
<tns:Auth>
|
507
|
+
<value>12345</value>
|
508
|
+
</tns:Auth>
|
509
|
+
</env:Header>
|
510
|
+
<env:Body>
|
511
|
+
<tns:answer>
|
512
|
+
<value>42</value>
|
513
|
+
</tns:answer>
|
514
|
+
</env:Body>
|
515
|
+
</env:Envelope>
|
516
|
+
XML
|
517
|
+
|
518
|
+
expect(HTTPI.post("http://app/route/api/action", request).body).to eq <<-XML
|
519
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
520
|
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="false">
|
521
|
+
<soap:Body>
|
522
|
+
<tns:answerResponse>
|
523
|
+
<Value xsi:type="xsd:int">42</Value>
|
524
|
+
</tns:answerResponse>
|
525
|
+
</soap:Body>
|
526
|
+
</soap:Envelope>
|
527
|
+
XML
|
528
|
+
end
|
529
|
+
|
530
|
+
it "makes simple header values accessible" do
|
531
|
+
mock_controller do
|
532
|
+
soap_action "answer", :args => nil, :return => :int
|
533
|
+
def answer
|
534
|
+
expect(soap_request.headers).to eq({value: "12345"})
|
535
|
+
render :soap => "42"
|
536
|
+
end
|
537
|
+
end
|
538
|
+
|
539
|
+
request = <<-XML
|
540
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
541
|
+
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="false" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
|
542
|
+
<env:Header>
|
543
|
+
<value>12345</value>
|
544
|
+
</env:Header>
|
545
|
+
<env:Body>
|
546
|
+
<tns:answer>
|
547
|
+
<value>42</value>
|
548
|
+
</tns:answer>
|
549
|
+
</env:Body>
|
550
|
+
</env:Envelope>
|
551
|
+
XML
|
552
|
+
|
553
|
+
HTTPI.post("http://app/route/api/action", request)
|
554
|
+
|
555
|
+
end
|
556
|
+
|
557
|
+
it "makes complex header values accessible" do
|
558
|
+
mock_controller do
|
559
|
+
soap_action "answer", :args => nil, :return => :int
|
560
|
+
def answer
|
561
|
+
expect(soap_request.headers[:auth][:answer_response]).to eq "12345"
|
562
|
+
render :soap => "42"
|
563
|
+
end
|
564
|
+
end
|
565
|
+
|
566
|
+
request = <<-XML
|
567
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
568
|
+
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="false" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
|
569
|
+
<env:Header>
|
570
|
+
<Auth>
|
571
|
+
<AnswerResponse>12345</AnswerResponse>
|
572
|
+
</Auth>
|
573
|
+
</env:Header>
|
574
|
+
<env:Body>
|
575
|
+
<tns:answer>
|
576
|
+
<value>42</value>
|
577
|
+
</tns:answer>
|
578
|
+
</env:Body>
|
579
|
+
</env:Envelope>
|
580
|
+
XML
|
581
|
+
|
582
|
+
HTTPI.post("http://app/route/api/action", request)
|
583
|
+
|
584
|
+
end
|
585
|
+
|
586
|
+
it "renders a simple header if specified" do
|
587
|
+
mock_controller do
|
588
|
+
soap_action "answer", :args => nil, :return => :int, header_return: :string
|
589
|
+
def answer
|
590
|
+
render :soap => "42", :header => "12345"
|
591
|
+
end
|
592
|
+
end
|
593
|
+
|
594
|
+
|
595
|
+
request = <<-XML
|
596
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
597
|
+
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="false" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
|
598
|
+
<env:Body>
|
599
|
+
<tns:answer>
|
600
|
+
<value>42</value>
|
601
|
+
</tns:answer>
|
602
|
+
</env:Body>
|
603
|
+
</env:Envelope>
|
604
|
+
XML
|
605
|
+
|
606
|
+
expect(HTTPI.post("http://app/route/api/action", request).body).to eq <<-XML
|
607
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
608
|
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="false">
|
609
|
+
<soap:Header>
|
610
|
+
<tns:answerResponse>
|
611
|
+
<Value xsi:type="xsd:string">12345</Value>
|
612
|
+
</tns:answerResponse>
|
613
|
+
</soap:Header>
|
614
|
+
<soap:Body>
|
615
|
+
<tns:answerResponse>
|
616
|
+
<Value xsi:type="xsd:int">42</Value>
|
617
|
+
</tns:answerResponse>
|
618
|
+
</soap:Body>
|
619
|
+
</soap:Envelope>
|
620
|
+
XML
|
621
|
+
end
|
622
|
+
end
|
623
|
+
|
624
|
+
it "renders a complex header if specified" do
|
625
|
+
mock_controller do
|
626
|
+
soap_action "answer", :args => nil, :return => :int, header_return: {:"Auth" => :string}
|
627
|
+
def answer
|
628
|
+
render :soap => "42", :header => {Auth: "12345"}
|
629
|
+
end
|
630
|
+
end
|
631
|
+
|
632
|
+
|
633
|
+
request = <<-XML
|
634
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
635
|
+
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="false" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
|
636
|
+
<env:Body>
|
637
|
+
<tns:answer>
|
638
|
+
<value>42</value>
|
639
|
+
</tns:answer>
|
640
|
+
</env:Body>
|
641
|
+
</env:Envelope>
|
642
|
+
XML
|
643
|
+
|
644
|
+
expect(HTTPI.post("http://app/route/api/action", request).body).to eq <<-XML
|
645
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
646
|
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="false">
|
647
|
+
<soap:Header>
|
648
|
+
<tns:answerResponse>
|
649
|
+
<Auth xsi:type="xsd:string">12345</Auth>
|
650
|
+
</tns:answerResponse>
|
651
|
+
</soap:Header>
|
652
|
+
<soap:Body>
|
653
|
+
<tns:answerResponse>
|
654
|
+
<Value xsi:type="xsd:int">42</Value>
|
655
|
+
</tns:answerResponse>
|
656
|
+
</soap:Body>
|
657
|
+
</soap:Envelope>
|
658
|
+
XML
|
659
|
+
end
|
660
|
+
|
661
|
+
|
420
662
|
context "types" do
|
421
663
|
it "recognize boolean" do
|
422
664
|
mock_controller do
|
423
665
|
soap_action "true", :args => :boolean, :return => :nil
|
424
666
|
def true
|
425
|
-
params[:value].
|
667
|
+
expect(params[:value]).to be true
|
426
668
|
render :soap => nil
|
427
669
|
end
|
428
670
|
|
429
671
|
soap_action "false", :args => :boolean, :return => :nil
|
430
672
|
def false
|
431
|
-
params[:value].
|
673
|
+
expect(params[:value]).to be false
|
432
674
|
render :soap => nil
|
433
675
|
end
|
434
676
|
end
|
@@ -443,26 +685,26 @@ describe WashOut do
|
|
443
685
|
mock_controller do
|
444
686
|
soap_action "date", :args => :date, :return => :nil
|
445
687
|
def date
|
446
|
-
params[:value].
|
688
|
+
expect(params[:value]).to eq Date.parse('2000-12-30') unless params[:value].blank?
|
447
689
|
render :soap => nil
|
448
690
|
end
|
449
691
|
end
|
450
692
|
|
451
693
|
savon(:date, :value => '2000-12-30')
|
452
|
-
|
694
|
+
expect { savon(:date) }.not_to raise_exception
|
453
695
|
end
|
454
696
|
|
455
697
|
it "recognize base64Binary" do
|
456
698
|
mock_controller do
|
457
699
|
soap_action "base64", :args => :base64Binary, :return => :nil
|
458
700
|
def base64
|
459
|
-
params[:value].
|
701
|
+
expect(params[:value]).to eq('test') unless params[:value].blank?
|
460
702
|
render :soap => nil
|
461
703
|
end
|
462
704
|
end
|
463
705
|
|
464
706
|
savon(:base64, :value => Base64.encode64('test'))
|
465
|
-
|
707
|
+
expect { savon(:base64) }.not_to raise_exception
|
466
708
|
end
|
467
709
|
end
|
468
710
|
|
@@ -477,9 +719,9 @@ describe WashOut do
|
|
477
719
|
end
|
478
720
|
end
|
479
721
|
|
480
|
-
|
722
|
+
expect {
|
481
723
|
savon(:duty, :bad => 42, :good => nil)
|
482
|
-
}.
|
724
|
+
}.to raise_exception(Savon::SOAPFault)
|
483
725
|
end
|
484
726
|
|
485
727
|
it "raise for date in incorrect format" do
|
@@ -489,9 +731,9 @@ describe WashOut do
|
|
489
731
|
render :soap => nil
|
490
732
|
end
|
491
733
|
end
|
492
|
-
|
734
|
+
expect {
|
493
735
|
savon(:date, :value => 'incorrect format')
|
494
|
-
}.
|
736
|
+
}.to raise_exception(Savon::SOAPFault)
|
495
737
|
end
|
496
738
|
|
497
739
|
it "raise to report SOAP errors" do
|
@@ -503,8 +745,8 @@ describe WashOut do
|
|
503
745
|
end
|
504
746
|
end
|
505
747
|
|
506
|
-
|
507
|
-
|
748
|
+
expect { savon(:error, :need_error => false) }.not_to raise_exception
|
749
|
+
expect { savon(:error, :need_error => true) }.to raise_exception(Savon::SOAPFault)
|
508
750
|
end
|
509
751
|
|
510
752
|
it "misses basic exceptions" do
|
@@ -516,8 +758,8 @@ describe WashOut do
|
|
516
758
|
end
|
517
759
|
end
|
518
760
|
|
519
|
-
|
520
|
-
|
761
|
+
expect { savon(:error, :need_error => false) }.not_to raise_exception
|
762
|
+
expect { savon(:error, :need_error => true) }.to raise_exception(Exception)
|
521
763
|
end
|
522
764
|
|
523
765
|
it "raise for manual throws" do
|
@@ -528,7 +770,7 @@ describe WashOut do
|
|
528
770
|
end
|
529
771
|
end
|
530
772
|
|
531
|
-
|
773
|
+
expect { savon(:error) }.to raise_exception(Savon::SOAPFault)
|
532
774
|
end
|
533
775
|
|
534
776
|
it "raise when response structure mismatches" do
|
@@ -561,12 +803,12 @@ describe WashOut do
|
|
561
803
|
end
|
562
804
|
end
|
563
805
|
|
564
|
-
|
806
|
+
expect { savon(:bad) }.to raise_exception(
|
565
807
|
WashOut::Dispatcher::ProgrammerError,
|
566
808
|
/SOAP response .*wyldness.*Array.*Hash.*stallion/
|
567
809
|
)
|
568
810
|
|
569
|
-
|
811
|
+
expect { savon(:bad2) }.to raise_exception(
|
570
812
|
WashOut::Dispatcher::ProgrammerError,
|
571
813
|
/SOAP response .*oops.*String.*telephone_booths.*Array/
|
572
814
|
)
|
@@ -574,11 +816,14 @@ describe WashOut do
|
|
574
816
|
end
|
575
817
|
|
576
818
|
context "deprecates" do
|
577
|
-
|
819
|
+
# This test uses deprecated rspec expectations
|
820
|
+
# and it's not clear how to rewrite it.
|
821
|
+
xit "old syntax" do
|
578
822
|
# save rspec context check
|
579
823
|
raise_runtime_exception = raise_exception(RuntimeError)
|
580
824
|
|
581
825
|
mock_controller do
|
826
|
+
|
582
827
|
lambda {
|
583
828
|
soap_action "rumba",
|
584
829
|
:args => :integer,
|
@@ -601,8 +846,7 @@ describe WashOut do
|
|
601
846
|
end
|
602
847
|
end
|
603
848
|
|
604
|
-
savon(name.underscore.to_sym)["#{name.underscore}_response".to_sym][:value].
|
605
|
-
should == "forty two"
|
849
|
+
expect(savon(name.underscore.to_sym)["#{name.underscore}_response".to_sym][:value]).to eq "forty two"
|
606
850
|
end
|
607
851
|
|
608
852
|
it "respects :response_tag option" do
|
@@ -613,31 +857,45 @@ describe WashOut do
|
|
613
857
|
end
|
614
858
|
end
|
615
859
|
|
616
|
-
savon(:specific).
|
860
|
+
expect(savon(:specific)).to eq({:test => {:value=>"test"}})
|
617
861
|
end
|
618
862
|
|
619
863
|
it "handles snakecase option properly" do
|
620
864
|
mock_controller(snakecase_input: false, camelize_wsdl: false) do
|
621
865
|
soap_action "rocknroll", :args => {:ZOMG => :string}, :return => nil
|
622
866
|
def rocknroll
|
623
|
-
params["ZOMG"].
|
867
|
+
expect(params["ZOMG"]).to eq "yam!"
|
624
868
|
render :soap => nil
|
625
869
|
end
|
626
870
|
end
|
627
871
|
|
628
872
|
savon(:rocknroll, "ZOMG" => 'yam!')
|
629
873
|
end
|
874
|
+
end
|
875
|
+
|
876
|
+
describe "Router" do
|
877
|
+
it "raises when SOAP message without SOAP Envelope arrives" do
|
878
|
+
mock_controller do; end
|
879
|
+
invalid_request = '<a></a>'
|
880
|
+
response_hash = Nori.new.parse(HTTPI.post("http://app/route/api/action", invalid_request).body)
|
881
|
+
expect(response_hash["soap:Envelope"]["soap:Body"]["soap:Fault"]['faultstring']).to eq "Invalid SOAP request"
|
882
|
+
end
|
630
883
|
|
884
|
+
it "raises when SOAP message without SOAP Body arrives" do
|
885
|
+
mock_controller do; end
|
886
|
+
invalid_request = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"></s:Envelope>'
|
887
|
+
response_hash = Nori.new.parse(HTTPI.post("http://app/route/api/action", invalid_request).body)
|
888
|
+
expect(response_hash["soap:Envelope"]["soap:Body"]["soap:Fault"]['faultstring']).to eq "Invalid SOAP request"
|
889
|
+
end
|
631
890
|
end
|
632
891
|
|
633
892
|
describe "WS Security" do
|
634
|
-
|
635
893
|
it "appends username_token to params" do
|
636
894
|
mock_controller(wsse_username: "gorilla", wsse_password: "secret") do
|
637
895
|
soap_action "checkToken", :args => :integer, :return => nil, :to => 'check_token'
|
638
896
|
def check_token
|
639
|
-
request.env['WSSE_TOKEN']['username'].
|
640
|
-
request.env['WSSE_TOKEN']['password'].
|
897
|
+
expect(request.env['WSSE_TOKEN']['username']).to eq "gorilla"
|
898
|
+
expect(request.env['WSSE_TOKEN']['password']).to eq "secret"
|
641
899
|
render :soap => nil
|
642
900
|
end
|
643
901
|
end
|
@@ -656,20 +914,20 @@ describe WashOut do
|
|
656
914
|
end
|
657
915
|
|
658
916
|
# correct auth
|
659
|
-
|
660
|
-
|
917
|
+
expect { savon(:check_auth, 42){ wsse_auth "gorilla", "secret" } }.
|
918
|
+
not_to raise_exception
|
661
919
|
|
662
920
|
# wrong user
|
663
|
-
|
664
|
-
|
921
|
+
expect { savon(:check_auth, 42){ wsse_auth "chimpanzee", "secret" } }.
|
922
|
+
to raise_exception(Savon::SOAPFault)
|
665
923
|
|
666
924
|
# wrong pass
|
667
|
-
|
668
|
-
|
925
|
+
expect { savon(:check_auth, 42){ wsse_auth "gorilla", "nicetry" } }.
|
926
|
+
to raise_exception(Savon::SOAPFault)
|
669
927
|
|
670
928
|
# no auth
|
671
|
-
|
672
|
-
|
929
|
+
expect { savon(:check_auth, 42) }.
|
930
|
+
to raise_exception(Savon::SOAPFault)
|
673
931
|
end
|
674
932
|
|
675
933
|
it "handles PasswordDigest auth" do
|
@@ -681,30 +939,30 @@ describe WashOut do
|
|
681
939
|
end
|
682
940
|
|
683
941
|
# correct auth
|
684
|
-
|
685
|
-
|
942
|
+
expect { savon(:check_auth, 42){ wsse_auth "gorilla", "secret" } }.
|
943
|
+
not_to raise_exception
|
686
944
|
|
687
945
|
# correct digest auth
|
688
|
-
|
689
|
-
|
946
|
+
expect { savon(:check_auth, 42){ wsse_auth "gorilla", "secret", :digest } }.
|
947
|
+
not_to raise_exception
|
690
948
|
|
691
949
|
# wrong user
|
692
|
-
|
693
|
-
|
950
|
+
expect { savon(:check_auth, 42){ wsse_auth "chimpanzee", "secret", :digest } }.
|
951
|
+
to raise_exception(Savon::SOAPFault)
|
694
952
|
|
695
953
|
# wrong pass
|
696
|
-
|
697
|
-
|
954
|
+
expect { savon(:check_auth, 42){ wsse_auth "gorilla", "nicetry", :digest } }.
|
955
|
+
to raise_exception(Savon::SOAPFault)
|
698
956
|
|
699
957
|
# no auth
|
700
|
-
|
701
|
-
|
958
|
+
expect { savon(:check_auth, 42) }.
|
959
|
+
to raise_exception(Savon::SOAPFault)
|
702
960
|
end
|
703
961
|
|
704
962
|
it "handles auth callback" do
|
705
963
|
mock_controller(
|
706
964
|
wsse_auth_callback: lambda {|user, password|
|
707
|
-
return user == "gorilla" && password == "secret"
|
965
|
+
return user == "gorilla" && password == "secret"
|
708
966
|
}
|
709
967
|
) do
|
710
968
|
soap_action "checkAuth", :args => :integer, :return => :boolean, :to => 'check_auth'
|
@@ -714,24 +972,24 @@ describe WashOut do
|
|
714
972
|
end
|
715
973
|
|
716
974
|
# correct auth
|
717
|
-
|
718
|
-
|
975
|
+
expect { savon(:check_auth, 42){ wsse_auth "gorilla", "secret" } }.
|
976
|
+
not_to raise_exception
|
719
977
|
|
720
978
|
# correct digest auth
|
721
|
-
|
722
|
-
|
979
|
+
expect { savon(:check_auth, 42){ wsse_auth "gorilla", "secret", :digest } }.
|
980
|
+
to raise_exception(Savon::SOAPFault)
|
723
981
|
|
724
982
|
# wrong user
|
725
|
-
|
726
|
-
|
983
|
+
expect { savon(:check_auth, 42){ wsse_auth "chimpanzee", "secret", :digest } }.
|
984
|
+
to raise_exception(Savon::SOAPFault)
|
727
985
|
|
728
986
|
# wrong pass
|
729
|
-
|
730
|
-
|
987
|
+
expect { savon(:check_auth, 42){ wsse_auth "gorilla", "nicetry", :digest } }.
|
988
|
+
to raise_exception(Savon::SOAPFault)
|
731
989
|
|
732
990
|
# no auth
|
733
|
-
|
734
|
-
|
991
|
+
expect { savon(:check_auth, 42) }.
|
992
|
+
to raise_exception(Savon::SOAPFault)
|
735
993
|
end
|
736
994
|
|
737
995
|
end
|