Mercurial > hg > nginx-tests
diff stream_js_fetch.t @ 1806:564f74bf6e4d
Tests: added stream fetch tests for js_access directive.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Mon, 14 Nov 2022 17:52:23 -0800 |
parents | cadf15e2e2b3 |
children | 7cf848422b28 |
line wrap: on
line diff
--- a/stream_js_fetch.t Thu Nov 10 17:08:43 2022 +0400 +++ b/stream_js_fetch.t Mon Nov 14 17:52:23 2022 -0800 @@ -54,6 +54,14 @@ location /validate { js_content test.validate; } + + location /success { + return 200; + } + + location /fail { + return 403; + } } } @@ -73,6 +81,18 @@ js_filter test.filter_verify; proxy_pass 127.0.0.1:8091; } + + server { + listen 127.0.0.1:8083; + js_access test.access_ok; + proxy_pass 127.0.0.1:8090; + } + + server { + listen 127.0.0.1:8084; + js_access test.access_nok; + proxy_pass 127.0.0.1:8090; + } } EOF @@ -132,10 +152,25 @@ }); } - export default {njs: test_njs, validate, preread_verify, filter_verify}; + async function access_ok(s) { + let reply = await ngx.fetch('http://127.0.0.1:$p/success', + {headers: {Host:'aaa'}}); + + (reply.status == 200) ? s.allow(): s.deny(); + } + + async function access_nok(s) { + let reply = await ngx.fetch('http://127.0.0.1:$p/fail', + {headers: {Host:'aaa'}}); + + (reply.status == 200) ? s.allow(): s.deny(); + } + + export default {njs: test_njs, validate, preread_verify, filter_verify, + access_ok, access_nok}; EOF -$t->try_run('no stream njs available')->plan(7); +$t->try_run('no stream njs available')->plan(9); $t->run_daemon(\&stream_daemon, port(8090), port(8091)); $t->waitforsocket('127.0.0.1:' . port(8090)); @@ -167,6 +202,9 @@ } +is(stream('127.0.0.1:' . port(8083))->io('ABC'), 'ABC', 'access fetch ok'); +is(stream('127.0.0.1:' . port(8084))->io('ABC'), '', 'access fetch nok'); + ############################################################################### sub stream_daemon {