Mercurial > hg > nginx-tests
annotate js_variables.t @ 1619:436d0ffc2ea3
Tests: correctly shutdown ssl for reproducible session reuse tests.
Previously, session reuse tests in stream_ssl_certificate.t were prone
to testing errors, since the client doesn't write any application data
before closing a connection, which is done so to pass tests on win32.
In this case, the server may happened to get an unexpected eof meaning
that it will abandon that session. This is specific to stream testing
pattern, changes to ssl_certificate.t are applied too for consistency.
This is also specific to SSL_R_UNEXPECTED_EOF_WHILE_READING, which is
implemented in OpenSSL 3.0.0.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 23 Nov 2020 22:46:06 +0000 |
parents | bc0990ea2e5b |
children | 18ac4d9e5a2a |
rev | line source |
---|---|
1442
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
2 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
3 # (C) Dmitry Volyntsev |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
5 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
6 # Tests for http njs module, setting nginx variables. |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
7 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
9 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
11 use strict; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
12 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
14 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
16 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
19 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
21 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
24 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http rewrite/) |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF'); |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
27 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
29 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
31 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
32 events { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
33 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
34 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
35 http { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
37 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
38 js_set $test_var test_var; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
39 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
40 js_include test.js; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
41 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
42 server { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
43 listen 127.0.0.1:8080; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
44 server_name localhost; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
45 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
46 set $foo foo_orig; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
47 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
48 location /var_set { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
49 return 200 $test_var$foo; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
50 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
51 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
52 location /content_set { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
53 js_content content_set; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
54 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
55 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
56 location /not_found_set { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
57 js_content not_found_set; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
58 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
59 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
60 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
61 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
62 EOF |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
63 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
64 $t->write_file('test.js', <<EOF); |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
65 function test_var(r) { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
66 r.variables.foo = r.variables.arg_a; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
67 return 'test_var'; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
68 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
69 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
70 function content_set(r) { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
71 r.variables.foo = r.variables.arg_a; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
72 r.return(200, r.variables.foo); |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
73 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
74 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
75 function not_found_set(r) { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
76 try { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
77 r.variables.unknown = 1; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
78 } catch (e) { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
79 r.return(500, e); |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
80 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
81 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
82 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
83 EOF |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
84 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
85 $t->try_run('no njs')->plan(3); |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
86 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
87 ############################################################################### |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
88 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
89 like(http_get('/var_set?a=bar'), qr/test_varbar/, 'var set'); |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
90 like(http_get('/content_set?a=bar'), qr/bar/, 'content set'); |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
91 like(http_get('/not_found_set'), qr/variable not found/, 'not found exception'); |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
92 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
93 ############################################################################### |