diff options
| author | John MacFarlane <[email protected]> | 2023-06-23 10:54:23 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2023-06-23 10:54:59 -0700 |
| commit | 5246f02f0bb9c176a6d2f6e3d0c03407d8a67445 (patch) | |
| tree | 69cabc1c98426dd380a6ae8b38862781159a1336 | |
| parent | fe62da61dfd33e6b4c0c03895c528a47a0405bf7 (diff) | |
Improve tests for fillMediaBag/extractMedia.
Ensure that the current directory is not changed up if a test fails,
and fix messages for the assertion failures.
| -rw-r--r-- | test/Tests/MediaBag.hs | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/test/Tests/MediaBag.hs b/test/Tests/MediaBag.hs index 2522ff54d..65b6716d9 100644 --- a/test/Tests/MediaBag.hs +++ b/test/Tests/MediaBag.hs @@ -7,16 +7,15 @@ import Test.Tasty.HUnit import Text.Pandoc.Class.IO (extractMedia) import Text.Pandoc.Class (fillMediaBag, runIOorExplode) import System.IO.Temp (withTempDirectory) +import Text.Pandoc.Shared (inDirectory) import System.FilePath import Text.Pandoc.Builder as B -import System.Directory (doesFileExist, copyFile, setCurrentDirectory, getCurrentDirectory) +import System.Directory (doesFileExist, copyFile) tests :: [TestTree] tests = [ testCase "test fillMediaBag & extractMedia" $ - withTempDirectory "." "extractMediaTest" $ \tmpdir -> do - olddir <- getCurrentDirectory - setCurrentDirectory tmpdir + withTempDirectory "." "extractMediaTest" $ \tmpdir -> inDirectory tmpdir $ do copyFile "../../test/lalune.jpg" "moon.jpg" let d = B.doc $ B.para (B.image "../../test/lalune.jpg" "" mempty) <> @@ -27,14 +26,13 @@ tests = [ fillMediaBag d extractMedia "foo" d exists1 <- doesFileExist ("foo" </> "moon.jpg") - assertBool "file in directory extract with original name" exists1 + assertBool "file in directory is not extracted with original name" exists1 exists2 <- doesFileExist ("foo" </> "f9d88c3dbe18f6a7f5670e994a947d51216cdf0e.jpg") - assertBool "file above directory extracted with hashed name" exists2 + assertBool "file above directory is not extracted with hashed name" exists2 exists3 <- doesFileExist ("foo" </> "2a0eaa89f43fada3e6c577beea4f2f8f53ab6a1d.lua") exists4 <- doesFileExist "a.lua" - assertBool "data uri with malicious payload does not get written to arbitrary location" + assertBool "data uri with malicious payload gets written outside of destination dir" (exists3 && not exists4) exists5 <- doesFileExist ("foo" </> "d5fceb6532643d0d84ffe09c40c481ecdf59e15a.gif") - assertBool "data uri with gif is properly decoded" exists5 - setCurrentDirectory olddir + assertBool "data uri with gif is not properly decoded" exists5 ] |
