annotate geo_binary.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 1fe8d33f75ad
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1044
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Andrey Zelenkov
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for nginx geo module with binary base.
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 ###############################################################################
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 select STDERR; $| = 1;
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDOUT; $| = 1;
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25 plan(skip_all => 'long configuration parsing') unless $ENV{TEST_NGINX_UNSAFE};
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 my $t = Test::Nginx->new()->has(qw/http geo/);
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 $t->write_file_expand('nginx.conf', <<'EOF');
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 %%TEST_GLOBALS%%
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 daemon off;
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 events {
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 }
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 http {
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 %%TEST_GLOBALS_HTTP%%
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 geo $geo_base_create {
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 ranges;
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 include base.conf;
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 }
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 geo $geo_base_include {
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 ranges;
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 include base.conf;
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 }
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 server {
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 listen 127.0.0.1:8080;
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 server_name localhost;
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 location / {
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 add_header X-IP $remote_addr;
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 add_header X-GBc $geo_base_create;
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 add_header X-GBi $geo_base_include;
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 }
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 }
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 }
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 EOF
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 $t->write_file('1', '');
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 $t->write_file('base.conf', join('', map {
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 "127." . $_/256/256 % 256 . "." . $_/256 % 256 . "." . $_ % 256 .
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 "-127." . $_/256/256 % 256 . "." . $_/256 % 256 . "." .$_ % 256 . " " .
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 ($_ == 1 ? "loopback" : "range$_") . ";" } (0 .. 100000)));
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 $t->run();
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 plan(skip_all => 'no 127.0.0.1 on host')
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 if http_get('/1') !~ /X-IP: 127.0.0.1/m;
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 $t->plan(2);
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 ###############################################################################
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 my $r = http_get('/1');
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 like($r, qr/^X-GBc: loopback/m, 'geo binary base create');
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 like($r, qr/^X-GBi: loopback/m, 'geo binary base include');
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83
1fe8d33f75ad Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 ###############################################################################