annotate stream_js.t @ 1842:af47a0b348a5

Tests: LibreSSL certificate negotiation with TLSv1.3. LibreSSL fails to negotiate certificates based on signature algorithms when using TLSv1.3, and fails with "missing rsa certificate" and "unknown pkey type" errors.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 23 Mar 2023 19:50:17 +0300
parents 520fb74cce4c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
2
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
3 # (C) Andrey Zelenkov
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
4 # (C) Dmitry Volyntsev
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
5 # (C) Nginx, Inc.
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
6
1375
f168fc46c7a4 Tests: renamed JavaScript to njs.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1374
diff changeset
7 # Tests for stream njs module.
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
8
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
9 ###############################################################################
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
10
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
11 use warnings;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
12 use strict;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
13
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
14 use Test::More;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
15
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
16 BEGIN { use FindBin; chdir($FindBin::Bin); }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
17
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
18 use lib 'lib';
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
19 use Test::Nginx;
1005
557faa1782e5 Tests: stream JavaScript test with udp.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1003
diff changeset
20 use Test::Nginx::Stream qw/ dgram stream /;
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
21
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
22 ###############################################################################
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
23
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
24 select STDERR; $| = 1;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
25 select STDOUT; $| = 1;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
26
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
27 my $t = Test::Nginx->new()->has(qw/http proxy rewrite stream stream_return udp/)
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
28 ->write_file_expand('nginx.conf', <<'EOF');
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
29
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
30 %%TEST_GLOBALS%%
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
31
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
32 daemon off;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
33
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
34 events {
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
35 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
36
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
37 http {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
38 %%TEST_GLOBALS_HTTP%%
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
39
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
40 js_import test.js;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
41
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
42 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
43 listen 127.0.0.1:8079;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
44 server_name localhost;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
45
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
46 location /njs {
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
47 js_content test.njs;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
48 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
49
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
50 location /p/ {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
51 proxy_pass http://127.0.0.1:8095/;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
52
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
53 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
54
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
55 location /return {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
56 return 200 $http_foo;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
57 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
58 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
59 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
60
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
61 stream {
1609
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1544
diff changeset
62 %%TEST_GLOBALS_STREAM%%
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1544
diff changeset
63
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
64 js_set $js_addr test.addr;
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
65 js_set $js_var test.variable;
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
66 js_set $js_log test.log;
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
67 js_set $js_unk test.unk;
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
68 js_set $js_req_line test.req_line;
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
69 js_set $js_sess_unk test.sess_unk;
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
70 js_set $js_async test.asyncf;
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
71
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
72 js_import test.js;
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
73
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
74 log_format status $server_port:$status;
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
75
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
76 server {
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
77 listen 127.0.0.1:8080;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
78 return $js_addr;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
79 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
80
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
81 server {
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
82 listen 127.0.0.1:8081;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
83 return $js_log;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
84 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
85
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
86 server {
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
87 listen 127.0.0.1:8082;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
88 return $js_var;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
89 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
90
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
91 server {
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
92 listen 127.0.0.1:8083;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
93 return $js_unk;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
94 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
95
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
96 server {
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
97 listen 127.0.0.1:8084;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
98 return $js_sess_unk;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
99 }
1005
557faa1782e5 Tests: stream JavaScript test with udp.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1003
diff changeset
100
557faa1782e5 Tests: stream JavaScript test with udp.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1003
diff changeset
101 server {
1237
e4974af3fb12 Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1005
diff changeset
102 listen 127.0.0.1:%%PORT_8985_UDP%% udp;
1005
557faa1782e5 Tests: stream JavaScript test with udp.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1003
diff changeset
103 return $js_addr;
557faa1782e5 Tests: stream JavaScript test with udp.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1003
diff changeset
104 }
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
105
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
106 server {
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
107 listen 127.0.0.1:8086;
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
108 js_access test.access_step;
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
109 js_preread test.preread_step;
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
110 js_filter test.filter_step;
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
111 proxy_pass 127.0.0.1:8090;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
112 }
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
113
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
114 server {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
115 listen 127.0.0.1:8087;
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
116 js_access test.access_undecided;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
117 return OK;
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
118 access_log %%TESTDIR%%/status.log status;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
119 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
120
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
121 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
122 listen 127.0.0.1:8088;
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
123 js_access test.access_allow;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
124 return OK;
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
125 access_log %%TESTDIR%%/status.log status;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
126 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
127
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
128 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
129 listen 127.0.0.1:8089;
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
130 js_access test.access_deny;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
131 return OK;
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
132 access_log %%TESTDIR%%/status.log status;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
133 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
134
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
135 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
136 listen 127.0.0.1:8091;
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
137 js_preread test.preread_async;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
138 proxy_pass 127.0.0.1:8090;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
139 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
140
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
141 server {
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
142 listen 127.0.0.1:8092;
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
143 js_preread test.preread_data;
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
144 proxy_pass 127.0.0.1:8090;
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
145 }
1248
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
146
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
147 server {
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
148 listen 127.0.0.1:8093;
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
149 js_preread test.preread_req_line;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
150 return $js_req_line;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
151 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
152
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
153 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
154 listen 127.0.0.1:8094;
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
155 js_filter test.filter_empty;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
156 proxy_pass 127.0.0.1:8090;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
157 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
158
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
159 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
160 listen 127.0.0.1:8095;
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
161 js_filter test.filter_header_inject;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
162 proxy_pass 127.0.0.1:8079;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
163 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
164
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
165 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
166 listen 127.0.0.1:8096;
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
167 js_filter test.filter_search;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
168 proxy_pass 127.0.0.1:8090;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
169 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
170
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
171 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
172 listen 127.0.0.1:8097;
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
173 js_access test.access_except;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
174 proxy_pass 127.0.0.1:8090;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
175 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
176
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
177 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
178 listen 127.0.0.1:8098;
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
179 js_preread test.preread_except;
1248
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
180 proxy_pass 127.0.0.1:8090;
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
181 }
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
182
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
183 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
184 listen 127.0.0.1:8099;
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
185 js_filter test.filter_except;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
186 proxy_pass 127.0.0.1:8090;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
187 }
1738
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
188
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
189 server {
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
190 listen 127.0.0.1:8100;
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
191 return $js_async;
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
192 }
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
193 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
194
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
195 EOF
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
196
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
197 $t->write_file('test.js', <<EOF);
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
198 function test_njs(r) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
199 r.return(200, njs.version);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
200 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
201
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
202 function addr(s) {
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
203 return 'addr=' + s.remoteAddress;
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
204 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
205
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
206 function variable(s) {
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
207 return 'variable=' + s.variables.remote_addr;
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
208 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
209
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
210 function sess_unk(s) {
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
211 return 'sess_unk=' + s.unk;
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
212 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
213
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
214 function log(s) {
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
215 s.log("SEE-THIS");
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
216 }
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
217
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
218 var res = '';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
219
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
220 function access_step(s) {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
221 res += '1';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
222
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
223 setTimeout(function() {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
224 if (s.remoteAddress.match('127.0.0.1')) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
225 s.allow();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
226 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
227 }, 1);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
228 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
229
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
230 function preread_step(s) {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
231 s.on('upload', function (data) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
232 res += '2';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
233 if (res.length >= 3) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
234 s.done();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
235 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
236 });
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
237 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
238
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
239 function filter_step(s) {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
240 s.on('upload', function(data, flags) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
241 s.send(data);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
242 res += '3';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
243 });
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
244
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
245 s.on('download', function(data, flags) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
246
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
247 if (!flags.last) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
248 res += '4';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
249 s.send(data);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
250
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
251 } else {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
252 res += '5';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
253 s.send(res, {last:1});
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
254 s.off('download');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
255 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
256 });
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
257 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
258
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
259 function access_undecided(s) {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
260 s.decline();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
261 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
262
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
263 function access_allow(s) {
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
264 if (s.remoteAddress.match('127.0.0.1')) {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
265 s.done();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
266 return;
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
267 }
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
268
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
269 s.deny();
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
270 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
271
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
272 function access_deny(s) {
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
273 if (s.remoteAddress.match('127.0.0.1')) {
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
274 s.deny();
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
275 return;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
276 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
277
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
278 s.allow();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
279 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
280
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
281
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
282 function preread_async(s) {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
283 setTimeout(function() {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
284 s.done();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
285 }, 1);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
286 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
287
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
288 function preread_data(s) {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
289 s.on('upload', function (data, flags) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
290 if (data.indexOf('z') != -1) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
291 s.done();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
292 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
293 });
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
294 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
295
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
296 var line = '';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
297
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
298 function preread_req_line(s) {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
299 s.on('upload', function (data, flags) {
1441
2e81f7788cf7 Tests: adapted stream_js.t to njs changes.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1375
diff changeset
300 var n = data.indexOf('\\n');
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
301 if (n != -1) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
302 line = data.substr(0, n);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
303 s.done();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
304 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
305 });
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
306 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
307
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
308 function req_line(s) {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
309 return line;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
310 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
311
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
312 function filter_empty(s) {
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
313 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
314
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
315 function filter_header_inject(s) {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
316 var req = '';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
317
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
318 s.on('upload', function(data, flags) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
319 req += data;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
320
1441
2e81f7788cf7 Tests: adapted stream_js.t to njs changes.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1375
diff changeset
321 var n = req.search('\\n');
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
322 if (n != -1) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
323 var rest = req.substr(n + 1);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
324 req = req.substr(0, n + 1);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
325
1441
2e81f7788cf7 Tests: adapted stream_js.t to njs changes.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1375
diff changeset
326 s.send(req + 'Foo: foo' + '\\r\\n' + rest, flags);
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
327
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
328 s.off('upload');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
329 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
330 });
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
331 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
332
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
333 function filter_search(s) {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
334 s.on('download', function(data, flags) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
335 var n = data.search('y');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
336 if (n != -1) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
337 s.send('z');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
338 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
339 });
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
340
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
341 s.on('upload', function(data, flags) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
342 var n = data.search('x');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
343 if (n != -1) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
344 s.send('y');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
345 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
346 });
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
347 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
348
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
349 function access_except(s) {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
350 function done() {return s.a.a};
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
351
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
352 setTimeout(done, 1);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
353 setTimeout(done, 2);
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
354 }
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
355
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
356 function preread_except(s) {
1248
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
357 var fs = require('fs');
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
358 fs.readFileSync();
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
359 }
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
360
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
361 function filter_except(s) {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
362 s.on('unknown', function() {});
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
363 }
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
364
1738
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
365 function pr(x) {
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
366 return new Promise(resolve => {resolve(x)}).then(v => v).then(v => v);
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
367 }
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
368
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
369 async function asyncf(s) {
1738
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
370 const a1 = await pr(10);
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
371 const a2 = await pr(20);
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
372
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
373 s.setReturnValue(`retval: \${a1 + a2}`);
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
374 }
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
375
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
376 export default {njs:test_njs, addr, variable, sess_unk, log, access_step,
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
377 preread_step, filter_step, access_undecided, access_allow,
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
378 access_deny, preread_async, preread_data, preread_req_line,
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
379 req_line, filter_empty, filter_header_inject, filter_search,
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
380 access_except, preread_except, filter_except, asyncf};
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
381
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
382 EOF
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
383
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
384 $t->run_daemon(\&stream_daemon, port(8090));
1738
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
385 $t->try_run('no stream njs available')->plan(23);
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
386 $t->waitforsocket('127.0.0.1:' . port(8090));
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
387
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
388 ###############################################################################
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
389
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
390 is(stream('127.0.0.1:' . port(8080))->read(), 'addr=127.0.0.1',
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
391 's.remoteAddress');
1237
e4974af3fb12 Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1005
diff changeset
392 is(dgram('127.0.0.1:' . port(8985))->io('.'), 'addr=127.0.0.1',
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
393 's.remoteAddress udp');
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
394 is(stream('127.0.0.1:' . port(8081))->read(), 'undefined', 's.log');
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
395 is(stream('127.0.0.1:' . port(8082))->read(), 'variable=127.0.0.1',
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
396 's.variables');
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
397 is(stream('127.0.0.1:' . port(8083))->read(), '', 'stream js unknown function');
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
398 is(stream('127.0.0.1:' . port(8084))->read(), 'sess_unk=undefined', 's.unk');
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
399
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
400 is(stream('127.0.0.1:' . port(8086))->io('0'), '0122345',
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
401 'async handlers order');
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
402 is(stream('127.0.0.1:' . port(8087))->io('#'), 'OK', 'access_undecided');
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
403 is(stream('127.0.0.1:' . port(8088))->io('#'), 'OK', 'access_allow');
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
404 is(stream('127.0.0.1:' . port(8089))->io('#'), '', 'access_deny');
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
405
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
406 is(stream('127.0.0.1:' . port(8091))->io('#'), '#', 'preread_async');
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
407 is(stream('127.0.0.1:' . port(8092))->io('#z'), '#z', 'preread_async_data');
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
408 is(stream('127.0.0.1:' . port(8093))->io("xy\na"), 'xy', 'preread_req_line');
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
409
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
410 is(stream('127.0.0.1:' . port(8094))->io('x'), 'x', 'filter_empty');
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
411 like(get('/p/return'), qr/foo/, 'filter_injected_header');
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
412 is(stream('127.0.0.1:' . port(8096))->io('x'), 'z', 'filter_search');
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
413
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
414 stream('127.0.0.1:' . port(8097))->io('x');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
415 stream('127.0.0.1:' . port(8098))->io('x');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
416 stream('127.0.0.1:' . port(8099))->io('x');
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
417
1738
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
418 TODO: {
1811
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
419 local $TODO = 'not yet' unless has_version('0.7.0');
1738
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
420
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
421 is(stream('127.0.0.1:' . port(8100))->read(), 'retval: 30', 'asyncf');
1738
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
422
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
423 }
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
424
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
425 $t->stop();
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
426
1315
890516ca898a Tests: reverted 3882f8f3b2bc to unbreak with njs 0.1.15.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1310
diff changeset
427 ok(index($t->read_file('error.log'), 'SEE-THIS') > 0, 'stream js log');
1248
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
428 ok(index($t->read_file('error.log'), 'at fs.readFileSync') > 0,
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
429 'stream js_preread backtrace');
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1738
diff changeset
430 ok(index($t->read_file('error.log'), 'at filter_except') > 0,
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
431 'stream js_filter backtrace');
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
432
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
433 my @p = (port(8087), port(8088), port(8089));
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
434 like($t->read_file('status.log'), qr/$p[0]:200/, 'status undecided');
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
435 like($t->read_file('status.log'), qr/$p[1]:200/, 'status allow');
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
436 like($t->read_file('status.log'), qr/$p[2]:403/, 'status deny');
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
437
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
438 ###############################################################################
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
439
1811
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
440 sub has_version {
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
441 my $need = shift;
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
442
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
443 get('/njs') =~ /^([.0-9]+)$/m;
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
444
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
445 my @v = split(/\./, $1);
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
446 my ($n, $v);
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
447
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
448 for $n (split(/\./, $need)) {
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
449 $v = shift @v || 0;
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
450 return 0 if $n > $v;
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
451 return 1 if $v > $n;
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
452 }
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
453
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
454 return 1;
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
455 }
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
456
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
457 ###############################################################################
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1751
diff changeset
458
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
459 sub stream_daemon {
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
460 my $server = IO::Socket::INET->new(
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
461 Proto => 'tcp',
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
462 LocalAddr => '127.0.0.1:' . port(8090),
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
463 Listen => 5,
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
464 Reuse => 1
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
465 )
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
466 or die "Can't create listening socket: $!\n";
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
467
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
468 local $SIG{PIPE} = 'IGNORE';
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
469
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
470 while (my $client = $server->accept()) {
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
471 $client->autoflush(1);
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
472
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
473 log2c("(new connection $client)");
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
474
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
475 $client->sysread(my $buffer, 65536) or next;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
476
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
477 log2i("$client $buffer");
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
478
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
479 log2o("$client $buffer");
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
480
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
481 $client->syswrite($buffer);
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
482
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
483 close $client;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
484 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
485 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
486
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
487 sub log2i { Test::Nginx::log_core('|| <<', @_); }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
488 sub log2o { Test::Nginx::log_core('|| >>', @_); }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
489 sub log2c { Test::Nginx::log_core('||', @_); }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
490
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
491 sub get {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
492 my ($url, %extra) = @_;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
493
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
494 my $s = IO::Socket::INET->new(
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
495 Proto => 'tcp',
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
496 PeerAddr => '127.0.0.1:' . port(8079)
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
497 ) or die "Can't connect to nginx: $!\n";
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
498
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
499 return http_get($url, socket => $s);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
500 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
501
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
502 ###############################################################################