Mercurial > hg > nginx-tests
annotate js_paths.t @ 1836:74cffa9d4c43
Tests: enabled session reuse via TLS session tickets.
This fixes tests with TLSv1.3 enabled when using BoringSSL, since
for TLSv1.3 it only supports session reuse via TLS session tickets,
and not server-side session cache.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 23 Mar 2023 19:50:02 +0300 |
parents | 18ac4d9e5a2a |
children |
rev | line source |
---|---|
1456
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
2 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
3 # (C) Dmitry Volyntsev |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
5 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
6 # Tests for http njs module, js_path directive. |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
7 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
9 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
11 use strict; |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
12 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
14 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
16 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
19 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
21 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
24 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http/) |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF'); |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
27 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
29 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
31 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
32 events { |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
33 } |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
34 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
35 http { |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
37 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
38 js_path "%%TESTDIR%%/lib1"; |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
39 js_path "lib2"; |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
40 |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
41 js_import test.js; |
1456
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
42 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
43 server { |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
44 listen 127.0.0.1:8080; |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
45 server_name localhost; |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
46 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
47 location /test { |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
48 js_content test.test; |
1456
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
49 } |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
50 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
51 location /test2 { |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
52 js_content test.test2; |
1456
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
53 } |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
54 } |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
55 } |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
56 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
57 EOF |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
58 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
59 $t->write_file('test.js', <<EOF); |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
60 import m1 from 'module1.js'; |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
61 import m2 from 'module2.js'; |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
62 import m3 from 'lib1/module1.js'; |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
63 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
64 function test(r) { |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
65 r.return(200, m1[r.args.fun](r.args.a, r.args.b)); |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
66 } |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
67 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
68 function test2(r) { |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
69 r.return(200, m2.sum(r.args.a, r.args.b)); |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
70 } |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
71 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
72 function test3(r) { |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
73 r.return(200, m3.sum(r.args.a, r.args.b)); |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
74 } |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
75 |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
76 export default {test, test2}; |
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
77 |
1456
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
78 EOF |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
79 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
80 my $d = $t->testdir(); |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
81 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
82 mkdir("$d/lib1"); |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
83 mkdir("$d/lib2"); |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
84 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
85 $t->write_file('lib1/module1.js', <<EOF); |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
86 function sum(a, b) { return Number(a) + Number(b); } |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
87 function prod(a, b) { return Number(a) * Number(b); } |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
88 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
89 export default {sum, prod}; |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
90 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
91 EOF |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
92 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
93 $t->write_file('lib2/module2.js', <<EOF); |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
94 function sum(a, b) { return a + b; } |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
95 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
96 export default {sum}; |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
97 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
98 EOF |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
99 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
100 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
101 $t->try_run('no njs available')->plan(4); |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
102 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
103 ############################################################################### |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
104 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
105 like(http_get('/test?fun=sum&a=3&b=4'), qr/7/s, 'test sum'); |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
106 like(http_get('/test?fun=prod&a=3&b=4'), qr/12/s, 'test prod'); |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
107 like(http_get('/test2?a=3&b=4'), qr/34/s, 'test2'); |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
108 like(http_get('/test2?a=A&b=B'), qr/AB/s, 'test2 relative'); |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
109 |
f4ae08adc23f
Tests: added njs modules tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
110 ############################################################################### |