Mercurial > hg > nginx-tests
view autoindex_format.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 | 81579df2ba8c |
children |
line wrap: on
line source
#!/usr/bin/perl # (C) Maxim Dounin # (C) Sergey Kandaurov # (C) Nginx, Inc. # Tests for autoindex module with autoindex_format directive. ############################################################################### use warnings; use strict; use Test::More; BEGIN { use FindBin; chdir($FindBin::Bin); } use lib 'lib'; use Test::Nginx; ############################################################################### select STDERR; $| = 1; select STDOUT; $| = 1; my $t = Test::Nginx->new()->has(qw/http autoindex symlink/)->plan(37) ->write_file_expand('nginx.conf', <<'EOF'); %%TEST_GLOBALS%% daemon off; events { } http { %%TEST_GLOBALS_HTTP%% server { listen 127.0.0.1:8080; server_name localhost; autoindex on; location /xml/ { autoindex_format xml; alias %%TESTDIR%%/; } location /json/ { autoindex_format json; alias %%TESTDIR%%/; } location /jsonp/ { autoindex_format jsonp; alias %%TESTDIR%%/; } } } EOF my $d = $t->testdir(); mkdir("$d/test-dir"); symlink("$d/test-dir", "$d/test-dir-link"); $t->write_file('test-file', 'x' x 42); symlink("$d/test-file", "$d/test-file-link"); $t->write_file('test-\'-quote', ''); $t->write_file('test-"-double', ''); $t->write_file('test-<>-angle', ''); mkdir($d . '/utf8'); $t->write_file('utf8/test-utf8-' . ("\xd1\x84" x 3), ''); $t->write_file('utf8/test-utf8-' . ("\xd1\x84" x 45), ''); $t->run(); ############################################################################### my ($r, $mtime, $data); $r = http_get('/xml/'); $mtime = qr/mtime="\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ"/; like($r, qr!Content-Type: text/xml; charset=utf-8!, 'xml content type'); like($r, qr!<file(\s+\w+="[^=]*?")+\s*>test-file</file>!, 'xml file format'); like($r, qr!<directory(\s+\w+="[^=]*?")+\s*>test-dir</directory>!, 'xml dir format'); ($data) = $r =~ qr!<file\s+(.*?)>test-file</file>!; like($data, $mtime, 'xml file mtime'); like($data, qr!size="42"!, 'xml file size'); ($data) = $r =~ qr!<file\s+(.*?)>test-file-link</file>!; like($data, $mtime, 'xml file link mtime'); like($data, qr!size="42"!, 'xml file link size'); ($data) = $r =~ qr!<directory\s+(.*?)>test-dir</directory>!; like($data, $mtime, 'xml dir mtime'); unlike($data, qr!size="\d+"!, 'xml dir size'); ($data) = $r =~ qr!<directory\s+(.*?)>test-dir-link</directory>!; like($data, $mtime, 'xml dir link mtime'); unlike($data, qr!size="\d+"!, 'xml dir link size'); like($r, qr!<file.*?>test-\'-quote</file>!, 'xml quote'); like($r, qr!<file.*?>test-\"-double</file>!, 'xml double'); like($r, qr!<file.*?>test-<>-angle</file>!, 'xml angle'); $r = http_get('/json/'); $mtime = qr/"mtime"\s*:\s*"\w{3}, \d\d \w{3} \d{4} \d\d:\d\d:\d\d \w{3}"/; my $string = qr!"(?:[^\\"]+|\\["\\/bfnrt])*"!; my $number = qr!-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][-+]?\d+)?!; my $kv = qr!\s*$string\s*:\s*($string|$number)\s*!; like($r, qr!Content-Type: application/json!, 'json content type'); like($r, qr!{$kv(,$kv)*}!, 'json format'); ($data) = $r =~ qr!(\{[^}]*?"name"\s*:\s*"test-file".*?})!; like($data, qr!"type"\s*:\s*"file"!, 'json file'); like($data, $mtime, 'json file mtime'); like($data, qr!"size"\s*:\s*42!, 'json file size'); ($data) = $r =~ qr!(\{[^}]*?"name"\s*:\s*"test-file-link".*?})!; like($data, qr!"type"\s*:\s*"file"!, 'json file link'); like($data, $mtime, 'json file link mtime'); like($data, qr!"size"\s*:\s*42!, 'json file link size'); ($data) = $r =~ qr!(\{[^}]*?"name"\s*:\s*"test-dir".*?})!; like($data, qr!"type"\s*:\s*"directory"!, 'json dir'); like($data, $mtime, 'json dir mtime'); unlike($data, qr!"size"\s*:\s*$number!, 'json dir size'); ($data) = $r =~ qr!(\{[^}]*?"name"\s*:\s*"test-dir-link".*?})!; like($data, qr!"type"\s*:\s*"directory"!, 'json dir link'); like($data, $mtime, 'json dir link mtime'); unlike($data, qr!"size"\s*:\s*$number!, 'json dir link size'); like($r, qr!"name"\s*:\s*"test-'-quote"!, 'json quote'); like($r, qr!"name"\s*:\s*"test-\\\"-double"!, 'json double'); like($r, qr!"name"\s*:\s*"test-<>-angle"!, 'json angle'); like(http_get_body('/jsonp/test-dir/?callback=foo'), qr/^\s*foo\s*\(\s*\[\s*\]\s*\)\s*;\s*$/ms, 'jsonp callback'); like(http_get_body('/jsonp/test-dir/?callback='), qr/^\s*\[\s*\s*\]\s*$/ms, 'jsonp callback empty'); # utf8 tests $r = http_get('/xml/utf8/'); like($r, qr!test-utf8-(\xd1\x84){3}</file>!ms, 'xml utf8'); like($r, qr!test-utf8-(\xd1\x84){45}</file>!ms, 'xml utf8 long'); $r = http_get('/json/utf8/'); like($r, qr!test-utf8-(\xd1\x84){3}"!ms, 'json utf8'); like($r, qr!test-utf8-(\xd1\x84){45}"!ms, 'json utf8 long'); ############################################################################### sub http_get_body { my ($uri) = @_; return undef if !defined $uri; http_get($uri) =~ /(.*?)\x0d\x0a?\x0d\x0a?(.*)/ms; return $2; } ###############################################################################