Mercurial > hg > nginx-tests
annotate stream_js_variables.t @ 1847:a9704b9ed7a2
Tests: removed multiple server certificates from ssl_ocsp.t.
Multiple server certificates are not needed to test OCSP verification of
client certificates (in contrast to OCSP stapling, where server certificates
are verified, and different staples should be correctly returned with
different server certificates). And using multiple server certificates
causes issues when testing with LibreSSL due to broken sigalgs-based
server certificate selection in LibreSSL with TLSv1.3.
Accordingly, the test is simplified to do not use multiple server
certificates.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 23 Mar 2023 19:50:26 +0300 |
parents | 18ac4d9e5a2a |
children |
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 stream 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 use Test::Nginx::Stream qw/ stream /; |
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 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
25 |
1614
bc0990ea2e5b
Tests: js TODO adjusted up to 0.4.0.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1609
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/stream stream_return/) |
1442
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
27 ->write_file_expand('nginx.conf', <<'EOF'); |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
28 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
30 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
32 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
33 events { |
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 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
36 stream { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1558
diff
changeset
|
37 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1558
diff
changeset
|
38 |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
39 js_set $test_var test.variable; |
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
40 js_set $test_not_found test.not_found; |
1442
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
41 |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
42 js_import test.js; |
1442
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
43 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
44 server { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
45 listen 127.0.0.1:8081; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
46 return $test_var$status; |
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 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
49 server { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
50 listen 127.0.0.1:8082; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
51 return $test_not_found; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
52 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
53 } |
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 EOF |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
56 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
57 $t->write_file('test.js', <<EOF); |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
58 function variable(s) { |
1442
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
59 s.variables.status = 400; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
60 return 'test_var'; |
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 |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
63 function not_found(s) { |
1442
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
64 try { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
65 s.variables.unknown = 1; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
66 } catch (e) { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
67 return 'not_found'; |
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 |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
71 export default {variable, not_found}; |
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
72 |
1442
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
73 EOF |
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 $t->try_run('no stream njs available')->plan(2); |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
76 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
77 ############################################################################### |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
78 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
79 is(stream('127.0.0.1:' . port(8081))->read(), 'test_var400', 'var set'); |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
80 is(stream('127.0.0.1:' . port(8082))->read(), 'not_found', 'not found set'); |
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 $t->stop(); |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
83 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
84 ############################################################################### |