@@ -34,6 +34,7 @@ import Data.Map qualified as Map
3434import Data.Maybe (catMaybes )
3535import Data.Proxy (Proxy (Proxy ))
3636import Data.Row (Row )
37+ import Data.String (fromString )
3738import Data.Text (Text , pack , unpack )
3839import Data.Text.Encoding (encodeUtf8 )
3940import Data.UUID.V4 qualified as UUID
@@ -75,8 +76,9 @@ import Servant.API (
7576 )
7677import Servant.API.WebSocket (WebSocketPending )
7778import Servant.Server (Application , Handler , Server , err404 , serve )
78- import System.Directory (canonicalizePath , doesFileExist , makeAbsolute )
79- import System.FilePath (takeDirectory , (</>) )
79+ import System.Directory (doesFileExist , makeAbsolute )
80+ import System.FilePath ((</>) )
81+ import Test.QuickCheck (Arbitrary (arbitrary ), elements , vectorOf )
8082import Wallet.Types (ContractInstanceId (.. ))
8183import Prelude
8284
@@ -105,6 +107,7 @@ type RawTxEndpoint =
105107 :> Get '[JSON ] RawTx
106108
107109newtype TxIdCapture = TxIdCapture TxId
110+ deriving newtype (Eq , Show )
108111
109112instance FromHttpApiData TxIdCapture where
110113 parseUrlPiece :: Text -> Either Text TxIdCapture
@@ -121,6 +124,9 @@ instance FromHttpApiData TxIdCapture where
121124instance ToHttpApiData TxIdCapture where
122125 toUrlPiece (TxIdCapture txId) = txIdToText txId
123126
127+ instance Arbitrary TxIdCapture where
128+ arbitrary = TxIdCapture . fromString <$> vectorOf 64 (elements " 0123456789abcdefABCDEF" )
129+
124130server :: HasDefinitions t => PABConfig -> AppState -> Server (API t )
125131server pabConfig state =
126132 websocketHandler state
@@ -274,13 +280,10 @@ rawTxHandler config (TxIdCapture txId) = do
274280 -- Absolute path to pcTxFileDir that is specified in the config
275281 txFolderPath <- liftIO $ makeAbsolute (unpack config. pcTxFileDir)
276282
277- -- Add/Set .raw extension on path
278- let suppliedPath :: FilePath
279- suppliedPath = txFolderPath </> unpack (txFileName txId " raw" )
280- -- Resolve path indirections
281- path <- liftIO $ canonicalizePath suppliedPath
282- -- ensure it does not try to escape txFolderPath
283- assert (takeDirectory path == txFolderPath)
283+ -- Create full path
284+ let path :: FilePath
285+ path = txFolderPath </> unpack (txFileName txId " raw" )
286+
284287 -- ensure file exists
285288 fileExists <- liftIO $ doesFileExist path
286289 assert fileExists
0 commit comments