mirror of
https://github.com/caddyserver/caddy.git
synced 2026-10-20 19:04:36 +00:00
add fs and try_files tests
Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com>
This commit is contained in:
parent
d193d7fb0f
commit
7a9ce91986
3 changed files with 212 additions and 0 deletions
0
caddytest/spec/http/file_server/assets/indexed/style.css
Normal file
0
caddytest/spec/http/file_server/assets/indexed/style.css
Normal file
95
caddytest/spec/http/fs/spec.hurl
Normal file
95
caddytest/spec/http/fs/spec.hurl
Normal 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"
|
||||
117
caddytest/spec/http/try_files/spec.hurl
Normal file
117
caddytest/spec/http/try_files/spec.hurl
Normal 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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue