Mercurial > hg > nginx-tests
annotate js_return.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 | 9bc1ca067449 |
children | bc0990ea2e5b |
rev | line source |
---|---|
1317
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
1375
f168fc46c7a4
Tests: renamed JavaScript to njs.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1320
diff
changeset
|
6 # Tests for http njs module, return method. |
1317
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
1320
8bd4b88fcac5
Tests: TODO js_return.t fail seen with older njs on some platforms.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1317
diff
changeset
|
15 use Config; |
8bd4b88fcac5
Tests: TODO js_return.t fail seen with older njs on some platforms.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1317
diff
changeset
|
16 |
1317
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 ############################################################################### |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDERR; $| = 1; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http/) |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 ->write_file_expand('nginx.conf', <<'EOF'); |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 daemon off; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 events { |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 } |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 http { |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 %%TEST_GLOBALS_HTTP%% |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 js_include test.js; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 server { |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 listen 127.0.0.1:8080; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 server_name localhost; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
1320
8bd4b88fcac5
Tests: TODO js_return.t fail seen with older njs on some platforms.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1317
diff
changeset
|
46 location /njs { |
8bd4b88fcac5
Tests: TODO js_return.t fail seen with older njs on some platforms.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1317
diff
changeset
|
47 js_content test_njs; |
8bd4b88fcac5
Tests: TODO js_return.t fail seen with older njs on some platforms.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1317
diff
changeset
|
48 } |
8bd4b88fcac5
Tests: TODO js_return.t fail seen with older njs on some platforms.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1317
diff
changeset
|
49 |
1317
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 location / { |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 js_content test_return; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 } |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 } |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 } |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 EOF |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 $t->write_file('test.js', <<EOF); |
1436
9d8b100a6ce3
Tests: get rid of deprecated njs API in 0.2.2.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1375
diff
changeset
|
59 function test_njs(r) { |
9d8b100a6ce3
Tests: get rid of deprecated njs API in 0.2.2.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1375
diff
changeset
|
60 r.return(200, njs.version); |
1320
8bd4b88fcac5
Tests: TODO js_return.t fail seen with older njs on some platforms.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1317
diff
changeset
|
61 } |
8bd4b88fcac5
Tests: TODO js_return.t fail seen with older njs on some platforms.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1317
diff
changeset
|
62 |
1436
9d8b100a6ce3
Tests: get rid of deprecated njs API in 0.2.2.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1375
diff
changeset
|
63 function test_return(r) { |
9d8b100a6ce3
Tests: get rid of deprecated njs API in 0.2.2.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1375
diff
changeset
|
64 r.return(Number(r.args.c), r.args.t); |
1317
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 } |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 EOF |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 $t->try_run('no njs return')->plan(5); |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 ############################################################################### |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 like(http_get('/?c=200'), qr/200 OK.*\x0d\x0a?\x0d\x0a?$/s, 'return code'); |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 like(http_get('/?c=200&t=SEE-THIS'), qr/200 OK.*^SEE-THIS$/ms, 'return text'); |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 like(http_get('/?c=301&t=path'), qr/ 301 .*Location: path/s, 'return redirect'); |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 like(http_get('/?c=404'), qr/404 Not.*html/s, 'return error page'); |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 like(http_get('/?c=inv'), qr/ 500 /, 'return invalid'); |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 ############################################################################### |