ExtDirect/Test/Data/Router.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 36 CC 1 SCAR 6.9
CC
1
Cov
0%
get_tests
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 # This does not need to be indexed by PAUSE
2 package
3 RPC::ExtDirect::Test::Data::Router;
4  
5 use strict;
6 use warnings;
7  
8 # This aref contains definitions/data for Router tests
9 my $tests = [{
10 name => 'Invalid raw POST',
11
12 config => {
13 api_path => '/api',
14 router_path => '/router',
15 poll_path => '/events',
16 debug => 1,
17 },
18
19 input => {
20 method => 'POST',
21 url => '/router',
22 cgi_url => '/router1',
23
24 content => {
25 type => 'raw_post',
26 arg => [
27 'http://localhost/router',
28 '{"something":"invalid":"here"}',
29 ],
30 },
31 },
32
33 output => {
34 status => 200,
35 content_type => qr|^application/json\b|,
36 content_length => 249,
37 comparator => 'cmp_json',
38 content =>
39 q|{"action":null,"message":"ExtDirect error decoding POST data: |.
40 q| ', or } expected while parsing object/hash,|.
41 q| at character offset 22 (before \":\"here\"}\")'",|.
42 q| "method":null, "tid": null, "type":"exception",|.
43 q| "where":"RPC::ExtDirect::Serializer->decode_post"}|,
44 },
45 }, {
46 name => 'Valid raw POST, single request',
47
48 config => {
49 api_path => '/api',
50 router_path => '/router',
51 poll_path => '/events',
52 debug => 1,
53 },
54
55 input => {
56 method => 'POST',
57 url => '/router',
58 cgi_url => '/router1',
59
60 content => {
61 type => 'raw_post',
62 arg => [
63 'http://localhost/router',
64 q|{"type":"rpc","tid":1,"action":"Foo",|.
65 q| "method":"foo_foo","data":["bar"]}|,
66 ],
67 },
68 },
69
70 output => {
71 status => 200,
72 content_type => qr|^application/json\b|,
73 content_length => 78,
74 comparator => 'cmp_json',
75 content =>
76 q|{"action":"Foo","method":"foo_foo",|.
77 q|"result":"foo! 'bar'","tid":1,"type":"rpc"}|,
78 },
79 }, {
80 name => 'Valid raw POST, multiple requests',
81
82 config => {
83 api_path => '/api',
84 router_path => '/router',
85 poll_path => '/events',
86 debug => 1,
87 },
88
89 input => {
90 method => 'POST',
91 url => '/router',
92 cgi_url => '/router1',
93
94 content => {
95 type => 'raw_post',
96 arg => [
97 'http://localhost/router',
98 q|[{"tid":1,"action":"Qux","method":"foo_foo",|.
99 q| "data":["foo"],"type":"rpc"},|.
100 q| {"tid":2,"action":"Qux","method":"foo_bar",|.
101 q| "data":["bar1","bar2"],"type":"rpc"},|.
102 q| {"tid":3,"action":"Qux","method":"foo_baz",|.
103 q| "data":{"foo":"baz1","bar":"baz2",|.
104 q| "baz":"baz3"},"type":"rpc"}]|,
105 ],
106 },
107 },
108
109 output => {
110 status => 200,
111 content_type => qr|^application/json\b|,
112 content_length => 304,
113 comparator => 'cmp_str',
114 content =>
115 q|[{"action":"Qux","method":"foo_foo",|.
116 q|"result":"foo! 'foo'","tid":1,"type":"rpc"},|.
117 q|{"action":"Qux","method":"foo_bar",|.
118 q|"result":["foo! bar!","bar1","bar2"],"tid":2,"type":"rpc"},|.
119 q|{"action":"Qux","method":"foo_baz",|.
120 q|"result":{"bar":"baz2","baz":"baz3","foo":"baz1",|.
121 q|"msg":"foo! bar! baz!"},"tid":3,"type":"rpc"}]|,
122 },
123 }, {
124 name => 'Valid POST with invalid metadata 1',
125
126 config => {
127 api_path => '/api',
128 router_path => '/router',
129 poll_path => '/events',
130 debug => 1,
131 },
132
133 input => {
134 method => 'POST',
135 url => '/router',
136 cgi_url => '/router4',
137
138 content => {
139 type => 'raw_post',
140 arg => [
141 'http://localhost/router',
142 q|{"type":"rpc","tid":1,"action":"Meta",|.
143 q|"method":"arg0","data":null,|.
144 q|"metadata":[42]}|,
145 ],
146 },
147 },
148
149 output => {
150 status => 200,
151 content_type => qr|^application/json\b|,
152 content_length => 213,
153 comparator => 'cmp_str',
154 content =>
155 q|{"action":"Meta",|.
156 q|"message":"ExtDirectMethodMeta.arg0requires|.
157 q|2metadatavalue(s)butonly1areprovided",|.
158 q|"method":"arg0","tid":1,"type":"exception",|.
159 q|"where":"RPC::ExtDirect::API::Method->check_method_metadata"}|,
160 },
161 }, {
162 name => 'Valid POST with metadata 1',
163
164 config => {
165 api_path => '/api',
166 router_path => '/router',
167 poll_path => '/events',
168 debug => 1,
169 },
170
171 input => {
172 method => 'POST',
173 url => '/router',
174 cgi_url => '/router4',
175
176 content => {
177 type => 'raw_post',
178 arg => [
179 'http://localhost/router',
180 q|{"type":"rpc","tid":1,"action":"Meta",|.
181 q|"method":"arg0","data":null,|.
182 q|"metadata":[42,"foo"]}|,
183 ],
184 },
185 },
186
187 output => {
188 status => 200,
189 content_type => qr|^application/json\b|,
190 content_length => 83,
191 comparator => 'cmp_str',
192 content =>
193 q|{"action":"Meta","method":"arg0",|.
194 q|"result":{"meta":[42,"foo"]},"tid":1,|.
195 q|"type":"rpc"}|,
196 },
197 }, {
198 name => 'Valid POST with metadata 2',
199
200 config => {
201 api_path => '/api',
202 router_path => '/router',
203 poll_path => '/events',
204 debug => 1,
205 },
206
207 input => {
208 method => 'POST',
209 url => '/router',
210 cgi_url => '/router4',
211
212 content => {
213 type => 'raw_post',
214 arg => [
215 'http://localhost/router',
216 q|{"type":"rpc","tid":1,"action":"Meta",|.
217 q|"method":"arg1_last","data":["foo"],|.
218 q|"metadata":[42]}|,
219 ],
220 },
221 },
222
223 output => {
224 status => 200,
225 content_type => qr|^application/json\b|,
226 content_length => 95,
227 comparator => 'cmp_str',
228 content =>
229 q|{"action":"Meta","method":"arg1_last",|.
230 q|"result":{"arg1":"foo","meta":[42]},|.
231 q|"tid":1,"type":"rpc"}|,
232 },
233 }, {
234 name => 'Valid POST with metadata 3',
235
236 config => {
237 api_path => '/api',
238 router_path => '/router',
239 poll_path => '/events',
240 debug => 1,
241 },
242
243 input => {
244 method => 'POST',
245 url => '/router',
246 cgi_url => '/router4',
247
248 content => {
249 type => 'raw_post',
250 arg => [
251 'http://localhost/router',
252 q|{"type":"rpc","tid":1,"action":"Meta",|.
253 q|"method":"arg1_first","data":["foo"],|.
254 q|"metadata":[42,43]}|,
255 ],
256 },
257 },
258
259 output => {
260 status => 200,
261 content_type => qr|^application/json\b|,
262 content_length => 99,
263 comparator => 'cmp_str',
264 content =>
265 q|{"action":"Meta","method":"arg1_first",|.
266 q|"result":{"arg1":"foo","meta":[42,43]},|.
267 q|"tid":1,"type":"rpc"}|,
268 },
269 }, {
270 name => 'Valid POST with metadata 4',
271
272 config => {
273 api_path => '/api',
274 router_path => '/router',
275 poll_path => '/events',
276 debug => 1,
277 },
278
279 input => {
280 method => 'POST',
281 url => '/router',
282 cgi_url => '/router4',
283
284 content => {
285 type => 'raw_post',
286 arg => [
287 'http://localhost/router',
288 q|{"type":"rpc","tid":1,"action":"Meta",|.
289 q|"method":"arg2_last","data":[42,43],|.
290 q|"metadata":["foo","bar"]}|,
291 ],
292 },
293 },
294
295 output => {
296 status => 200,
297 content_type => qr|^application/json\b|,
298 content_length => 105,
299 comparator => 'cmp_str',
300 content =>
301 q|{"action":"Meta","method":"arg2_last",|.
302 q|"result":{"arg1":42,"arg2":43,"meta":["foo"]},|.
303 q|"tid":1,"type":"rpc"}|,
304 },
305 }, {
306 name => 'Valid POST with metadata 5',
307
308 config => {
309 api_path => '/api',
310 router_path => '/router',
311 poll_path => '/events',
312 debug => 1,
313 },
314
315 input => {
316 method => 'POST',
317 url => '/router',
318 cgi_url => '/router4',
319
320 content => {
321 type => 'raw_post',
322 arg => [
323 'http://localhost/router',
324 q|{"type":"rpc","tid":1,"action":"Meta",|.
325 q|"method":"arg2_middle","data":[44,45],|.
326 q|"metadata":["fred","bonzo","qux"]}|,
327 ],
328 },
329 },
330
331 output => {
332 status => 200,
333 content_type => qr|^application/json\b|,
334 content_length => 116,
335 comparator => 'cmp_str',
336 content =>
337 q|{"action":"Meta","method":"arg2_middle",|.
338 q|"result":{"arg1":44,"arg2":45,"meta":|.
339 q|["fred","bonzo"]},"tid":1,"type":"rpc"}|,
340 },
341 }, {
342 name => 'Valid POST with metadata 6',
343
344 config => {
345 api_path => '/api',
346 router_path => '/router',
347 poll_path => '/events',
348 debug => 1,
349 },
350
351 input => {
352 method => 'POST',
353 url => '/router',
354 cgi_url => '/router4',
355
356 content => {
357 type => 'raw_post',
358 arg => [
359 'http://localhost/router',
360 q|{"type":"rpc","tid":1,"action":"Meta",|.
361 q|"method":"named_default",|.
362 q|"data":{"foo":"bar","fred":"bonzo"},|.
363 q|"metadata":[42]}|,
364 ],
365 },
366 },
367
368 output => {
369 status => 200,
370 content_type => qr|^application/json\b|,
371 content_length => 113,
372 comparator => 'cmp_str',
373 content =>
374 q|{"action":"Meta","method":"named_default",|.
375 q|"result":{"foo":"bar","fred":"bonzo",|.
376 q|"meta":[42]},"tid":1,"type":"rpc"}|,
377 },
378 }, {
379 name => 'Valid POST with metadata 7',
380
381 config => {
382 api_path => '/api',
383 router_path => '/router',
384 poll_path => '/events',
385 debug => 1,
386 },
387
388 input => {
389 method => 'POST',
390 url => '/router',
391 cgi_url => '/router4',
392
393 content => {
394 type => 'raw_post',
395 arg => [
396 'http://localhost/router',
397 q|{"type":"rpc","tid":1,"action":"Meta",|.
398 q|"method":"named_arg",|.
399 q|"data":{"qux":"fred"},|.
400 q|"metadata":["blerg"]}|,
401 ],
402 },
403 },
404
405 output => {
406 status => 200,
407 content_type => qr|^application/json\b|,
408 content_length => 100,
409 comparator => 'cmp_str',
410 content =>
411 q|{"action":"Meta","method":"named_arg",|.
412 q|"result":{"meta":["blerg"],"qux":"fred"},|.
413 q|"tid":1,"type":"rpc"}|,
414 },
415 }, {
416 name => 'Valid POST with metadata 8',
417
418 config => {
419 api_path => '/api',
420 router_path => '/router',
421 poll_path => '/events',
422 debug => 1,
423 },
424
425 input => {
426 method => 'POST',
427 url => '/router',
428 cgi_url => '/router4',
429
430 content => {
431 type => 'raw_post',
432 arg => [
433 'http://localhost/router',
434 q|{"type":"rpc","tid":1,"action":"Meta",|.
435 q|"method":"named_arg",|.
436 q|"data":{"foo":"bar"},|.
437 q|"metadata":["blerg"]}|,
438 ],
439 },
440 },
441
442 output => {
443 status => 200,
444 content_type => qr|^application/json\b|,
445 content_length => 87,
446 comparator => 'cmp_str',
447 content =>
448 q|{"action":"Meta","method":"named_arg",|.
449 q|"result":{"meta":["blerg"]},|.
450 q|"tid":1,"type":"rpc"}|,
451 },
452 }, {
453 name => 'Valid POST with metadata 9',
454
455 config => {
456 api_path => '/api',
457 router_path => '/router',
458 poll_path => '/events',
459 debug => 1,
460 },
461
462 input => {
463 method => 'POST',
464 url => '/router',
465 cgi_url => '/router4',
466
467 content => {
468 type => 'raw_post',
469 arg => [
470 'http://localhost/router',
471 q|{"type":"rpc","tid":1,"action":"Meta",|.
472 q|"method":"named_strict",|.
473 q|"data":{"frob":"dux","frogg":"bonzo"},|.
474 q|"metadata":{"foo":{"bar":{"baz":42}}}}|,
475 ],
476 },
477 },
478
479 output => {
480 status => 200,
481 content_type => qr|^application/json\b|,
482 content_length => 136,
483 comparator => 'cmp_str',
484 content =>
485 q|{"action":"Meta","method":"named_strict",|.
486 q|"result":{"frob":"dux","frogg":"bonzo",|.
487 q|"meta":{"foo":{"bar":{"baz":42}}}},|.
488 q|"tid":1,"type":"rpc"}|,
489 },
490 }, {
491 name => 'Valid POST with metadata 10',
492
493 config => {
494 api_path => '/api',
495 router_path => '/router',
496 poll_path => '/events',
497 debug => 1,
498 },
499
500 input => {
501 method => 'POST',
502 url => '/router',
503 cgi_url => '/router4',
504
505 content => {
506 type => 'raw_post',
507 arg => [
508 'http://localhost/router',
509 q|{"type":"rpc","tid":1,"action":"Meta",|.
510 q|"method":"named_unstrict",|.
511 q|"data":{"qux":null},"metadata":{}}|,
512 ],
513 },
514 },
515
516 output => {
517 status => 200,
518 content_type => qr|^application/json\b|,
519 content_length => 96,
520 comparator => 'cmp_str',
521 content =>
522 q|{"action":"Meta","method":"named_unstrict",|.
523 q|"result":{"meta":{},"qux":null},|.
524 q|"tid":1,"type":"rpc"}|,
525 },
526 }, {
527 name => 'Valid POST with ancillary properties',
528
529 config => {
530 api_path => '/api',
531 router_path => '/router',
532 poll_path => '/events',
533 debug => 1,
534 },
535
536 input => {
537 method => 'POST',
538 url => '/router',
539 cgi_url => '/router4',
540
541 content => {
542 type => 'raw_post',
543 arg => [
544 'http://localhost/router',
545 q|{"type":"rpc","tid":1,"action":"Meta",|.
546 q|"method":"aux","data":null,"foo":"bar",|.
547 q|"token":"kaboom!"}|,
548 ],
549 },
550 },
551
552 output => {
553 status => 200,
554 content_type => qr|^application/json\b|,
555 content_length => 102,
556 comparator => 'cmp_str',
557 content =>
558 q|{"action":"Meta","method":"aux",|.
559 q|"result":{"aux":{"foo":"bar","token":"kaboom!"}},|.
560 q|"tid":1,"type":"rpc"}|,
561 },
562 }, {
563 name => 'Form request, no uploads',
564
565 config => {
566 api_path => '/api',
567 router_path => '/router',
568 poll_path => '/events',
569 debug => 1,
570 },
571
572 input => {
573 method => 'POST',
574 url => '/router',
575 cgi_url => '/router1',
576
577 content => {
578 type => 'form_post',
579 arg => [
580 'http://localhost/router',
581 action => '/router.cgi',
582 method => 'POST',
583 extAction => 'Bar',
584 extMethod => 'bar_baz',
585 extTID => 123,
586 field1 => 'foo',
587 field2 => 'bar',
588 extType => 'rpc',
589 ],
590 },
591 },
592
593 output => {
594 status => 200,
595 content_type => qr|^application/json\b|,
596 content_length => 99,
597 comparator => 'cmp_str',
598 content =>
599 q|{"action":"Bar","method":"bar_baz",|.
600 q|"result":{"field1":"foo","field2":"bar"},|.
601 q|"tid":123,"type":"rpc"}|,
602 },
603 }, {
604 name => 'Form request with ordered metadata',
605
606 config => {
607 api_path => '/api',
608 router_path => '/router',
609 poll_path => '/events',
610 debug => 1,
611 },
612
613 input => {
614 method => 'POST',
615 url => '/router',
616 cgi_url => '/router4',
617
618 content => {
619 type => 'form_post',
620 arg => [
621 'http://localhost/router',
622 action => '/router.cgi',
623 method => 'POST',
624 extAction => 'Meta',
625 extMethod => 'form_ordered',
626 extType => 'rpc',
627 extTID => 42,
628 fred => 'frob',
629
630 # Client sends JSON encoded metadata with forms
631 metadata => '[42]',
632 ],
633 },
634 },
635
636 output => {
637 status => 200,
638 content_type => qr|^application/json\b|,
639 content_length => 104,
640 comparator => 'cmp_str',
641 content =>
642 q|{"action":"Meta","method":"form_ordered",|.
643 q|"result":{"fred":"frob","metadata":[42]},|.
644 q|"tid":42,"type":"rpc"}|,
645 },
646 }, {
647 name => 'Form request with named metadata',
648
649 config => {
650 api_path => '/api',
651 router_path => '/router',
652 poll_path => '/events',
653 debug => 1,
654 },
655
656 input => {
657 method => 'POST',
658 url => '/router',
659 cgi_url => '/router4',
660
661 content => {
662 type => 'form_post',
663 arg => [
664 'http://localhost/router',
665 action => '/router.cgi',
666 method => 'POST',
667 extAction => 'Meta',
668 extMethod => 'form_named',
669 extType => 'rpc',
670 extTID => 58,
671 frogg => 'splurge',
672 boogaloo => 1916,
673  
674 # Client sends JSON encoded metadata with forms
675 metadata => '{"foo":1,"bar":2,"baz":3}',
676 ],
677 },
678 },
679
680 output => {
681 status => 200,
682 content_type => qr|^application/json\b|,
683 content_length => 139,
684 comparator => 'cmp_str',
685
686 # Note that we send a number in boogaloo field above
687 # but expect a string in return. This is due to the nature
688 # of form POST submits; in either URL encoding or form-multipart
689 # the data is sent as
690 content =>
691 q|{"action":"Meta","method":"form_named",|.
692 q|"result":{"_m":{"bar":2,"baz":3,"foo":1},|.
693 q|"boogaloo":"1916","frogg":"splurge"},|.
694 q|"tid":58,"type":"rpc"}|,
695 },
696 }, {
697 name => 'Form request with named metadata, multipart encoded',
698
699 config => {
700 api_path => '/api',
701 router_path => '/router',
702 poll_path => '/events',
703 debug => 1,
704 },
705
706 input => {
707 method => 'POST',
708 url => '/router',
709 cgi_url => '/router4',
710
711 content => {
712 type => 'form_upload',
713 arg => [
714 'http://localhost/router',
715 [],
716 action => '/router.cgi',
717 method => 'POST',
718 extAction => 'Meta',
719 extMethod => 'form_named',
720 extType => 'rpc',
721 extUpload => 'true',
722 extTID => 63,
723 frogg => 'splurge',
724 boogaloo => 1916,
725  
726 # Client sends JSON encoded metadata with forms
727 metadata => '{"foo":1,"bar":2,"baz":3}',
728 ],
729 },
730 },
731
732 output => {
733 status => 200,
734 content_type => qr|^text/html\b|,
735 content_length => 186,
736 comparator => 'cmp_str',
737 content =>
738 q|<html><body><textarea>|.
739 q|{"action":"Meta","method":"form_named",|.
740 q|"result":{"_m":{"bar":2,"baz":3,"foo":1},|.
741 q|"boogaloo":"1916","frogg":"splurge"},|.
742 q|"tid":63,"type":"rpc"}|.
743 q|</textarea></body></html>|,
744 },
745 }, {
746 name => 'Form request, one upload',
747
748 config => {
749 api_path => '/api',
750 router_path => '/router',
751 poll_path => '/events',
752 debug => 1,
753 },
754
755 input => {
756 method => 'POST',
757 url => '/router',
758 cgi_url => '/router2',
759
760 content => {
761 type => 'form_upload',
762 arg => [
763 'http://localhost/router',
764 ['qux.txt'],
765 action => '/router.cgi',
766 method => 'POST',
767 extAction => 'JuiceBar',
768 extMethod => 'bar_baz',
769 extTID => 7,
770 extType => 'rpc',
771 foo_field => 'foo',
772 bar_field => 'bar',
773 extUpload => 'true',
774 ],
775 },
776 },
777
778 output => {
779 status => 200,
780 content_type => qr|^text/html\b|,
781 content_length => 253,
782 comparator => 'cmp_str',
783 content =>
784 q|<html><body><textarea>|.
785 q|{"action":"JuiceBar","method":"bar_baz",|.
786 q|"result":{"bar_field":"bar",|.
787 q|"foo_field":"foo",|.
788 q|"upload_response":"The following files were |.
789 q|processed:\n|.
790 q|qux.txt application/octet-stream 31 ok\n"|.
791 q|},"tid":7,|.
792 q|"type":"rpc"}|.
793 q|</textarea></body></html>|,
794 },
795 }, {
796 name => 'Form request, multiple uploads',
797
798 config => {
799 api_path => '/api',
800 router_path => '/router',
801 poll_path => '/events',
802 debug => 1,
803 },
804
805 input => {
806 method => 'POST',
807 cgi_url => '/router2',
808 url => '/router',
809
810 content => {
811 type => 'form_upload',
812 arg => [
813 'http://localhost/router',
814 ['foo.jpg', 'bar.png', 'script.js'],
815 action => '/router.cgi',
816 method => 'POST',
817 extAction => 'JuiceBar',
818 extMethod => 'bar_baz',
819 extTID => 8,
820 field => 'value',
821 extUpload => 'true',
822 extType => 'rpc',
823 ],
824 },
825 },
826
827 output => {
828 status => 200,
829 content_type => qr|^text/html\b|,
830 content_length => 321,
831 comparator => 'cmp_str',
832 content =>
833 q|<html><body><textarea>|.
834 q|{"action":"JuiceBar","method":"bar_baz",|.
835 q|"result":{|.
836 q|"field":"value",|.
837 q|"upload_response":"The following files were |.
838 q|processed:\n|.
839 q|foo.jpg application/octet-stream 16159 ok\n|.
840 q|bar.png application/octet-stream 20693 ok\n|.
841 q|script.js application/octet-stream 80 ok\n"|.
842 q|},"tid":8,"type":"rpc"}|.
843 q|</textarea></body></html>|,
844 },
845 }];
846  
847 sub get_tests { return $tests };
848  
849 1;