add fs and try_files tests

Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com>
This commit is contained in:
Mohammed Al Sahaf 2026-06-06 22:26:11 +03:00
parent d193d7fb0f
commit 7a9ce91986
No known key found for this signature in database
3 changed files with 212 additions and 0 deletions

View file

@ -0,0 +1,95 @@
# Spec: fs directive — selects which named filesystem to use for file_server etc.
# Only the "default" (OS) filesystem is available without external plugins.
# These tests verify the directive parses, is applied conditionally, and does
# not interfere with file_server resolving files from the configured root.
# Configure Caddy with explicit default filesystem
POST http://localhost:2019/load
Content-Type: text/caddyfile
```
{
skip_install_trust
http_port 9080
https_port 9443
local_certs
}
localhost {
root * {{indexed_root}}
fs default
file_server
}
```
HTTP 200
# PROPERTY: `fs default` selects the OS-backed filesystem and serves files normally
GET https://localhost:9443/index.txt
[Options]
insecure: true
HTTP 200
[Asserts]
body == "index.txt"
# PROPERTY: default filesystem honors index files for directory requests
GET https://localhost:9443/
[Options]
insecure: true
HTTP 200
[Asserts]
header "Content-Type" contains "text/html"
body contains "Index.html"
# Configure Caddy with `fs` applied conditionally via named matcher
POST http://localhost:2019/load
Content-Type: text/caddyfile
```
{
skip_install_trust
http_port 9080
https_port 9443
local_certs
}
localhost {
root * {{indexed_root}}
@indexed path /indexed/*
fs @indexed default
file_server
}
```
HTTP 200
# PROPERTY: matcher-scoped `fs` does not break unrelated paths
GET https://localhost:9443/index.txt
[Options]
insecure: true
HTTP 200
[Asserts]
body == "index.txt"
# Configure Caddy with fs and browse listing
POST http://localhost:2019/load
Content-Type: text/caddyfile
```
{
skip_install_trust
http_port 9080
https_port 9443
local_certs
}
localhost {
root * {{unindexed_root}}
fs default
file_server browse
}
```
HTTP 200
# PROPERTY: fs default works with file_server browse (directory listing fallback)
GET https://localhost:9443/
[Options]
insecure: true
HTTP 200
[Asserts]
header "Content-Type" contains "text/html"

View file

@ -0,0 +1,117 @@
# Configure Caddy with try_files directive
POST http://localhost:2019/load
Content-Type: text/caddyfile
```
{
skip_install_trust
http_port 9080
https_port 9443
local_certs
}
localhost {
root * {{indexed_root}}
try_files {path} {path}.txt {path}/index.html
file_server
}
```
# try_files tries the original path first
GET https://localhost:9443/index.txt
[Options]
insecure: true
HTTP 200
[Asserts]
body == "index.txt"
# try_files falls through to next option if first doesn't exist
GET https://localhost:9443/index
[Options]
insecure: true
HTTP 200
[Asserts]
body == "index.txt"
# try_files falls through to directory index when the directory exists
GET https://localhost:9443/
[Options]
insecure: true
HTTP 200
[Asserts]
body contains "Index.html"
# Configure Caddy with try_files and final fallback
POST http://localhost:2019/load
Content-Type: text/caddyfile
```
{
skip_install_trust
http_port 9080
https_port 9443
local_certs
}
localhost {
root * {{indexed_root}}
try_files {path} /index.html
file_server
}
```
# try_files uses final fallback when nothing matches
GET https://localhost:9443/does-not-exist
[Options]
insecure: true
HTTP 200
[Asserts]
body contains "Index.html"
# Configure Caddy with try_files policy
POST http://localhost:2019/load
Content-Type: text/caddyfile
```
{
skip_install_trust
http_port 9080
https_port 9443
local_certs
}
localhost {
root * {{indexed_root}}
try_files {path} {path}/ =404
}
```
# try_files with =404 returns 404 when no files match
GET https://localhost:9443/nonexistent
[Options]
insecure: true
HTTP 404
# Configure Caddy with try_files and query parameters
POST http://localhost:2019/load
Content-Type: text/caddyfile
```
{
skip_install_trust
http_port 9080
https_port 9443
local_certs
}
localhost {
root * {{indexed_root}}
try_files {path} /index.html
file_server
}
```
# try_files preserves query parameters
GET https://localhost:9443/missing?param=value
[Options]
insecure: true
HTTP 200
[Asserts]
body contains "Index.html"