@@ -78,7 +78,7 @@ import Data.Type.Equality (testEquality, (:~:) (Refl))
7878import Data.Word (Word16 )
7979import GHC.Stack (withFrozenCallStack )
8080import SMPAgentClient
81- import SMPClient (cfgMS , cfgJ2QS , prevRange , prevVersion , testPort , testPort2 , testStoreLogFile , withSmpServer , withSmpServers2 , withSmpServerConfigOn , withSmpServerProxy , withSmpServersProxy2 , withSmpServerStoreLogOn , withSmpServerStoreMsgLogOn )
81+ import SMPClient (cfgJ2QS , cfgMS , prevRange , prevVersion , proxyCfgJ2QS , proxyCfgMS , testPort , testPort2 , testStoreLogFile , withSmpServer , withSmpServers2 , withSmpServerConfigOn , withSmpServerProxy , withSmpServersProxy2 , withSmpServerStoreLogOn , withSmpServerStoreMsgLogOn )
8282import Simplex.Messaging.Agent hiding (createConnection , joinConnection , sendMessage )
8383import qualified Simplex.Messaging.Agent as A
8484import Simplex.Messaging.Agent.Client (ProtocolTestFailure (.. ), ProtocolTestStep (.. ), ServerQueueInfo (.. ), UserNetworkInfo (.. ), UserNetworkType (.. ), waitForUserNetwork )
@@ -102,7 +102,7 @@ import Simplex.Messaging.Server.Env.STM (AServerStoreCfg (..), AStoreType (..),
102102import Simplex.Messaging.Server.Expiration
103103import Simplex.Messaging.Server.MsgStore.Types (SMSType (.. ), SQSType (.. ))
104104import Simplex.Messaging.Server.QueueStore.QueueInfo
105- import Simplex.Messaging.Transport (ATransport (.. ), SMPVersion , VersionSMP , authCmdsSMPVersion , currentServerSMPRelayVersion , minClientSMPRelayVersion , minServerSMPRelayVersion , sendingProxySMPVersion , sndAuthKeySMPVersion , supportedSMPHandshakes )
105+ import Simplex.Messaging.Transport (ATransport (.. ), SMPVersion , VersionSMP , authCmdsSMPVersion , currentServerSMPRelayVersion , minClientSMPRelayVersion , minServerSMPRelayVersion , sendingProxySMPVersion , sndAuthKeySMPVersion , supportedSMPHandshakes , supportedServerSMPRelayVRange )
106106import Simplex.Messaging.Util (bshow , diffToMicroseconds )
107107import Simplex.Messaging.Version (VersionRange (.. ))
108108import qualified Simplex.Messaging.Version as V
@@ -315,6 +315,7 @@ functionalAPITests ps = do
315315 describe " should connect via 1-time short link with async join" $ testProxyMatrix ps testInviationShortLinkAsync
316316 describe " should connect via contact short link" $ testProxyMatrix ps testContactShortLink
317317 describe " should add short link to existing contact and connect" $ testProxyMatrix ps testAddContactShortLink
318+ describe " try to create 1-time short link with prev versions" $ testProxyMatrixWithPrev ps testInviationShortLinkPrev
318319 describe " server restart" $ do
319320 it " should get 1-time link data after restart" $ testInviationShortLinkRestart ps
320321 it " should connect via contact short link after restart" $ testContactShortLinkRestart ps
@@ -547,8 +548,21 @@ testServerMatrix2 ps runTest = do
547548
548549testProxyMatrix :: HasCallStack => (ATransport , AStoreType ) -> (Bool -> AgentClient -> AgentClient -> IO () ) -> Spec
549550testProxyMatrix ps runTest = do
550- it " 2 servers, directly" $ withSmpServers2 ps $ withAgentClientsServers2 initAgentServers initAgentServers2 $ runTest False
551- it " 2 servers, via proxy" $ withSmpServersProxy2 ps $ withAgentClientsServers2 initAgentServersProxy initAgentServersProxy2 $ runTest True
551+ it " 2 servers, directly" $ withSmpServers2 ps $ withAgentClientsServers2 (agentCfg, initAgentServers) (agentCfg, initAgentServers2) $ runTest False
552+ it " 2 servers, via proxy" $ withSmpServersProxy2 ps $ withAgentClientsServers2 (agentCfg, initAgentServersProxy) (agentCfg, initAgentServersProxy2) $ runTest True
553+
554+ testProxyMatrixWithPrev :: HasCallStack => (ATransport , AStoreType ) -> (Bool -> Bool -> AgentClient -> AgentClient -> IO () ) -> Spec
555+ testProxyMatrixWithPrev ps@ (t, msType@ (ASType qs _ms)) runTest = do
556+ it " 2 servers, directly, curr clients, prev servers" $ withSmpServers2Prev $ withAgentClientsServers2 (agentCfg, initAgentServers) (agentCfg, initAgentServers2) $ runTest False True
557+ it " 2 servers, via proxy, curr clients, prev servers" $ withSmpServersProxy2Prev $ withAgentClientsServers2 (agentCfg, initAgentServersProxy) (agentCfg, initAgentServersProxy2) $ runTest True True
558+ it " 2 servers, directly, prev clients, curr servers" $ withSmpServers2 ps $ withAgentClientsServers2 (agentCfgVPrevPQ, initAgentServers) (agentCfgVPrevPQ, initAgentServers2) $ runTest False False
559+ it " 2 servers, via proxy, prev clients, curr servers" $ withSmpServersProxy2 ps $ withAgentClientsServers2 (agentCfgVPrevPQ, initAgentServersProxy) (agentCfgVPrevPQ, initAgentServersProxy2) $ runTest True False
560+ where
561+ prev cfg' = cfg' {smpServerVRange = prevRange supportedServerSMPRelayVRange}
562+ withSmpServers2Prev a = withServers2 (prev $ cfgMS msType) (prev $ cfgJ2QS qs) a
563+ withSmpServersProxy2Prev a = withServers2 (prev $ proxyCfgMS msType) (prev $ proxyCfgJ2QS qs) a
564+ withServers2 cfg1 cfg2 a =
565+ withSmpServerConfigOn t cfg1 testPort $ \ _ -> withSmpServerConfigOn t cfg2 testPort2 $ \ _ -> a
552566
553567testPQMatrix2 :: HasCallStack => (ATransport , AStoreType ) -> (HasCallStack => (AgentClient , InitialKeys ) -> (AgentClient , PQSupport ) -> AgentMsgId -> IO () ) -> Spec
554568testPQMatrix2 = pqMatrix2_ True
@@ -604,10 +618,10 @@ withAgentClientsCfgServers2 aCfg bCfg servers runTest =
604618 withAgent 2 bCfg servers testDB2 $ \ b ->
605619 runTest a b
606620
607- withAgentClientsServers2 :: HasCallStack => InitialAgentServers -> InitialAgentServers -> (HasCallStack => AgentClient -> AgentClient -> IO a ) -> IO a
608- withAgentClientsServers2 aServers bServers runTest =
609- withAgent 1 agentCfg aServers testDB $ \ a ->
610- withAgent 2 agentCfg bServers testDB2 $ \ b ->
621+ withAgentClientsServers2 :: HasCallStack => ( AgentConfig , InitialAgentServers ) -> ( AgentConfig , InitialAgentServers ) -> (HasCallStack => AgentClient -> AgentClient -> IO a ) -> IO a
622+ withAgentClientsServers2 (aCfg, aServers) (bCfg, bServers) runTest =
623+ withAgent 1 aCfg aServers testDB $ \ a ->
624+ withAgent 2 bCfg bServers testDB2 $ \ b ->
611625 runTest a b
612626
613627withAgentClientsCfg2 :: HasCallStack => AgentConfig -> AgentConfig -> (HasCallStack => AgentClient -> AgentClient -> IO a ) -> IO a
@@ -1114,16 +1128,26 @@ testInviationShortLink viaProxy a b =
11141128 runExceptT (getConnShortLink c 1 shortLink) >>= \ case
11151129 Left (SMP _ AUTH ) -> pure ()
11161130 r -> liftIO $ expectationFailure (" unexpected result " <> show r)
1117- runRight $ do
1118- aId <- A. prepareConnectionToJoin b 1 True connReq PQSupportOn
1119- sndSecure <- A. joinConnection b 1 aId True connReq " bob's connInfo" PQSupportOn SMSubscribe
1120- liftIO $ sndSecure `shouldBe` True
1121- (" " , _, CONF confId _ " bob's connInfo" ) <- get a
1122- allowConnection a bId confId " alice's connInfo"
1123- get a ##> (" " , bId, CON )
1124- get b ##> (" " , aId, INFO " alice's connInfo" )
1125- get b ##> (" " , aId, CON )
1126- exchangeGreetingsViaProxy viaProxy a bId b aId
1131+ runRight $ testJoinConn_ viaProxy True a bId b connReq
1132+
1133+ testJoinConn_ :: Bool -> Bool -> AgentClient -> ConnId -> AgentClient -> ConnectionRequestUri c -> ExceptT AgentErrorType IO ()
1134+ testJoinConn_ viaProxy sndSecure a bId b connReq = do
1135+ aId <- A. prepareConnectionToJoin b 1 True connReq PQSupportOn
1136+ sndSecure' <- A. joinConnection b 1 aId True connReq " bob's connInfo" PQSupportOn SMSubscribe
1137+ liftIO $ sndSecure' `shouldBe` sndSecure
1138+ (" " , _, CONF confId _ " bob's connInfo" ) <- get a
1139+ allowConnection a bId confId " alice's connInfo"
1140+ get a ##> (" " , bId, CON )
1141+ get b ##> (" " , aId, INFO " alice's connInfo" )
1142+ get b ##> (" " , aId, CON )
1143+ exchangeGreetingsViaProxy viaProxy a bId b aId
1144+
1145+ testInviationShortLinkPrev :: HasCallStack => Bool -> Bool -> AgentClient -> AgentClient -> IO ()
1146+ testInviationShortLinkPrev viaProxy sndSecure a b = runRight_ $ do
1147+ let userData = " some user data"
1148+ -- can't create short link with previous version
1149+ (bId, CCLink connReq Nothing ) <- A. createConnection a 1 True SCMInvitation (Just userData) Nothing CR. IKPQOn SMSubscribe
1150+ testJoinConn_ viaProxy sndSecure a bId b connReq
11271151
11281152testInviationShortLinkAsync :: HasCallStack => Bool -> AgentClient -> AgentClient -> IO ()
11291153testInviationShortLinkAsync viaProxy a b = do
0 commit comments