Skip to content

Commit

Permalink
add file_server test
Browse files Browse the repository at this point in the history
Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com>
  • Loading branch information
mohammed90 committed Jun 20, 2024
1 parent 0ecb1ba commit 7e174a0
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ jobs:
if: matrix.os == 'linux' && matrix.go == '1.22'
run: |
mkdir hurl-report
find . -name *.hurl -exec hurl --very-verbose --verbose --test --report-junit hurl-report/junit.xml --color {} \;
find . -name *.hurl -exec hurl --variable indexed_root=$PWD/caddytest/spec/http/file_server/assets/indexed --variable unindexed_root=$PWD/caddytest/spec/http/file_server/assets/unindexed --very-verbose --verbose --test --report-junit hurl-report/junit.xml --color {} \;
- name: Publish Test Results
if: matrix.os == 'linux' && matrix.go == '1.22'
Expand Down
9 changes: 9 additions & 0 deletions caddytest/spec/http/file_server/assets/indexed/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Index.html Title</title>
</head>
<body>
Index.html
</body>
</html>
1 change: 1 addition & 0 deletions caddytest/spec/http/file_server/assets/indexed/index.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index.txt
Empty file.
108 changes: 108 additions & 0 deletions caddytest/spec/http/file_server/spec.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Configure Caddy with default configuration
POST http://localhost:2019/load
Content-Type: text/caddyfile
```
{
skip_install_trust
http_port 9080
https_port 9443
local_certs
debug
}
localhost {
root {{indexed_root}}
file_server
}
```

# requests without specific file receive index file per
# the default index list: index.html, index.txt
GET https://localhost:9443
[Options]
insecure: true
HTTP 200
[Asserts]
```
<!DOCTYPE html>
<html>
<head>
<title>Index.html Title</title>
</head>
<body>
Index.html
</body>
</html>```


# if index.txt is specifically requested, we expect index.txt
GET https://localhost:9443/index.txt
[Options]
insecure: true
HTTP 200
[Asserts]
body == "index.txt"

# requests for sub-folder folloed by .. result in sanitized path
GET https://localhost:9443/non-existent/../index.txt
[Options]
insecure: true
HTTP 200
[Asserts]
body == "index.txt"

GET https://localhost:9443/../
[Options]
insecure: true
HTTP 200
[Asserts]
body == "index.txt"


# Configure Caddy with custsom index "index.txt"
POST http://localhost:2019/load
Content-Type: text/caddyfile
```
{
skip_install_trust
http_port 9080
https_port 9443
local_certs
debug
}
localhost {
root {{indexed_root}}
file_server {
index index.txt
}
}
```

GET https://localhost:9443
[Options]
insecure: true
HTTP 200
[Asserts]
body == "index.txt"


# Configure with a root not containing index files
POST http://localhost:2019/load
Content-Type: text/caddyfile
```
{
skip_install_trust
http_port 9080
https_port 9443
local_certs
debug
}
localhost {
root {{unindexed_root}}
file_server
}
```

GET https://localhost:9443
[Options]
insecure: true
HTTP 404

0 comments on commit 7e174a0

Please sign in to comment.