Mercurial > hg > nginx-tests
annotate js_dump.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 | 96fb3513345b |
children | bc0990ea2e5b |
rev | line source |
---|---|
1534
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
2 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
3 # (C) Dmitry Volyntsev |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
5 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
6 # Tests for http njs module, request object dump. |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
7 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
9 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
11 use strict; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
12 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
14 use Socket qw/ CRLF /; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
15 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
16 BEGIN { use FindBin; chdir($FindBin::Bin); } |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
17 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
18 use lib 'lib'; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
20 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
22 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
25 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http rewrite/) |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
27 ->write_file_expand('nginx.conf', <<'EOF'); |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
28 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
30 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
32 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
33 events { |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
34 } |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
35 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
36 http { |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
38 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
39 js_include test.js; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
40 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
41 server { |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
42 listen 127.0.0.1:8080; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
43 server_name localhost; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
44 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
45 location /njs { |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
46 js_content test_njs; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
47 } |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
48 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
49 location /dump { |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
50 js_content test_dump; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
51 } |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
52 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
53 location /stringify { |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
54 js_content test_stringify; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
55 } |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
56 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
57 location /stringify_subrequest { |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
58 js_content test_stringify_subrequest; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
59 } |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
60 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
61 location /js_sub { |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
62 return 201 '{$request_method}'; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
63 } |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
64 } |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
65 } |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
66 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
67 EOF |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
68 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
69 $t->write_file('test.js', <<EOF); |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
70 function test_njs(r) { |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
71 r.return(200, njs.version); |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
72 } |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
73 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
74 function test_dump(r) { |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
75 r.headersOut.baz = 'bar'; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
76 r.return(200, njs.dump(r)); |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
77 } |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
78 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
79 function test_stringify(r) { |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
80 r.headersOut.baz = 'bar'; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
81 var obj = JSON.parse(JSON.stringify(r)); |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
82 r.return(200, JSON.stringify(obj)); |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
83 } |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
84 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
85 function test_stringify_subrequest(r) { |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
86 r.subrequest('/js_sub', reply => { |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
87 r.return(200, JSON.stringify(reply)) |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
88 }); |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
89 } |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
90 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
91 EOF |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
92 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
93 $t->try_run('no njs dump')->plan(3); |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
94 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
95 ############################################################################### |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
96 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
97 TODO: { |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
98 local $TODO = 'not yet' |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
99 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.3.8'; |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
100 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
101 like(http( |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
102 'GET /dump?v=1&t=x HTTP/1.0' . CRLF |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
103 . 'Foo: bar' . CRLF |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
104 . 'Foo2: bar2' . CRLF |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
105 . 'Host: localhost' . CRLF . CRLF |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
106 ), qr/method:'GET'/, 'njs.dump(r)'); |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
107 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
108 like(http( |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
109 'GET /stringify?v=1&t=x HTTP/1.0' . CRLF |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
110 . 'Foo: bar' . CRLF |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
111 . 'Foo2: bar2' . CRLF |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
112 . 'Host: localhost' . CRLF . CRLF |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
113 ), qr/headersOut":\{"baz":"bar"}/, 'JSON.stringify(r)'); |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
114 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
115 like(http( |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
116 'GET /stringify_subrequest HTTP/1.0' . CRLF |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
117 . 'Host: localhost' . CRLF . CRLF |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
118 ), qr/responseBody":"\{GET}"/, 'JSON.stringify(reply)'); |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
119 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
120 } |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
121 |
96fb3513345b
Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
122 ############################################################################### |