mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-04-04 13:26:14 +00:00
* SMP proxy: low level client and server implementation * SMP proxy: server implementation (#1098) * wip * PRXY command * progress * SMP Proxy: client-level implementation (#1101) * buildable * encode messages * update pkey * fix queue types * wrap SEND in proxy lookup * WIP proxy client * WIP * post-rebase fixes * encode something with something * cleanup * update * fix nonce/corrId in batchingTests * WIP: dig into createSMPProxySession * agent * test progress * pass the test * parameterize transport handle with transport peer to include server certificate (#1100) * parameterize transport handle with transport peer to include server certificate * include server certificate into THandle * load server chain and sign key * fix key type * fix for 8.10 --------- Co-authored-by: Alexander Bondarenko <486682+dpwiz@users.noreply.github.com> Co-authored-by: IC Rainbow <aenor.realm@gmail.com> * cleanup * add 2-server test * remove subsumed test * checkCredentials for BrokerMsg * skip batching tests * remove userId param * remove agent changes --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> --------- Co-authored-by: Alexander Bondarenko <486682+dpwiz@users.noreply.github.com> * remove unused type * icrease test timeout * reduce transport block * envelope sizes * don't fork unless have proxied commands to process --------- Co-authored-by: Alexander Bondarenko <486682+dpwiz@users.noreply.github.com> Co-authored-by: IC Rainbow <aenor.realm@gmail.com>
92 lines
2.9 KiB
Haskell
92 lines
2.9 KiB
Haskell
{-# LANGUAGE DeriveGeneric #-}
|
|
{-# LANGUAGE LambdaCase #-}
|
|
{-# LANGUAGE ScopedTypeVariables #-}
|
|
{-# LANGUAGE StandaloneDeriving #-}
|
|
{-# OPTIONS_GHC -Wno-orphans #-}
|
|
|
|
module CoreTests.ProtocolErrorTests where
|
|
|
|
import qualified Data.ByteString.Char8 as B
|
|
import qualified Data.Text as T
|
|
import Data.Text.Encoding (encodeUtf8)
|
|
import GHC.Generics (Generic)
|
|
import Generic.Random (genericArbitraryU)
|
|
import Simplex.FileTransfer.Transport (XFTPErrorType (..))
|
|
import Simplex.Messaging.Agent.Protocol
|
|
import qualified Simplex.Messaging.Agent.Protocol as Agent
|
|
import Simplex.Messaging.Encoding
|
|
import Simplex.Messaging.Encoding.String
|
|
import Simplex.Messaging.Protocol (CommandError (..), ErrorType (..), ProxyError (..))
|
|
import Simplex.Messaging.Transport (HandshakeError (..), TransportError (..))
|
|
import Simplex.RemoteControl.Types (RCErrorType (..))
|
|
import Test.Hspec
|
|
import Test.Hspec.QuickCheck (modifyMaxSuccess)
|
|
import Test.QuickCheck
|
|
|
|
protocolErrorTests :: Spec
|
|
protocolErrorTests = modifyMaxSuccess (const 1000) $ do
|
|
describe "errors parsing / serializing" $ do
|
|
it "should parse SMP protocol errors" . property $ \(err :: ErrorType) ->
|
|
smpDecode (smpEncode err) == Right err
|
|
it "should parse SMP agent errors" . property $ \(err :: AgentErrorType) ->
|
|
errHasSpaces err
|
|
|| strDecode (strEncode err) == Right err
|
|
where
|
|
errHasSpaces = \case
|
|
BROKER srv (Agent.RESPONSE e) -> hasSpaces srv || hasSpaces e
|
|
BROKER srv _ -> hasSpaces srv
|
|
_ -> False
|
|
hasSpaces s = ' ' `B.elem` encodeUtf8 (T.pack s)
|
|
|
|
deriving instance Generic AgentErrorType
|
|
|
|
deriving instance Generic CommandErrorType
|
|
|
|
deriving instance Generic ConnectionErrorType
|
|
|
|
deriving instance Generic BrokerErrorType
|
|
|
|
deriving instance Generic SMPAgentError
|
|
|
|
deriving instance Generic AgentCryptoError
|
|
|
|
deriving instance Generic ErrorType
|
|
|
|
deriving instance Generic CommandError
|
|
|
|
deriving instance Generic ProxyError
|
|
|
|
deriving instance Generic TransportError
|
|
|
|
deriving instance Generic HandshakeError
|
|
|
|
deriving instance Generic XFTPErrorType
|
|
|
|
deriving instance Generic RCErrorType
|
|
|
|
instance Arbitrary AgentErrorType where arbitrary = genericArbitraryU
|
|
|
|
instance Arbitrary CommandErrorType where arbitrary = genericArbitraryU
|
|
|
|
instance Arbitrary ConnectionErrorType where arbitrary = genericArbitraryU
|
|
|
|
instance Arbitrary BrokerErrorType where arbitrary = genericArbitraryU
|
|
|
|
instance Arbitrary SMPAgentError where arbitrary = genericArbitraryU
|
|
|
|
instance Arbitrary AgentCryptoError where arbitrary = genericArbitraryU
|
|
|
|
instance Arbitrary ErrorType where arbitrary = genericArbitraryU
|
|
|
|
instance Arbitrary CommandError where arbitrary = genericArbitraryU
|
|
|
|
instance Arbitrary ProxyError where arbitrary = genericArbitraryU
|
|
|
|
instance Arbitrary TransportError where arbitrary = genericArbitraryU
|
|
|
|
instance Arbitrary HandshakeError where arbitrary = genericArbitraryU
|
|
|
|
instance Arbitrary XFTPErrorType where arbitrary = genericArbitraryU
|
|
|
|
instance Arbitrary RCErrorType where arbitrary = genericArbitraryU
|