Mercurial > hg > nginx-tests
annotate js_internal_redirect.t @ 1571:1b4ceab9cb1c
Tests: fixed ssl_certificate.t with LibreSSL client.
Net::SSLeay::connect() that manages TLS handshake could return unexpected
error when receiving server alert, as seen in server certificate tests if
it could not been selected. Typically, it returns the expected error -1,
but with certain libssl implementations it can be 0, as explained below.
The error is propagated from libssl's SSL_connect(), which is usually -1.
In modern OpenSSL versions, it is the default error code used in the state
machine returned when something went wrong with parsing TLS message header.
In versions up to OpenSSL 1.0.2, with SSLv23_method() used by default, -1
is the only error code in the ssl_connect() method implementation which is
used as well if receiving alert while parsing ServerHello. BoringSSL also
seems to return -1. But it is not so with LibreSSL that returns zero.
Previously, tests failed with client built with LibreSSL with SSLv3 removed.
Here, the error is propagated directly from ssl_read_bytes() method, which
is always implemented as ssl3_read_bytes() in all TLS methods. It could be
also seen with OpenSSL up to 1.0.2 with non-default methods explicitly set.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 29 May 2020 23:10:20 +0300 |
parents | 9521130f6f22 |
children | a7902e5adeab |
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 | 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 | 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 | 72 req.internalRedirect('\@named'); |
1343
2ff483941037
Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
73 |
1345 | 74 } else { |
75 if (req.variables.arg_a) { | |
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 | 78 } else { |
79 req.internalRedirect('/redirect'); | |
80 } | |
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 |
2ff483941037
Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
90 like(http_get('/test'), qr/redirect/s, 'redirect'); |
2ff483941037
Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
91 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
|
92 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
|
93 |
2ff483941037
Tests: added njs http internalRedirect() method tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
94 ############################################################################### |