Mercurial > hg > nginx-tests
comparison js_subrequests.t @ 1616:cd0461e1e392
Tests: added js subrequest test with error_page redirect.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Wed, 18 Nov 2020 19:03:09 +0000 |
parents | bc0990ea2e5b |
children | 5ac6efbe5552 |
comparison
equal
deleted
inserted
replaced
1615:4eb2a82dd9b5 | 1616:cd0461e1e392 |
---|---|
50 | 50 |
51 server { | 51 server { |
52 listen 127.0.0.1:8080; | 52 listen 127.0.0.1:8080; |
53 server_name localhost; | 53 server_name localhost; |
54 | 54 |
55 location /njs { | |
56 js_content test_njs; | |
57 } | |
58 | |
55 location /sr { | 59 location /sr { |
56 js_content sr; | 60 js_content sr; |
57 } | 61 } |
58 | 62 |
59 location /sr_pr { | 63 location /sr_pr { |
107 | 111 |
108 location /sr_detached_in_variable_handler { | 112 location /sr_detached_in_variable_handler { |
109 return 200 $subrequest_var; | 113 return 200 $subrequest_var; |
110 } | 114 } |
111 | 115 |
112 location /sr_error_page { | 116 location /sr_async_var { |
113 set $_ $async_var; | 117 set $_ $async_var; |
114 error_page 404 /return; | 118 error_page 404 /return; |
115 return 404; | 119 return 404; |
116 } | 120 } |
117 | 121 |
122 location /sr_error_page { | |
123 js_content sr_error_page; | |
124 } | |
125 | |
118 location /sr_js_in_subrequest { | 126 location /sr_js_in_subrequest { |
119 js_content sr_js_in_subrequest; | 127 js_content sr_js_in_subrequest; |
120 } | 128 } |
121 | 129 |
122 location /sr_js_in_subrequest_pr { | 130 location /sr_js_in_subrequest_pr { |
208 } | 216 } |
209 | 217 |
210 location /return { | 218 location /return { |
211 return 200 '["$request_method"]'; | 219 return 200 '["$request_method"]'; |
212 } | 220 } |
221 | |
222 location /error_page_404 { | |
223 return 404; | |
224 | |
225 error_page 404 /404.html; | |
226 } | |
213 } | 227 } |
214 | 228 |
215 server { | 229 server { |
216 listen 127.0.0.1:8081; | 230 listen 127.0.0.1:8081; |
217 server_name localhost; | 231 server_name localhost; |
252 | 266 |
253 EOF | 267 EOF |
254 | 268 |
255 $t->write_file('test.js', <<EOF); | 269 $t->write_file('test.js', <<EOF); |
256 this.Failed = {get toConvert() { return {toString(){return {};}}}}; | 270 this.Failed = {get toConvert() { return {toString(){return {};}}}}; |
271 | |
272 function test_njs(r) { | |
273 r.return(200, njs.version); | |
274 } | |
257 | 275 |
258 function sr(r) { | 276 function sr(r) { |
259 subrequest_fn(r, ['/p/sub2'], ['uri', 'status']) | 277 subrequest_fn(r, ['/p/sub2'], ['uri', 'status']) |
260 } | 278 } |
261 | 279 |
338 }); | 356 }); |
339 | 357 |
340 return ""; | 358 return ""; |
341 } | 359 } |
342 | 360 |
361 function sr_error_page(r) { | |
362 r.subrequest('/error_page_404') | |
363 .then(reply => {r.return(200, `reply.status:\${reply.status}`)}); | |
364 } | |
365 | |
343 function subrequest_var(r) { | 366 function subrequest_var(r) { |
344 r.subrequest('/p/detached', {detached:true}); | 367 r.subrequest('/p/detached', {detached:true}); |
345 r.subrequest('/p/detached', {detached:true, args:'a=yyy', | 368 r.subrequest('/p/detached', {detached:true, args:'a=yyy', |
346 method:'POST'}); | 369 method:'POST'}); |
347 | 370 |
468 | 491 |
469 EOF | 492 EOF |
470 | 493 |
471 $t->write_file('t', '["SEE-THIS"]'); | 494 $t->write_file('t', '["SEE-THIS"]'); |
472 | 495 |
473 $t->try_run('no njs available')->plan(31); | 496 $t->try_run('no njs available')->plan(32); |
474 $t->run_daemon(\&http_daemon); | 497 $t->run_daemon(\&http_daemon); |
475 | 498 |
476 ############################################################################### | 499 ############################################################################### |
477 | 500 |
478 is(get_json('/sr'), '[{"status":404,"uri":"/p/sub2"}]', 'sr'); | 501 is(get_json('/sr'), '[{"status":404,"uri":"/p/sub2"}]', 'sr'); |
519 'sr_unavail_pr'); | 542 'sr_unavail_pr'); |
520 | 543 |
521 like(http_get('/sr_detached_in_variable_handler'), qr/subrequest_var/, | 544 like(http_get('/sr_detached_in_variable_handler'), qr/subrequest_var/, |
522 'sr_detached_in_variable_handler'); | 545 'sr_detached_in_variable_handler'); |
523 | 546 |
547 TODO: { | |
548 todo_skip 'leaves coredump', 1 unless $ENV{TEST_NGINX_UNSAFE} | |
549 or http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.5.0'; | |
550 | |
551 like(http_get('/sr_error_page'), qr/reply\.status:404/, | |
552 'sr_error_page'); | |
553 | |
554 } | |
555 | |
524 http_get('/sr_broken'); | 556 http_get('/sr_broken'); |
525 http_get('/sr_in_sr'); | 557 http_get('/sr_in_sr'); |
526 http_get('/sr_in_variable_handler'); | 558 http_get('/sr_in_variable_handler'); |
527 http_get('/sr_error_page'); | 559 http_get('/sr_async_var'); |
528 http_get('/sr_too_large'); | 560 http_get('/sr_too_large'); |
529 http_get('/sr_except_not_a_func'); | 561 http_get('/sr_except_not_a_func'); |
530 http_get('/sr_except_failed_to_convert_options_arg'); | 562 http_get('/sr_except_failed_to_convert_options_arg'); |
531 http_get('/sr_uri_except'); | 563 http_get('/sr_uri_except'); |
532 | 564 |