view proxy_store.t @ 1974:b5036a0f9ae0 default tip

Tests: improved compatibility when using recent "openssl" app. Starting with OpenSSL 3.0, "openssl genrsa" generates encrypted keys in PKCS#8 format instead of previously used PKCS#1 format. Further, since OpenSSL 1.1.0 such keys are using PBKDF2 hmacWithSHA256. Such keys are not supported by old SSL libraries, notably by OpenSSL before 1.0.0 (OpenSSL 0.9.8 only supports hmacWithSHA1) and by BoringSSL before May 21, 2019 (support for hmacWithSHA256 was added in 302a4dee6c), and trying to load such keys into nginx compiled with an old SSL library results in "unsupported prf" errors. To facilitate testing with old SSL libraries, keys are now generated with "openssl genrsa -traditional" if the flag is available.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 06 May 2024 00:04:26 +0300
parents 882267679006
children
line wrap: on
line source

#!/usr/bin/perl

# (C) Maxim Dounin

# Tests for proxy_store functionality.

###############################################################################

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();

$t->write_file_expand('nginx.conf', <<'EOF')->has(qw/http proxy ssi/)->plan(9);

%%TEST_GLOBALS%%

daemon off;

events {
}

http {
    %%TEST_GLOBALS_HTTP%%

    server {
        listen       127.0.0.1:8080;
        server_name  localhost;

        location /store- {
            proxy_pass http://127.0.0.1:8080/;
            proxy_store on;
        }
        location /store-string- {
            proxy_pass http://127.0.0.1:8080/;
            proxy_store %%TESTDIR%%$uri;
        }
        location /ssi.html {
            ssi on;
        }
        location /index-big.html {
            limit_rate  200k;
        }
    }
}

EOF

$t->write_file('index.html', 'SEE-THIS');
$t->write_file('index-nostore.html', 'SEE-THIS');
$t->write_file('index-big.html', 'x' x (100 << 10));
$t->write_file('ssi.html',
	'<!--#include virtual="/store-index-big.html?1" -->' .
	'<!--#include virtual="/store-index-big.html?2" -->'
);
$t->run();

###############################################################################

like(http_get('/store-index.html'), qr/SEE-THIS/, 'proxy request');
ok(-e $t->testdir() . '/store-index.html', 'result stored');

like(http_get('/store-string-index.html'), qr/SEE-THIS/,
	'proxy string path request');
ok(-e $t->testdir() . '/store-string-index.html', 'string path result stored');

like(http_head('/store-index-nostore.html'), qr/200 OK/, 'head request');
ok(!-e $t->testdir() . '/store-index-nostore.html', 'result not stored');

ok(scalar @{[ glob $t->testdir() . '/proxy_temp/*' ]} == 0, 'no temp files');

http_get('/store-index-big.html', aborted => 1, sleep => 0.1);

select(undef, undef, undef, 0.5);
select(undef, undef, undef, 2.5)
	if scalar @{[ glob $t->testdir() . '/proxy_temp/*' ]};

ok(scalar @{[ glob $t->testdir() . '/proxy_temp/*' ]} == 0,
	'no temp files after aborted request');

http_get('/ssi.html', aborted => 1, sleep => 0.1);

select(undef, undef, undef, 0.5);
select(undef, undef, undef, 2.5)
	if scalar @{[ glob $t->testdir() . '/proxy_temp/*' ]};

ok(scalar @{[ glob $t->testdir() . '/proxy_temp/*' ]} == 0,
	'no temp files after aborted ssi');

###############################################################################