annotate js_internal_redirect.t @ 1477:8b122b35703b

Tests: fixed session reuse tests in ssl_certificate.t with TLSv1.3. Previously, session data was retrieved too early, before server passed application data, which usually means NewSessionTicket is not yet sent. The fix is to ask server for application data, then retrieve a session.
author Sergey Kandaurov <pluknet@nginx.com>
date Mon, 20 May 2019 16:00:40 +0300
parents 533d31d5057e
children 9521130f6f22
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1343
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
2
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
3 # (C) Dmitry Volyntsev
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
5
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
6 # Tests for http njs module, internalRedirect method.
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
7
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
8 ###############################################################################
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
9
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
10 use warnings;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
11 use strict;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
12
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
13 use Test::More;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
14
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
16
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
17 use lib 'lib';
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
19
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
20 ###############################################################################
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
21
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
22 select STDERR; $| = 1;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
23 select STDOUT; $| = 1;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
24
1347
106d9f806288 Tests: js_internal_redirect.t cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1346
diff changeset
25 my $t = Test::Nginx->new()->has(qw/http rewrite/)
1343
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
26 ->write_file_expand('nginx.conf', <<'EOF');
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
27
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
28 %%TEST_GLOBALS%%
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
29
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
30 daemon off;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
31
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
32 events {
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
33 }
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
34
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
35 http {
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
36 %%TEST_GLOBALS_HTTP%%
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
37
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
38 js_include test.js;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
39
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
40 server {
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
41 listen 127.0.0.1:8080;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
42 server_name localhost;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
43
1346
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
44 location /njs {
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
45 js_content test_njs;
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
46 }
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
47
1343
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
48 location /test {
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
49 js_content test_redirect;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
50 }
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
51
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
52 location /redirect {
1345
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
53 internal;
1343
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
54 return 200 redirect$arg_b;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
55 }
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
56
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
57 location @named {
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
58 return 200 named;
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
59 }
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
60 }
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
61 }
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
62
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
63 EOF
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
64
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
65 $t->write_file('test.js', <<EOF);
1346
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
66 function test_njs(r) {
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
67 r.return(200, njs.version);
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
68 }
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
69
1345
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
70 function test_redirect(req) {
1444
533d31d5057e Tests: adapted js_internal_redirect.t to njs changes.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1347
diff changeset
71 if (req.variables.arg_dest == 'named') {
1345
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
72 req.internalRedirect('\@named');
1343
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
73
1345
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
74 } else {
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
75 if (req.variables.arg_a) {
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
76 req.internalRedirect('/redirect?b=' + req.variables.arg_a);
1343
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
77
1345
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
78 } else {
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
79 req.internalRedirect('/redirect');
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
80 }
9fbe84b7ddc6 Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1343
diff changeset
81 }
1343
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
82 }
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
83
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
84 EOF
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
85
1346
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
86 $t->try_run('no njs available')->plan(3);
1343
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
87
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
88 ###############################################################################
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
89
1346
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
90 TODO: {
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
91 local $TODO = 'no njs internalRedirect'
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
92 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.2.2';
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
93
1343
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
94 like(http_get('/test'), qr/redirect/s, 'redirect');
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
95 like(http_get('/test?a=A'), qr/redirectA/s, 'redirect with args');
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
96 like(http_get('/test?dest=named'), qr/named/s, 'redirect to named location');
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
97
1346
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
98 }
4d5d1e59f45e Tests: TODO js_internal_redirect.t on njs < 0.2.2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1345
diff changeset
99
1343
2ff483941037 Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
100 ###############################################################################