Skip to content

Commit b9f33d9

Browse files
committed
Promote tests
Eio doesn't allow filesystem operations to escape the current directory. This is a safety feature but might break applications. The tests are changed to avoid the symlinks pointing outside of the current directory that Dune creates.
1 parent 70e3d38 commit b9f33d9

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

src/server/ocsigen_response.ml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,18 @@ let respond_not_found ?uri () =
7070
let respond_file ?headers ?(status = `OK) fname =
7171
let exception Isnt_a_file in
7272
try
73+
let sw = Stdlib.Option.get (Fiber.get Ocsigen_lib.current_switch) in
74+
let env = Stdlib.Option.get (Fiber.get Ocsigen_lib.env) in
7375
(* Copied from [cohttp-lwt-unix] and adapted to [Body]. *)
76+
let file_path = Eio.Path.( / ) env#cwd fname in
7477
let file_size =
7578
(* Check this isn't a directory first *)
76-
let s =
77-
Eio.Path.stat ~follow:true
78-
(Eio.Path.( / ) (Stdlib.Option.get (Fiber.get Ocsigen_lib.env))#cwd
79-
fname)
80-
in
79+
let s = Eio.Path.stat ~follow:true file_path in
8180
if s.Eio.File.Stat.kind <> `Regular_file
8281
then raise Isnt_a_file
8382
else s.size
8483
in
85-
let ic =
86-
let sw = Stdlib.Option.get (Fiber.get Ocsigen_lib.current_switch) in
87-
let env = Stdlib.Option.get (Fiber.get Ocsigen_lib.env) in
88-
Eio.Path.(open_in ~sw (env#cwd / fname))
89-
in
84+
let ic = Eio.Path.open_in ~sw file_path in
9085
let encoding = Http.Transfer.Fixed (Optint.Int63.to_int64 file_size) in
9186
let stream write =
9287
let buf = Cstruct.create 16384 in

test/extensions/deflatemod.t/index.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/extensions/deflatemod.t/run.t

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,42 @@
11
$ source ../../server-test-helpers.sh
22
$ run_server ./test.exe
33
ocsigen:main: [WARNING] Command pipe created
4-
ocsigen:access: connection for local-test from (curl/8.12.1): /index.html
4+
cohttp.eio: [INFO] unix:: accept connection
5+
ocsigen:access: connection for local-test from (curl/8.13.0): /index.html
56
ocsigen:ext: [INFO] host found! local-test:0 matches .*
67
ocsigen:ext:staticmod: [INFO] Is it a static file?
78
ocsigen:local-file: [INFO] Testing "./index.html".
89
ocsigen:local-file: [INFO] checking if file index.html can be sent
910
ocsigen:ext: [INFO] Compiling exclusion regexp $^
1011
ocsigen:local-file: [INFO] Returning "./index.html".
11-
ocsigen:access: connection for local-test from (curl/8.12.1): /index.html
12+
cohttp.eio: [INFO] unix:: disconnected
13+
cohttp.eio: [INFO] unix:: accept connection
14+
ocsigen:access: connection for local-test from (curl/8.13.0): /index.html
1215
ocsigen:ext: [INFO] host found! local-test:0 matches .*
1316
ocsigen:ext:staticmod: [INFO] Is it a static file?
1417
ocsigen:local-file: [INFO] Testing "./index.html".
1518
ocsigen:local-file: [INFO] checking if file index.html can be sent
1619
ocsigen:local-file: [INFO] Returning "./index.html".
17-
ocsigen:access: connection for local-test from (curl/8.12.1): /empty_dir/
20+
cohttp.eio: [INFO] unix:: disconnected
21+
cohttp.eio: [INFO] unix:: accept connection
22+
ocsigen:access: connection for local-test from (curl/8.13.0): /empty_dir/
1823
ocsigen:ext: [INFO] host found! local-test:0 matches .*
1924
ocsigen:ext:staticmod: [INFO] Is it a static file?
2025
ocsigen:local-file: [INFO] Testing "./empty_dir/".
2126
ocsigen:local-file: [INFO] Testing "./empty_dir/index.html" as possible index.
2227
ocsigen:local-file: [INFO] No index and no listing
23-
ocsigen:access: connection for local-test from (curl/8.12.1): /doesnt_exists.html
28+
cohttp.eio: [INFO] unix:: disconnected
29+
cohttp.eio: [INFO] unix:: accept connection
30+
ocsigen:access: connection for local-test from (curl/8.13.0): /doesnt_exists.html
2431
ocsigen:ext: [INFO] host found! local-test:0 matches .*
2532
ocsigen:ext:staticmod: [INFO] Is it a static file?
2633
ocsigen:local-file: [INFO] Testing "./doesnt_exists.html".
34+
cohttp.eio: [INFO] unix:: disconnected
2735
application: [WARNING] Command received: shutdown
2836

2937
First response is not compressed:
3038

39+
$ echo "Hello world" > index.html
3140
$ curl_ "index.html"
3241
HTTP/1.1 200 OK
3342
content-type: text/html

0 commit comments

Comments
 (0)