Skip to content

Commit c1cdc25

Browse files
committed
add file_server test
Signed-off-by: Mohammed Al Sahaf <[email protected]>
1 parent 0ecb1ba commit c1cdc25

File tree

6 files changed

+133
-3
lines changed

6 files changed

+133
-3
lines changed

.github/workflows/ci.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,14 @@ jobs:
137137
138138
- name: Run Caddy
139139
if: matrix.os == 'linux' && matrix.go == '1.22'
140-
working-directory: ./cmd/caddy
141140
run: |
142-
./caddy start
141+
./cmd/caddy/caddy start
143142
144143
- name: Run tests with Hurl
145144
if: matrix.os == 'linux' && matrix.go == '1.22'
146145
run: |
147146
mkdir hurl-report
148-
find . -name *.hurl -exec hurl --very-verbose --verbose --test --report-junit hurl-report/junit.xml --color {} \;
147+
find . -name *.hurl -exec hurl --variables-file caddytest/spec/hurl_vars.properties --very-verbose --verbose --test --report-junit hurl-report/junit.xml --color {} \;
149148
150149
- name: Publish Test Results
151150
if: matrix.os == 'linux' && matrix.go == '1.22'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Index.html Title</title>
5+
</head>
6+
<body>
7+
Index.html
8+
</body>
9+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
index.txt

caddytest/spec/http/file_server/assets/unindexed/.gitkeep

Whitespace-only changes.
+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Configure Caddy with default configuration
2+
POST http://localhost:2019/load
3+
Content-Type: text/caddyfile
4+
```
5+
{
6+
skip_install_trust
7+
http_port 9080
8+
https_port 9443
9+
local_certs
10+
debug
11+
}
12+
localhost {
13+
root {{indexed_root}}
14+
file_server
15+
}
16+
```
17+
18+
# requests without specific file receive index file per
19+
# the default index list: index.html, index.txt
20+
GET https://localhost:9443
21+
[Options]
22+
insecure: true
23+
HTTP 200
24+
[Asserts]
25+
```
26+
<!DOCTYPE html>
27+
<html>
28+
<head>
29+
<title>Index.html Title</title>
30+
</head>
31+
<body>
32+
Index.html
33+
</body>
34+
</html>```
35+
36+
37+
# if index.txt is specifically requested, we expect index.txt
38+
GET https://localhost:9443/index.txt
39+
[Options]
40+
insecure: true
41+
HTTP 200
42+
[Asserts]
43+
body == "index.txt"
44+
45+
# requests for sub-folder followed by .. result in sanitized path
46+
GET https://localhost:9443/non-existent/../index.txt
47+
[Options]
48+
insecure: true
49+
HTTP 200
50+
[Asserts]
51+
body == "index.txt"
52+
53+
# results out of root folder are sanitized,
54+
# and conform to default index list sequence.
55+
GET https://localhost:9443/../
56+
[Options]
57+
insecure: true
58+
HTTP 200
59+
[Asserts]
60+
```
61+
<!DOCTYPE html>
62+
<html>
63+
<head>
64+
<title>Index.html Title</title>
65+
</head>
66+
<body>
67+
Index.html
68+
</body>
69+
</html>```
70+
71+
72+
# Configure Caddy with custsom index "index.txt"
73+
POST http://localhost:2019/load
74+
Content-Type: text/caddyfile
75+
```
76+
{
77+
skip_install_trust
78+
http_port 9080
79+
https_port 9443
80+
local_certs
81+
debug
82+
}
83+
localhost {
84+
root {{indexed_root}}
85+
file_server {
86+
index index.txt
87+
}
88+
}
89+
```
90+
91+
GET https://localhost:9443
92+
[Options]
93+
insecure: true
94+
HTTP 200
95+
[Asserts]
96+
body == "index.txt"
97+
98+
99+
# Configure with a root not containing index files
100+
POST http://localhost:2019/load
101+
Content-Type: text/caddyfile
102+
```
103+
{
104+
skip_install_trust
105+
http_port 9080
106+
https_port 9443
107+
local_certs
108+
debug
109+
}
110+
localhost {
111+
root {{unindexed_root}}
112+
file_server
113+
}
114+
```
115+
116+
GET https://localhost:9443
117+
[Options]
118+
insecure: true
119+
HTTP 404

caddytest/spec/hurl_vars.properties

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
indexed_root=caddytest/spec/http/file_server/assets/indexed
2+
unindexed_root=caddytest/spec/http/file_server/assets/unindexed

0 commit comments

Comments
 (0)