mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-03-30 20:45:52 +00:00
* Files: main, env, stats, storeLog * Better + transport * Executable * Env * Update Client.hs, Server.hs, and 4 more files... * Answer on request * Delay * Temp file * Bypass cert check * update package.yml, rename * update store log * extend HTTP2 transport * refactor caStore * HTTP2 body * update server stats * file server/client framework * verify server commands * process FNEW command, CLI test works * simple XFTP server test (fails) * fix test, refactor * upload chunk works * receive file chunk in the client * remove transport handshake * typo Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> * fix names --------- Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com>
62 lines
2.0 KiB
Haskell
62 lines
2.0 KiB
Haskell
{-# LANGUAGE LambdaCase #-}
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
{-# LANGUAGE RankNTypes #-}
|
|
|
|
module XFTPClient where
|
|
|
|
import Control.Concurrent (ThreadId)
|
|
import Network.Socket (ServiceName)
|
|
import SMPClient (serverBracket)
|
|
import Simplex.FileTransfer.Client
|
|
import Simplex.FileTransfer.Server (runXFTPServerBlocking)
|
|
import Simplex.FileTransfer.Server.Env (XFTPServerConfig (..))
|
|
import Simplex.Messaging.Protocol (XFTPServer)
|
|
import Test.Hspec
|
|
|
|
xftpTest :: HasCallStack => (HasCallStack => XFTPClient -> IO ()) -> Expectation
|
|
xftpTest test = runXFTPTest test `shouldReturn` ()
|
|
|
|
runXFTPTest :: HasCallStack => (HasCallStack => XFTPClient -> IO a) -> IO a
|
|
runXFTPTest test = withXFTPServer $ testXFTPClient test
|
|
|
|
withXFTPServerCfg :: HasCallStack => XFTPServerConfig -> (HasCallStack => ThreadId -> IO a) -> IO a
|
|
withXFTPServerCfg cfg =
|
|
serverBracket
|
|
(`runXFTPServerBlocking` cfg)
|
|
(pure ())
|
|
|
|
withXFTPServer :: IO a -> IO a
|
|
withXFTPServer = withXFTPServerCfg testXFTPServerConfig . const
|
|
|
|
xftpTestPort :: ServiceName
|
|
xftpTestPort = "7000"
|
|
|
|
testXFTPServer :: XFTPServer
|
|
testXFTPServer = "xftp://LcJUMfVhwD8yxjAiSaDzzGF3-kLG4Uh0Fl_ZIjrRwjI=@localhost:7000"
|
|
|
|
testXFTPServerConfig :: XFTPServerConfig
|
|
testXFTPServerConfig =
|
|
XFTPServerConfig
|
|
{ xftpPort = xftpTestPort,
|
|
fileIdSize = 16,
|
|
storeLogFile = Nothing,
|
|
filesPath = "tests/xftp-files",
|
|
caCertificateFile = "tests/fixtures/ca.crt",
|
|
privateKeyFile = "tests/fixtures/server.key",
|
|
certificateFile = "tests/fixtures/server.crt",
|
|
logStatsInterval = Nothing,
|
|
logStatsStartTime = 0,
|
|
serverStatsLogFile = "tests/xftp-server-stats.daily.log",
|
|
serverStatsBackupFile = Nothing,
|
|
logTLSErrors = True
|
|
}
|
|
|
|
testXFTPClientConfig :: XFTPClientConfig
|
|
testXFTPClientConfig = defaultXFTPClientConfig
|
|
|
|
testXFTPClient :: HasCallStack => (HasCallStack => XFTPClient -> IO a) -> IO a
|
|
testXFTPClient client =
|
|
getXFTPClient (1, testXFTPServer, Nothing) testXFTPClientConfig (pure ()) >>= \case
|
|
Right c -> client c
|
|
Left e -> error $ show e
|