@@ -7,7 +7,9 @@ elli_static_test_() ->
7
7
fun setup /0 , fun teardown /1 ,
8
8
[? _test (readme ()),
9
9
? _test (no_file ()),
10
- ? _test (not_found ())]}.
10
+ ? _test (not_found ()),
11
+ ? _test (safe_traversal ()),
12
+ ? _test (unsafe_traversal ())]}.
11
13
12
14
13
15
readme () ->
@@ -28,6 +30,23 @@ not_found() ->
28
30
{ok , Response } = httpc :request (" http://localhost:3000/not_found" ),
29
31
? assertMatch ({{" HTTP/1.1" ,404 ," Not Found" }, _Headers , " Not Found" }, Response ).
30
32
33
+ safe_traversal () ->
34
+ {ok , Response } = httpc :request (" http://localhost:3000/elli_static/"
35
+ " ../elli_static/README.md" ),
36
+ {ok , File } = file :read_file (" README.md" ),
37
+ Expected = binary_to_list (File ),
38
+ ? assertEqual ([integer_to_list (iolist_size (Expected ))],
39
+ proplists :get_all_values (" content-length" , element (2 , Response ))),
40
+ ? assertMatch ({_Status , _Headers , Expected }, Response ).
41
+
42
+ unsafe_traversal () ->
43
+ % % compute the relative path to /etc/passwd
44
+ {ok , Cwd } = file :get_cwd (),
45
+ PasswdPath = [" .." || _ <- filename :split (Cwd )] ++ [" etc" , " passwd" ],
46
+ Path = filename :join (PasswdPath ),
47
+
48
+ {ok , Response } = httpc :request (" http://localhost:3000/elli_static/" ++ Path ),
49
+ ? assertMatch ({{" HTTP/1.1" ,404 ," Not Found" }, _Headers , " Not Found" }, Response ).
31
50
32
51
setup () ->
33
52
{ok , Dir } = file :get_cwd (),
0 commit comments