Mercurial > hg > nginx-tests
annotate js_request_body.t @ 1553:01867708af95
Tests: adjusted todo_alerts() in js_subrequest.t.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Mon, 02 Mar 2020 19:46:52 +0300 |
parents | 9521130f6f22 |
children | a7902e5adeab |
rev | line source |
---|---|
1322
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
2 |
1342
5833f3b7a884
Tests: adapted js_request_body.t for renamed property.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1322
diff
changeset
|
3 # (C) Dmitry Volyntsev |
1322
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
5 |
1342
5833f3b7a884
Tests: adapted js_request_body.t for renamed property.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1322
diff
changeset
|
6 # Tests for http njs module, req.requestBody method. |
1322
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
7 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
9 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
11 use strict; |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
12 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
14 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
15 use Socket qw/ CRLF /; |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
16 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
18 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
21 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
22 ############################################################################### |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
23 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
24 select STDERR; $| = 1; |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
26 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http/) |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
28 ->write_file_expand('nginx.conf', <<'EOF'); |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
29 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
31 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
32 daemon off; |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
33 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
34 events { |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
35 } |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
36 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
37 http { |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
38 %%TEST_GLOBALS_HTTP%% |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
39 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
40 js_include test.js; |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
41 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
42 server { |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
43 listen 127.0.0.1:8080; |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
44 server_name localhost; |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
45 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
46 location /njs { |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
47 js_content test_njs; |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
48 } |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
49 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
50 location /body { |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
51 js_content test_body; |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
52 } |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
53 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
54 location /in_file { |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
55 client_body_in_file_only on; |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
56 js_content test_body; |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
57 } |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
58 } |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
59 } |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
60 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
61 EOF |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
62 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
63 $t->write_file('test.js', <<EOF); |
1342
5833f3b7a884
Tests: adapted js_request_body.t for renamed property.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1322
diff
changeset
|
64 function test_njs(r) { |
5833f3b7a884
Tests: adapted js_request_body.t for renamed property.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1322
diff
changeset
|
65 r.return(200, njs.version); |
1322
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
66 } |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
67 |
1342
5833f3b7a884
Tests: adapted js_request_body.t for renamed property.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1322
diff
changeset
|
68 function test_body(r) { |
1322
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
69 try { |
1342
5833f3b7a884
Tests: adapted js_request_body.t for renamed property.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1322
diff
changeset
|
70 var body = r.requestBody; |
5833f3b7a884
Tests: adapted js_request_body.t for renamed property.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1322
diff
changeset
|
71 r.return(200, body); |
1322
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
72 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
73 } catch (e) { |
1342
5833f3b7a884
Tests: adapted js_request_body.t for renamed property.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1322
diff
changeset
|
74 r.return(500, e.message); |
1322
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
75 } |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
76 } |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
77 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
78 EOF |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
79 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
80 $t->try_run('no njs request body')->plan(3); |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
81 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
82 ############################################################################### |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
83 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
84 like(http_post('/body'), qr/REQ-BODY/, 'request body'); |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
85 like(http_post('/in_file'), qr/request body is in a file/, |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
86 'request body in file'); |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
87 like(http_post_big('/body'), qr/200.*^(1234567890){1024}$/ms, |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
88 'request body big'); |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
89 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
90 ############################################################################### |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
91 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
92 sub http_post { |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
93 my ($url, %extra) = @_; |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
94 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
95 my $p = "POST $url HTTP/1.0" . CRLF . |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
96 "Host: localhost" . CRLF . |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
97 "Content-Length: 8" . CRLF . |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
98 CRLF . |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
99 "REQ-BODY"; |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
100 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
101 return http($p, %extra); |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
102 } |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
103 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
104 sub http_post_big { |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
105 my ($url, %extra) = @_; |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
106 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
107 my $p = "POST $url HTTP/1.0" . CRLF . |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
108 "Host: localhost" . CRLF . |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
109 "Content-Length: 10240" . CRLF . |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
110 CRLF . |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
111 ("1234567890" x 1024); |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
112 |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
113 return http($p, %extra); |
d6daf03478ad
Tests: added njs request body tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
114 } |
1451 | 115 |
116 ############################################################################### |