[PATCH 3 of 7] Tests: try_files with alias additional tests

Maxim Dounin mdounin at mdounin.ru
Fri Apr 17 22:50:22 UTC 2026


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1776466165 -10800
#      Sat Apr 18 01:49:25 2026 +0300
# Node ID 1b0215d2bf862ceabc938de20e9e65d025d39a3d
# Parent  764b07be5a74047456643df286ffb0b9149bcea4
Tests: try_files with alias additional tests.

diff --git a/http_try_files.t b/http_try_files.t
--- a/http_try_files.t
+++ b/http_try_files.t
@@ -21,7 +21,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(12)
+my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(17)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
@@ -95,6 +95,34 @@ http {
                 try_files $uri =404;
             }
         }
+
+        location /alias-static/ {
+            alias %%TESTDIR%%/;
+            try_files /alias-static/found.html =404;
+        }
+
+        location /alias-vars/ {
+            alias %%TESTDIR%%/;
+            set $file /alias-vars/found.html;
+            try_files $file =404;
+        }
+
+        location /alias-fallback-static/ {
+            alias %%TESTDIR%%/;
+            try_files $uri /alias-fallback-static/found.html;
+        }
+
+        location /alias-fallback-vars/ {
+            alias %%TESTDIR%%/;
+            set $fallback /alias-fallback-vars/found.html;
+            try_files $uri $fallback;
+        }
+
+        location /alias-caseless/ {
+            alias %%TESTDIR%%/;
+            set $file /alias-caseless/found.html;
+            try_files $file =404;
+        }
     }
 
     server {
@@ -143,4 +171,47 @@ like(http_get('/alias-re-prefix/found'),
 like(http_get('/alias-nested/found.html'), qr!SEE THIS!,
 	'alias with nested location');
 
+# when a file matches location prefix covered by alias,
+# prefix needs to be removed; this used to work only with
+# variables, but not with static strings
+
+TODO: {
+local $TODO = 'not yet' unless $t->has_version('1.31.0');
+
+like(http_get('/alias-static/found.html'), qr!SEE THIS!,
+	'alias with static string');
+
+}
+
+like(http_get('/alias-vars/found.html'), qr!SEE THIS!,
+	'alias with variables');
+
+# in contrast, for the fallback URI we don't need to remove
+# anything (yet it was removed with variables)
+
+like(http_get('/alias-fallback-static/notfound'), qr!SEE THIS!,
+	'alias fallback to matching static string');
+
+TODO: {
+local $TODO = 'not yet' unless $t->has_version('1.31.0');
+
+like(http_get('/alias-fallback-vars/notfound'), qr!SEE THIS!,
+	'alias fallback to matching string with variables');
+
+}
+
+# with caseless systems, aliased prefix needs to be checked in a
+# case-insensitive way; this automatically happens with "try_files $uri",
+# since aliased prefix is compared to the original request URI, but was
+# not working with configuration-provided paths
+
+SKIP: {
+skip 'not caseless os', 1
+	unless $^O eq 'MSWin32' or $^O eq 'darwin';
+local $TODO = 'not yet' unless $t->has_version('1.31.0');
+
+like(http_get('/alias-CASELESS/found.html'), qr!SEE THIS!, 'alias caseless');
+
+}
+
 ###############################################################################



More information about the nginx-devel mailing list