Skip to content

Commit 47dea0b

Browse files
committed
Add test for combineSafe
1 parent 6c67568 commit 47dea0b

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tests/Happstack/Server/Tests.hs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import qualified Data.ByteString.Lazy as L
1313
import qualified Data.Map as Map
1414
import Happstack.Server ( Request(..), Method(..), Response(..), ServerPart, Headers, RqBody(Body), HttpVersion(..)
1515
, ToMessage(..), HeaderPair(..), ok, dir, simpleHTTP'', composeFilter, noContentLength, matchMethod)
16-
import Happstack.Server.FileServe.BuildingBlocks (sendFileResponse)
16+
import Happstack.Server.FileServe.BuildingBlocks (sendFileResponse, combineSafe)
1717
import Happstack.Server.Cookie
1818
import Happstack.Server.Internal.Compression
1919
import Happstack.Server.Internal.Cookie
@@ -34,6 +34,7 @@ allTests =
3434
, matchMethodTest
3535
, cookieHeaderOrderTest
3636
, pContentDispositionFilename
37+
, combineSafeTest
3738
]
3839

3940
cookieParserTest :: Test
@@ -247,3 +248,16 @@ pContentDispositionFilename =
247248
do let doesNotWorkWithOldParserButWithNew = "form-data; filename=\"file.pdf\"; name=\"file\"" :: String
248249
c <- parseContentDisposition doesNotWorkWithOldParserButWithNew
249250
assertEqual "parseContentDisposition" c (ContentDisposition "form-data" [("filename","file.pdf"),("name","file")])
251+
252+
-- | Make sure 'combineSafe' works correctly
253+
combineSafeTest :: Test
254+
combineSafeTest =
255+
"combineSafeTest" ~:
256+
do r1 <- combineSafe "/var/uploads/" "etc/passwd"
257+
r2 <- combineSafe "/var/uploads/" "/etc/passwd"
258+
r3 <- combineSafe "/var/uploads/" "../../etc/passwd"
259+
r4 <- combineSafe "/var/uploads/" "../uploads/home/../etc/passwd"
260+
r1 @?= Just "/var/uploads/etc/passwd"
261+
r2 @?= Nothing
262+
r3 @?= Nothing
263+
r4 @?= Just "/var/uploads/etc/passwd"

0 commit comments

Comments
 (0)