@@ -10,6 +10,7 @@ import qualified Data.ByteString.Char8 as S8
10import qualified Data.ByteString.Lazy.Char8 as L8
10import qualified Data.ByteString.Lazy.Char8 as L8
11import qualified Data.Text as T
11import qualified Data.Text as T
12import qualified Data.Text.Encoding as TE
12import qualified Data.Text.Encoding as TE
13+import System.IO (stderr, hPutStrLn)
15import Network.Wai
16import Network.Wai
@@ -40,23 +41,20 @@ setRawPathInfo r rawPinfo =
40 in r { rawPathInfo = rawPinfo, pathInfo = pInfo }
41 in r { rawPathInfo = rawPinfo, pathInfo = pInfo }
44main :: IO a
44main :: IO a
45main = hspecX $ do
45main = hspecX $ do
46 let must = liftIO . assert
46 let must = liftIO . assert
47+ let info = liftIO . hPutStrLn stderr
48 describe "Pieces: pathFromPieces" $ do
49 describe "Pieces: pathFromPieces" $ do
49 it "converts to a file path" $
50 it "converts to a file path" $
50 (pathFromPieces "prefix" [Piece "a" "a", Piece "bc" "bc"]) @?= "prefix/a/bc"
51 (pathFromPieces "prefix" [Piece "a" "a", Piece "bc" "bc"]) @?= "prefix/a/bc"
53− prop "each piece is in file path" $ \pieces ->
53+ prop "each piece is in file path" $ \piecesS ->
54− let piecesT = (map piecePretty pieces) in
54+ let pieces = map (\p -> Piece p "") piecesS
55− all (\p -> ("/" ++ (unfixPathName $ T.unpack p)) `isInfixOf` (pathFromPieces "root" $ pieces)) piecesT
55+ in all (\p -> ("/" ++ p) `isInfixOf` (pathFromPieces "root" $ pieces)) piecesS
59− let cacheLookup = MaxAgeForever -- (\fp h -> fp == "tests/runtests.hs" && h == "cached")
60 let statApp = flip runSession $ staticApp defaultFileServerSettings {ssFolder = fileSystemLookup "tests"}
58 let statApp = flip runSession $ staticApp defaultFileServerSettings {ssFolder = fileSystemLookup "tests"}
61 describe "staticApp" $ do
59 describe "staticApp" $ do
62 it "403 for unsafe paths" $ statApp $
60 it "403 for unsafe paths" $ statApp $
@@ -99,21 +97,37 @@ main = hspecX $ do
99 describe "when requesting a static asset" $ do
97 describe "when requesting a static asset" $ do
100 let runtests = setRawPathInfo defRequest "runtests.hs"
98 let runtests = setRawPathInfo defRequest "runtests.hs"
101 it "200 when no query parameters" $ statApp $ do
99 it "200 when no query parameters" $ statApp $ do
100+ req <- request runtests
101+ assertStatus 200 req
102+ assertNoHeader "Cache-Control" req
104+ it "200 when invalid if-modified-since header" $ statApp $ do
102 req <- request runtests {
105 req <- request runtests {
103 requestHeaders = [("If-Modified-Since", "")]
106 requestHeaders = [("If-Modified-Since", "")]
105 assertStatus 200 req
108 assertStatus 200 req
106 assertNoHeader "Cache-Control" req
109 assertNoHeader "Cache-Control" req
108− it "200 when no cache headers sent" $ statApp $ do
111+ it "200 when no cache headers and no cache query string" $ statApp $ do
109− req <- request runtests { rawQueryString ="?cached" }
112+ req <- request runtests { rawQueryString ="?foo" }
113+ assertStatus 200 req
114+ assertNoHeader "Cache-Control" req
116+ it "200 when no cache headers and bad cache query string" $ statApp $ do
117+ req <- request runtests { rawQueryString ="?etag=cached" }
118+ assertStatus 200 req
119+ assertNoHeader "Cache-Control" req
121+ it "200 when no cache headers and bad cache query string" $ statApp $ do
122+ req <- request runtests { rawQueryString ="?etag=" }
110 assertStatus 200 req
123 assertStatus 200 req
111 assertHeader "Cache-Control" "max-age=31536000" req
124 assertHeader "Cache-Control" "max-age=31536000" req
113− it "200 when If-Unmodified-Since" $ statApp $ do
126+ it "200 when empty If-Unmodified-Since" $ statApp $ do
114 req <- request runtests { rawQueryString ="?cached",
127 req <- request runtests { rawQueryString ="?cached",
115 requestHeaders = [("If-Unmodified-Since", "")]
128 requestHeaders = [("If-Unmodified-Since", "")]
117 assertStatus 200 req
131 assertStatus 200 req
118 assertHeader "Cache-Control" "max-age=31536000" req
132 assertHeader "Cache-Control" "max-age=31536000" req