wash_out 0.9.2 → 0.11.0.beta.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +31 -4
- data/Appraisals +11 -10
- data/Gemfile +1 -1
- data/README.md +41 -7
- data/Rakefile +6 -7
- 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 +0 -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 +0 -0
- 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/lib/wash_out/dispatcher.rb +68 -38
- data/lib/wash_out/param.rb +14 -2
- data/lib/wash_out/router.rb +40 -21
- data/lib/wash_out/soap.rb +1 -0
- data/lib/wash_out/version.rb +1 -1
- data/lib/wash_out/wsse.rb +3 -3
- data/lib/wash_out.rb +17 -4
- 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 +160 -102
- data/spec/spec_helper.rb +24 -4
- metadata +19 -11
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>
|
@@ -129,8 +138,8 @@ describe WashOut do
|
|
129
138
|
end
|
130
139
|
end
|
131
140
|
|
132
|
-
savon(:answer)[:answer_response][:value].
|
133
|
-
|
141
|
+
expect(savon(:answer)[:answer_response][:value]).
|
142
|
+
to eq "42"
|
134
143
|
end
|
135
144
|
|
136
145
|
it "accept insufficient parameters" do
|
@@ -141,8 +150,19 @@ describe WashOut do
|
|
141
150
|
end
|
142
151
|
end
|
143
152
|
|
144
|
-
savon(:answer)[:answer_response][:value].
|
145
|
-
|
153
|
+
expect(savon(:answer)[:answer_response][:value]).
|
154
|
+
to eq "42"
|
155
|
+
end
|
156
|
+
|
157
|
+
it "shows date in correct format" do
|
158
|
+
mock_controller do
|
159
|
+
soap_action "answer", :args => {}, :return => {:a => :date}
|
160
|
+
def answer
|
161
|
+
render :soap => {:a => DateTime.new(2000, 1, 1)}
|
162
|
+
end
|
163
|
+
end
|
164
|
+
result = Hash.from_xml savon(:answer, {}, false).http.body
|
165
|
+
expect(result['Envelope']['Body']['answerResponse']['A']).to eq '2000-01-01T00:00:00+00:00'
|
146
166
|
end
|
147
167
|
|
148
168
|
it "accept empty parameter" do
|
@@ -152,8 +172,7 @@ describe WashOut do
|
|
152
172
|
render :soap => {:a => params[:a]}
|
153
173
|
end
|
154
174
|
end
|
155
|
-
savon(:answer, :a => '')[:answer_response][:a].
|
156
|
-
should == {:"@xsi:type"=>"xsd:string"}
|
175
|
+
expect(savon(:answer, :a => '')[:answer_response][:a]).to be_nil
|
157
176
|
end
|
158
177
|
|
159
178
|
it "accept one parameter" do
|
@@ -164,8 +183,8 @@ describe WashOut do
|
|
164
183
|
end
|
165
184
|
end
|
166
185
|
|
167
|
-
savon(:check_answer, 42)[:check_answer_response][:value].
|
168
|
-
savon(:check_answer, 13)[:check_answer_response][:value].
|
186
|
+
expect(savon(:check_answer, 42)[:check_answer_response][:value]).to be true
|
187
|
+
expect(savon(:check_answer, 13)[:check_answer_response][:value]).to be false
|
169
188
|
end
|
170
189
|
|
171
190
|
it "accept two parameters" do
|
@@ -176,7 +195,7 @@ describe WashOut do
|
|
176
195
|
end
|
177
196
|
end
|
178
197
|
|
179
|
-
savon(:funky, :a => 42, :b => 'k')[:funky_response][:value].
|
198
|
+
expect(savon(:funky, :a => 42, :b => 'k')[:funky_response][:value]).to eq '420k'
|
180
199
|
end
|
181
200
|
end
|
182
201
|
|
@@ -199,8 +218,8 @@ describe WashOut do
|
|
199
218
|
message = { :circle => { :center => { :x => 3, :y => 4 },
|
200
219
|
:radius => 5 } }
|
201
220
|
|
202
|
-
savon(:get_area, message)[:get_area_response].
|
203
|
-
|
221
|
+
expect(savon(:get_area, message)[:get_area_response]).
|
222
|
+
to eq ({ :area => (Math::PI * 25).to_s, :distance_from_o => (5.0).to_s })
|
204
223
|
end
|
205
224
|
|
206
225
|
it "accept arrays" do
|
@@ -211,7 +230,7 @@ describe WashOut do
|
|
211
230
|
},
|
212
231
|
:return => nil
|
213
232
|
def rumba
|
214
|
-
params.
|
233
|
+
expect(params).to eq({"rumbas" => [1, 2, 3]})
|
215
234
|
render :soap => nil
|
216
235
|
end
|
217
236
|
end
|
@@ -227,7 +246,7 @@ describe WashOut do
|
|
227
246
|
},
|
228
247
|
:return => nil
|
229
248
|
def rumba
|
230
|
-
params.
|
249
|
+
expect(params).to eq({})
|
231
250
|
render :soap => nil
|
232
251
|
end
|
233
252
|
end
|
@@ -242,7 +261,7 @@ describe WashOut do
|
|
242
261
|
},
|
243
262
|
:return => nil
|
244
263
|
def rumba
|
245
|
-
params.
|
264
|
+
expect(params).to eq({"nested" => {}})
|
246
265
|
render :soap => nil
|
247
266
|
end
|
248
267
|
end
|
@@ -260,12 +279,12 @@ describe WashOut do
|
|
260
279
|
},
|
261
280
|
:return => nil
|
262
281
|
def rumba
|
263
|
-
params.
|
282
|
+
expect(params).to eq({
|
264
283
|
"rumbas" => [
|
265
284
|
{"zombies" => 'suck', "puppies" => 'rock'},
|
266
285
|
{"zombies" => 'slow', "puppies" => 'fast'}
|
267
286
|
]
|
268
|
-
}
|
287
|
+
})
|
269
288
|
render :soap => nil
|
270
289
|
end
|
271
290
|
end
|
@@ -292,8 +311,15 @@ describe WashOut do
|
|
292
311
|
end
|
293
312
|
end
|
294
313
|
|
295
|
-
savon(:gogogo)[:gogogo_response].
|
296
|
-
|
314
|
+
expect(savon(:gogogo)[:gogogo_response]).
|
315
|
+
to eq({
|
316
|
+
:zoo=>"zoo",
|
317
|
+
:boo=>{
|
318
|
+
:moo=>"moo",
|
319
|
+
:doo=>"doo",
|
320
|
+
:"@xsi:type"=>"tns:Boo"
|
321
|
+
}
|
322
|
+
})
|
297
323
|
end
|
298
324
|
|
299
325
|
it "respond with arrays" do
|
@@ -306,7 +332,9 @@ describe WashOut do
|
|
306
332
|
end
|
307
333
|
end
|
308
334
|
|
309
|
-
savon(:rumba)[:rumba_response].
|
335
|
+
expect(savon(:rumba)[:rumba_response]).to eq({
|
336
|
+
:value => ["1", "2", "3"]
|
337
|
+
})
|
310
338
|
end
|
311
339
|
|
312
340
|
it "respond with complex structures inside arrays" do
|
@@ -314,55 +342,57 @@ describe WashOut do
|
|
314
342
|
soap_action "rumba",
|
315
343
|
:args => nil,
|
316
344
|
:return => {
|
317
|
-
:rumbas => [{:zombies => :string, :puppies => :string}]
|
345
|
+
:rumbas => [{:@level => :integer, :zombies => :string, :puppies => :string}]
|
318
346
|
}
|
319
347
|
def rumba
|
320
348
|
render :soap =>
|
321
349
|
{:rumbas => [
|
322
|
-
{:zombies => "suck1", :puppies => "rock1" },
|
350
|
+
{:@level => 80, :zombies => "suck1", :puppies => "rock1" },
|
323
351
|
{:zombies => "suck2", :puppies => "rock2" }
|
324
352
|
]
|
325
353
|
}
|
326
354
|
end
|
327
355
|
end
|
328
356
|
|
329
|
-
savon(:rumba)[:rumba_response].
|
357
|
+
expect(savon(:rumba)[:rumba_response]).to eq({
|
330
358
|
:rumbas => [
|
331
|
-
{:zombies => "suck1",:puppies => "rock1", :"@xsi:type"=>"tns:Rumbas"},
|
359
|
+
{:zombies => "suck1",:puppies => "rock1", :"@xsi:type"=>"tns:Rumbas", :@level => "80"},
|
332
360
|
{:zombies => "suck2", :puppies => "rock2", :"@xsi:type"=>"tns:Rumbas" }
|
333
361
|
]
|
334
|
-
}
|
362
|
+
})
|
335
363
|
end
|
336
364
|
|
337
365
|
it "respond with structs in structs in arrays" do
|
338
366
|
mock_controller do
|
339
367
|
soap_action "rumba",
|
340
368
|
:args => nil,
|
341
|
-
:return => [{:rumbas => {:zombies => :integer}}]
|
369
|
+
:return => [{:rumbas => {:@level => :integer, :zombies => :integer}}]
|
342
370
|
|
343
371
|
def rumba
|
344
|
-
render :soap => [{:rumbas => {:zombies => 100000}}, {:rumbas => {:zombies => 2}}]
|
372
|
+
render :soap => [{:rumbas => {:@level => 80, :zombies => 100000}}, {:rumbas => {:@level => 90, :zombies => 2}}]
|
345
373
|
end
|
346
374
|
end
|
347
375
|
|
348
|
-
savon(:rumba)[:rumba_response].
|
376
|
+
expect(savon(:rumba)[:rumba_response]).to eq({
|
349
377
|
:value => [
|
350
378
|
{
|
351
379
|
:rumbas => {
|
352
380
|
:zombies => "100000",
|
353
|
-
:"@xsi:type" => "tns:Rumbas"
|
381
|
+
:"@xsi:type" => "tns:Rumbas",
|
382
|
+
:"@level" => "80"
|
354
383
|
},
|
355
384
|
:"@xsi:type" => "tns:Value"
|
356
385
|
},
|
357
386
|
{
|
358
387
|
:rumbas => {
|
359
388
|
:zombies => "2",
|
360
|
-
:"@xsi:type" => "tns:Rumbas"
|
389
|
+
:"@xsi:type" => "tns:Rumbas",
|
390
|
+
:@level => "90",
|
361
391
|
},
|
362
392
|
:"@xsi:type"=>"tns:Value"
|
363
393
|
}
|
364
394
|
]
|
365
|
-
}
|
395
|
+
})
|
366
396
|
end
|
367
397
|
|
368
398
|
context "with arrays missing" do
|
@@ -375,7 +405,7 @@ describe WashOut do
|
|
375
405
|
end
|
376
406
|
end
|
377
407
|
|
378
|
-
savon(:rocknroll)[:rocknroll_response].
|
408
|
+
expect(savon(:rocknroll)[:rocknroll_response]).to be nil
|
379
409
|
end
|
380
410
|
|
381
411
|
it "respond with complext definition" do
|
@@ -387,7 +417,7 @@ describe WashOut do
|
|
387
417
|
end
|
388
418
|
end
|
389
419
|
|
390
|
-
savon(:rocknroll)[:rocknroll_response].
|
420
|
+
expect(savon(:rocknroll)[:rocknroll_response]).to be nil
|
391
421
|
end
|
392
422
|
|
393
423
|
it "respond with nested simple definition" do
|
@@ -399,8 +429,20 @@ describe WashOut do
|
|
399
429
|
end
|
400
430
|
end
|
401
431
|
|
402
|
-
savon(:rocknroll)[:rocknroll_response][:my_value].
|
403
|
-
|
432
|
+
expect(savon(:rocknroll)[:rocknroll_response][:my_value]).to be_nil
|
433
|
+
end
|
434
|
+
|
435
|
+
it "responds with missing parameters" do
|
436
|
+
mock_controller do
|
437
|
+
soap_action "rocknroll",
|
438
|
+
args: nil,
|
439
|
+
return: {my_value: :integer}
|
440
|
+
def rocknroll
|
441
|
+
render soap: {my_value: nil}
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
expect(savon(:rocknroll)[:rocknroll_response][:my_value]).to be_nil
|
404
446
|
end
|
405
447
|
|
406
448
|
it "handles incomplete array response" do
|
@@ -422,13 +464,13 @@ describe WashOut do
|
|
422
464
|
mock_controller do
|
423
465
|
soap_action "true", :args => :boolean, :return => :nil
|
424
466
|
def true
|
425
|
-
params[:value].
|
467
|
+
expect(params[:value]).to be true
|
426
468
|
render :soap => nil
|
427
469
|
end
|
428
470
|
|
429
471
|
soap_action "false", :args => :boolean, :return => :nil
|
430
472
|
def false
|
431
|
-
params[:value].
|
473
|
+
expect(params[:value]).to be false
|
432
474
|
render :soap => nil
|
433
475
|
end
|
434
476
|
end
|
@@ -443,26 +485,26 @@ describe WashOut do
|
|
443
485
|
mock_controller do
|
444
486
|
soap_action "date", :args => :date, :return => :nil
|
445
487
|
def date
|
446
|
-
params[:value].
|
488
|
+
expect(params[:value]).to eq Date.parse('2000-12-30') unless params[:value].blank?
|
447
489
|
render :soap => nil
|
448
490
|
end
|
449
491
|
end
|
450
492
|
|
451
493
|
savon(:date, :value => '2000-12-30')
|
452
|
-
|
494
|
+
expect { savon(:date) }.not_to raise_exception
|
453
495
|
end
|
454
496
|
|
455
497
|
it "recognize base64Binary" do
|
456
498
|
mock_controller do
|
457
499
|
soap_action "base64", :args => :base64Binary, :return => :nil
|
458
500
|
def base64
|
459
|
-
params[:value].
|
501
|
+
expect(params[:value]).to eq('test') unless params[:value].blank?
|
460
502
|
render :soap => nil
|
461
503
|
end
|
462
504
|
end
|
463
505
|
|
464
506
|
savon(:base64, :value => Base64.encode64('test'))
|
465
|
-
|
507
|
+
expect { savon(:base64) }.not_to raise_exception
|
466
508
|
end
|
467
509
|
end
|
468
510
|
|
@@ -477,9 +519,9 @@ describe WashOut do
|
|
477
519
|
end
|
478
520
|
end
|
479
521
|
|
480
|
-
|
522
|
+
expect {
|
481
523
|
savon(:duty, :bad => 42, :good => nil)
|
482
|
-
}.
|
524
|
+
}.to raise_exception(Savon::SOAPFault)
|
483
525
|
end
|
484
526
|
|
485
527
|
it "raise for date in incorrect format" do
|
@@ -489,9 +531,9 @@ describe WashOut do
|
|
489
531
|
render :soap => nil
|
490
532
|
end
|
491
533
|
end
|
492
|
-
|
534
|
+
expect {
|
493
535
|
savon(:date, :value => 'incorrect format')
|
494
|
-
}.
|
536
|
+
}.to raise_exception(Savon::SOAPFault)
|
495
537
|
end
|
496
538
|
|
497
539
|
it "raise to report SOAP errors" do
|
@@ -503,8 +545,8 @@ describe WashOut do
|
|
503
545
|
end
|
504
546
|
end
|
505
547
|
|
506
|
-
|
507
|
-
|
548
|
+
expect { savon(:error, :need_error => false) }.not_to raise_exception
|
549
|
+
expect { savon(:error, :need_error => true) }.to raise_exception(Savon::SOAPFault)
|
508
550
|
end
|
509
551
|
|
510
552
|
it "misses basic exceptions" do
|
@@ -516,8 +558,8 @@ describe WashOut do
|
|
516
558
|
end
|
517
559
|
end
|
518
560
|
|
519
|
-
|
520
|
-
|
561
|
+
expect { savon(:error, :need_error => false) }.not_to raise_exception
|
562
|
+
expect { savon(:error, :need_error => true) }.to raise_exception(Exception)
|
521
563
|
end
|
522
564
|
|
523
565
|
it "raise for manual throws" do
|
@@ -528,7 +570,7 @@ describe WashOut do
|
|
528
570
|
end
|
529
571
|
end
|
530
572
|
|
531
|
-
|
573
|
+
expect { savon(:error) }.to raise_exception(Savon::SOAPFault)
|
532
574
|
end
|
533
575
|
|
534
576
|
it "raise when response structure mismatches" do
|
@@ -561,12 +603,12 @@ describe WashOut do
|
|
561
603
|
end
|
562
604
|
end
|
563
605
|
|
564
|
-
|
606
|
+
expect { savon(:bad) }.to raise_exception(
|
565
607
|
WashOut::Dispatcher::ProgrammerError,
|
566
608
|
/SOAP response .*wyldness.*Array.*Hash.*stallion/
|
567
609
|
)
|
568
610
|
|
569
|
-
|
611
|
+
expect { savon(:bad2) }.to raise_exception(
|
570
612
|
WashOut::Dispatcher::ProgrammerError,
|
571
613
|
/SOAP response .*oops.*String.*telephone_booths.*Array/
|
572
614
|
)
|
@@ -574,11 +616,14 @@ describe WashOut do
|
|
574
616
|
end
|
575
617
|
|
576
618
|
context "deprecates" do
|
577
|
-
|
619
|
+
# This test uses deprecated rspec expectations
|
620
|
+
# and it's not clear how to rewrite it.
|
621
|
+
xit "old syntax" do
|
578
622
|
# save rspec context check
|
579
623
|
raise_runtime_exception = raise_exception(RuntimeError)
|
580
624
|
|
581
625
|
mock_controller do
|
626
|
+
|
582
627
|
lambda {
|
583
628
|
soap_action "rumba",
|
584
629
|
:args => :integer,
|
@@ -601,8 +646,7 @@ describe WashOut do
|
|
601
646
|
end
|
602
647
|
end
|
603
648
|
|
604
|
-
savon(name.underscore.to_sym)["#{name.underscore}_response".to_sym][:value].
|
605
|
-
should == "forty two"
|
649
|
+
expect(savon(name.underscore.to_sym)["#{name.underscore}_response".to_sym][:value]).to eq "forty two"
|
606
650
|
end
|
607
651
|
|
608
652
|
it "respects :response_tag option" do
|
@@ -613,31 +657,45 @@ describe WashOut do
|
|
613
657
|
end
|
614
658
|
end
|
615
659
|
|
616
|
-
savon(:specific).
|
660
|
+
expect(savon(:specific)).to eq({:test => {:value=>"test"}})
|
617
661
|
end
|
618
662
|
|
619
663
|
it "handles snakecase option properly" do
|
620
664
|
mock_controller(snakecase_input: false, camelize_wsdl: false) do
|
621
665
|
soap_action "rocknroll", :args => {:ZOMG => :string}, :return => nil
|
622
666
|
def rocknroll
|
623
|
-
params["ZOMG"].
|
667
|
+
expect(params["ZOMG"]).to eq "yam!"
|
624
668
|
render :soap => nil
|
625
669
|
end
|
626
670
|
end
|
627
671
|
|
628
672
|
savon(:rocknroll, "ZOMG" => 'yam!')
|
629
673
|
end
|
674
|
+
end
|
630
675
|
|
676
|
+
describe "Router" do
|
677
|
+
it "raises when SOAP message without SOAP Envelope arrives" do
|
678
|
+
mock_controller do; end
|
679
|
+
invalid_request = '<a></a>'
|
680
|
+
response_hash = Nori.new.parse(HTTPI.post("http://app/route/api/action", invalid_request).body)
|
681
|
+
expect(response_hash["soap:Envelope"]["soap:Body"]["soap:Fault"]['faultstring']).to eq "Invalid SOAP request"
|
682
|
+
end
|
683
|
+
|
684
|
+
it "raises when SOAP message without SOAP Body arrives" do
|
685
|
+
mock_controller do; end
|
686
|
+
invalid_request = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"></s:Envelope>'
|
687
|
+
response_hash = Nori.new.parse(HTTPI.post("http://app/route/api/action", invalid_request).body)
|
688
|
+
expect(response_hash["soap:Envelope"]["soap:Body"]["soap:Fault"]['faultstring']).to eq "Invalid SOAP request"
|
689
|
+
end
|
631
690
|
end
|
632
691
|
|
633
692
|
describe "WS Security" do
|
634
|
-
|
635
693
|
it "appends username_token to params" do
|
636
694
|
mock_controller(wsse_username: "gorilla", wsse_password: "secret") do
|
637
695
|
soap_action "checkToken", :args => :integer, :return => nil, :to => 'check_token'
|
638
696
|
def check_token
|
639
|
-
request.env['WSSE_TOKEN']['username'].
|
640
|
-
request.env['WSSE_TOKEN']['password'].
|
697
|
+
expect(request.env['WSSE_TOKEN']['username']).to eq "gorilla"
|
698
|
+
expect(request.env['WSSE_TOKEN']['password']).to eq "secret"
|
641
699
|
render :soap => nil
|
642
700
|
end
|
643
701
|
end
|
@@ -656,20 +714,20 @@ describe WashOut do
|
|
656
714
|
end
|
657
715
|
|
658
716
|
# correct auth
|
659
|
-
|
660
|
-
|
717
|
+
expect { savon(:check_auth, 42){ wsse_auth "gorilla", "secret" } }.
|
718
|
+
not_to raise_exception
|
661
719
|
|
662
720
|
# wrong user
|
663
|
-
|
664
|
-
|
721
|
+
expect { savon(:check_auth, 42){ wsse_auth "chimpanzee", "secret" } }.
|
722
|
+
to raise_exception(Savon::SOAPFault)
|
665
723
|
|
666
724
|
# wrong pass
|
667
|
-
|
668
|
-
|
725
|
+
expect { savon(:check_auth, 42){ wsse_auth "gorilla", "nicetry" } }.
|
726
|
+
to raise_exception(Savon::SOAPFault)
|
669
727
|
|
670
728
|
# no auth
|
671
|
-
|
672
|
-
|
729
|
+
expect { savon(:check_auth, 42) }.
|
730
|
+
to raise_exception(Savon::SOAPFault)
|
673
731
|
end
|
674
732
|
|
675
733
|
it "handles PasswordDigest auth" do
|
@@ -681,24 +739,24 @@ describe WashOut do
|
|
681
739
|
end
|
682
740
|
|
683
741
|
# correct auth
|
684
|
-
|
685
|
-
|
742
|
+
expect { savon(:check_auth, 42){ wsse_auth "gorilla", "secret" } }.
|
743
|
+
not_to raise_exception
|
686
744
|
|
687
745
|
# correct digest auth
|
688
|
-
|
689
|
-
|
746
|
+
expect { savon(:check_auth, 42){ wsse_auth "gorilla", "secret", :digest } }.
|
747
|
+
not_to raise_exception
|
690
748
|
|
691
749
|
# wrong user
|
692
|
-
|
693
|
-
|
750
|
+
expect { savon(:check_auth, 42){ wsse_auth "chimpanzee", "secret", :digest } }.
|
751
|
+
to raise_exception(Savon::SOAPFault)
|
694
752
|
|
695
753
|
# wrong pass
|
696
|
-
|
697
|
-
|
754
|
+
expect { savon(:check_auth, 42){ wsse_auth "gorilla", "nicetry", :digest } }.
|
755
|
+
to raise_exception(Savon::SOAPFault)
|
698
756
|
|
699
757
|
# no auth
|
700
|
-
|
701
|
-
|
758
|
+
expect { savon(:check_auth, 42) }.
|
759
|
+
to raise_exception(Savon::SOAPFault)
|
702
760
|
end
|
703
761
|
|
704
762
|
it "handles auth callback" do
|
@@ -714,24 +772,24 @@ describe WashOut do
|
|
714
772
|
end
|
715
773
|
|
716
774
|
# correct auth
|
717
|
-
|
718
|
-
|
775
|
+
expect { savon(:check_auth, 42){ wsse_auth "gorilla", "secret" } }.
|
776
|
+
not_to raise_exception
|
719
777
|
|
720
778
|
# correct digest auth
|
721
|
-
|
722
|
-
|
779
|
+
expect { savon(:check_auth, 42){ wsse_auth "gorilla", "secret", :digest } }.
|
780
|
+
to raise_exception(Savon::SOAPFault)
|
723
781
|
|
724
782
|
# wrong user
|
725
|
-
|
726
|
-
|
783
|
+
expect { savon(:check_auth, 42){ wsse_auth "chimpanzee", "secret", :digest } }.
|
784
|
+
to raise_exception(Savon::SOAPFault)
|
727
785
|
|
728
786
|
# wrong pass
|
729
|
-
|
730
|
-
|
787
|
+
expect { savon(:check_auth, 42){ wsse_auth "gorilla", "nicetry", :digest } }.
|
788
|
+
to raise_exception(Savon::SOAPFault)
|
731
789
|
|
732
790
|
# no auth
|
733
|
-
|
734
|
-
|
791
|
+
expect { savon(:check_auth, 42) }.
|
792
|
+
to raise_exception(Savon::SOAPFault)
|
735
793
|
end
|
736
794
|
|
737
795
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -50,12 +50,20 @@ HTTPI.adapter = :rack
|
|
50
50
|
|
51
51
|
HTTPI::Adapter::Rack.mount 'app', Dummy::Application
|
52
52
|
Dummy::Application.routes.draw do
|
53
|
-
|
53
|
+
namespace :route do
|
54
|
+
scope module: 'space' do
|
55
|
+
wash_out :api
|
56
|
+
end
|
57
|
+
end
|
54
58
|
end
|
55
59
|
|
56
60
|
def mock_controller(options = {}, &block)
|
57
|
-
Object.send :
|
58
|
-
|
61
|
+
Object.send :const_set, :Route, Module.new unless defined?(Route)
|
62
|
+
Route.send :const_set, :Space, Module.new unless defined?(Route::Space)
|
63
|
+
Route::Space.send :remove_const, :ApiController if defined?(Route::Space::ApiController)
|
64
|
+
Route::Space.send :const_set, :ApiController, Class.new(ApplicationController) {
|
65
|
+
include RSpec::Matchers
|
66
|
+
|
59
67
|
soap_service options.reverse_merge({
|
60
68
|
snakecase_input: true,
|
61
69
|
camelize_wsdl: true,
|
@@ -64,5 +72,17 @@ def mock_controller(options = {}, &block)
|
|
64
72
|
class_exec &block if block
|
65
73
|
}
|
66
74
|
|
67
|
-
ActiveSupport::Dependencies::Reference.instance_variable_get(:'@store').delete('ApiController')
|
75
|
+
ActiveSupport::Dependencies::Reference.instance_variable_get(:'@store').delete('Route::Space::ApiController')
|
76
|
+
end
|
77
|
+
|
78
|
+
unless defined?(silence_stream) # Rails 5
|
79
|
+
def silence_stream(stream)
|
80
|
+
old_stream = stream.dup
|
81
|
+
stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
|
82
|
+
stream.sync = true
|
83
|
+
yield
|
84
|
+
ensure
|
85
|
+
stream.reopen(old_stream)
|
86
|
+
old_stream.close
|
87
|
+
end
|
68
88
|
end
|