Mercurial > hg > nginx-tests
annotate js_variables.t @ 1851:0351dee227a8
Tests: unbreak tests with dynamic certificates on stable.
In 74cffa9d4c43, ticket based session reuse is enabled in addition to
using a shared SSL session cache. This changed how a session can be
resumed in a different server:
- for a session ID based resumption, it is resumed in the same context
- when using session tickets, a key name is also checked for matching
- with a ticket callback, this is skipped in favor of callback's logic
This makes 'session id context match' tests fail with session tickets
on stable since ticket key names are unique in distinct SSL contexts.
On the other hand, tests pass on 1.23.2+ due to automatic ticket keys
rotation that installs ticket callback, and using a common shared SSL
session cache.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 28 Mar 2023 01:36:32 +0400 |
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 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 |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
38 js_set $test_var test.variable; |
1442
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
39 |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
40 js_import test.js; |
1442
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 |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
46 set $foo test.foo_orig; |
1442
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 { |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
53 js_content test.content_set; |
1442
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 { |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
57 js_content test.not_found_set; |
1442
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); |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
65 function variable(r) { |
1442
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 |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
83 export default {variable, content_set, not_found_set}; |
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
84 |
1442
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
85 EOF |
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 $t->try_run('no njs')->plan(3); |
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 ############################################################################### |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
90 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
91 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
|
92 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
|
93 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
|
94 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
95 ############################################################################### |