Mercurial > hg > nginx-tests
annotate gunzip_perl.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 | 882267679006 |
children |
rev | line source |
---|---|
231
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for gunzip filter module with perl module. |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx qw/ :DEFAULT :gzip /; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 eval { require IO::Compress::Gzip; }; |
773 | 25 plan(skip_all => "IO::Compress::Gzip not found") if $@; |
231
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http gunzip perl/)->plan(2) |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 ->write_file_expand('nginx.conf', <<'EOF'); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
231
diff
changeset
|
32 daemon off; |
231
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 events { |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 } |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 http { |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 %%TEST_GLOBALS_HTTP%% |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
41 listen 127.0.0.1:8080; |
231
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 server_name localhost; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 gunzip on; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 location / { |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 perl 'sub { |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 my $r = shift; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 $r->header_out("Content-Encoding", "gzip"); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 $r->send_http_header("text/plain"); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 return OK if $r->header_only; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 use IO::Compress::Gzip; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 my $in = "TEST"; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 my $out; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 IO::Compress::Gzip::gzip(\\$in => \\$out); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 $r->print($out); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 return OK; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 }'; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 } |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 } |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 } |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 EOF |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 $t->run(); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 ############################################################################### |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 http_gzip_like(http_gzip_request('/'), qr/TEST/, 'perl response gzipped'); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 like(http_get('/'), qr/TEST/, 'perl response gunzipped'); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 ############################################################################### |