[nginx-tests] Tests: access_log variable evaluation tests.
Maxim Dounin
mdounin at mdounin.ru
Fri Jun 19 20:41:45 UTC 2026
details: http://freenginx.org/hg/nginx-tests/rev/f0e7ac46c0d3
branches:
changeset: 2072:f0e7ac46c0d3
user: Maxim Dounin <mdounin at mdounin.ru>
date: Fri Jun 19 22:58:32 2026 +0300
description:
Tests: access_log variable evaluation tests.
The access log module uses its own script engine, which, however,
suffers from similar issues when trying to use variables with side
effects, or non-cacheable variables along with variables which use
ngx_http_script_run() and therefore flush all other non-cacheable
variables ($document_root, $realpath_root).
diffstat:
access_log_script.t | 96 ++++++++++++++++++++++++++++++++++++++++++++++
stream_access_log_script.t | 77 ++++++++++++++++++++++++++++++++++++
2 files changed, 173 insertions(+), 0 deletions(-)
diffs (183 lines):
diff --git a/access_log_script.t b/access_log_script.t
new file mode 100644
--- /dev/null
+++ b/access_log_script.t
@@ -0,0 +1,96 @@
+#!/usr/bin/perl
+
+# (C) Maxim Dounin
+
+# Tests for access_log, script execution.
+
+###############################################################################
+
+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 rewrite map/)->plan(2)
+ ->write_file_expand('nginx.conf', <<'EOF');
+
+%%TEST_GLOBALS%%
+
+daemon off;
+
+events {
+}
+
+http {
+ %%TEST_GLOBALS_HTTP%%
+
+ log_format map_capture "start $capture $map_capture end";
+ log_format map_volatile
+ "start $map_volatile $document_root $realpath_root end";
+
+ map $uri $map_capture {
+ ~(?<capture>.*) $capture;
+ }
+
+ map prefix:$capture $map_volatile {
+ volatile;
+ ~(?<capture>.*) $capture;
+ }
+
+ server {
+ listen 127.0.0.1:8080;
+ server_name localhost;
+
+ location /map {
+ access_log map.log map_capture;
+ }
+
+ location /map_volatile {
+ root html/$pid;
+ access_log map.log map_volatile;
+ }
+ }
+}
+
+EOF
+
+$t->run();
+
+###############################################################################
+
+TODO: {
+todo_skip 'might coredump', 2
+ unless $t->has_version('1.31.3')
+ or $ENV{TEST_NGINX_UNSAFE};
+local $TODO = 'not yet', $t->todo_alerts();
+
+# map with side effects might result in incorrect buffer size
+# and buffer overrun
+
+http_get('/map');
+
+# using a non-cacheable variable might result in incorrect buffer
+# size and buffer overrun
+
+http_get('/map_volatile');
+
+$t->stop();
+
+my $log = $t->read_file('map.log');
+
+like($log, qr!start /map /map end!, 'log and map with side effects');
+like($log, qr!start prefix: .* end!, 'log and volatile map');
+
+}
+
+###############################################################################
diff --git a/stream_access_log_script.t b/stream_access_log_script.t
new file mode 100644
--- /dev/null
+++ b/stream_access_log_script.t
@@ -0,0 +1,77 @@
+#!/usr/bin/perl
+
+# (C) Maxim Dounin
+
+# Stream tests for access_log, script execution.
+
+###############################################################################
+
+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/stream stream_map stream_return http rewrite/)->plan(1)
+ ->write_file_expand('nginx.conf', <<'EOF');
+
+%%TEST_GLOBALS%%
+
+daemon off;
+
+events {
+}
+
+stream {
+ %%TEST_GLOBALS_STREAM%%
+
+ log_format map_capture "start $capture $map_capture end";
+
+ map $pid $map_capture {
+ ~(?<capture>.*) $capture;
+ }
+
+ server {
+ listen 127.0.0.1:8080;
+ return ok;
+
+ access_log map.log map_capture;
+ }
+}
+
+EOF
+
+$t->run();
+
+###############################################################################
+
+TODO: {
+todo_skip 'might coredump', 1
+ unless $t->has_version('1.31.3')
+ or $ENV{TEST_NGINX_UNSAFE};
+local $TODO = 'not yet', $t->todo_alerts();
+
+# map with side effects might result in incorrect buffer size
+# and buffer overrun
+
+http_get('/');
+
+$t->stop();
+
+my $log = $t->read_file('map.log');
+
+like($log, qr!start /map /map end!, 'log and map with side effects');
+
+}
+
+###############################################################################
More information about the nginx-devel
mailing list