annotate post_action.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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
453
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
1 #!/usr/bin/perl
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
2
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
3 # (C) Maxim Dounin
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
4 # (C) Nginx, Inc.
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
5
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
6 # Tests for nginx post_action directive.
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
7
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
8 ###############################################################################
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
9
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
10 use warnings;
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
11 use strict;
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
12
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
13 use Test::More;
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
14
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
16
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
17 use lib 'lib';
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
18 use Test::Nginx;
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
19
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
20 ###############################################################################
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
22 select STDERR; $| = 1;
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
23 select STDOUT; $| = 1;
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
24
593
6c0a5903d0ae Tests: cleanup now duplicating tests for no alerts.
Sergey Kandaurov <pluknet@nginx.com>
parents: 548
diff changeset
25 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(5);
453
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
26
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
27 $t->write_file_expand('nginx.conf', <<'EOF');
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
28
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
29 %%TEST_GLOBALS%%
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
30
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
31 daemon off;
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
32
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
33 events {
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
34 }
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
35
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
36 http {
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
37 %%TEST_GLOBALS_HTTP%%
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
38
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
39 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
40 listen 127.0.0.1:8080;
453
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
41 server_name localhost;
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
42
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
43 location / {
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
44 post_action /post.html;
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
45 }
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
46
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
47 location /post.html {
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
48 # static
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
49 }
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
50
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
51 location /remote {
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
52 post_action /post.remote;
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
53 }
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
54
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
55 location /post.remote {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
56 proxy_pass http://127.0.0.1:8080/post.html;
453
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
57 }
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
58 }
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
59 }
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
60
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
61 EOF
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
62
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
63 $t->write_file('index.html', 'SEE-THIS');
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
64 $t->write_file('post.html', 'HIDDEN');
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
65 $t->write_file('remote', 'SEE-THIS');
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
66
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
67 $t->run();
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
68
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
69 ###############################################################################
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
70
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
71 like(http_get('/'), qr/SEE-THIS/m, 'post action');
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
72 unlike(http_get('/'), qr/HIDDEN/m, 'no additional body');
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
73
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
74 like(http_get('/remote'), qr/SEE-THIS/m, 'post action proxy');
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
75 unlike(http_get('/remote'), qr/HIDDEN/m, 'no additional body proxy');
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
76
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
77 $t->stop();
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
78
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
79 like(`cat ${\($t->testdir())}/access.log`, qr/post/, 'post action in logs');
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
80
baae3ed4ad09 Tests: post_action tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
81 ###############################################################################