core: set short links data, prepare entity, etc.; ios: connect to prepared contact (#5951)

This commit is contained in:
spaced4ndy authored and GitHub committed 2025-06-04 07:47:10 +00:00
1 parent b4e48dac29
commit 8a4760a2cb
64 files changed
+1117 -547

No files matched your search

+7
View File
@@ -248,6 +248,7 @@ testRetryConnecting ps = testChatCfgOpts2 cfg' opts' aliceProfile bobProfile tes
alice <## "server disconnected localhost ()"
bob ##> ("/_connect plan 1 " <> inv)
bob <## "invitation link: ok to connect"
_sLinkData <- getTermLine bob
bob ##> ("/_connect 1 " <> inv)
bob <##. "smp agent error: BROKER"
withSmpServer' serverCfg' $ do
@@ -255,6 +256,7 @@ testRetryConnecting ps = testChatCfgOpts2 cfg' opts' aliceProfile bobProfile tes
threadDelay 250000
bob ##> ("/_connect plan 1 " <> inv)
bob <## "invitation link: ok to connect"
_sLinkData <- getTermLine bob
bob ##> ("/_connect 1 " <> inv)
bob <## "confirmation sent!"
concurrently_
@@ -299,6 +301,7 @@ testRetryConnectingClientTimeout ps = do
withNewTestChatCfgOpts ps cfgZeroTimeout opts' "bob" bobProfile $ \bob -> do
bob ##> ("/_connect plan 1 " <> inv)
bob <## "invitation link: ok to connect"
_sLinkData <- getTermLine bob
bob ##> ("/_connect 1 " <> inv)
bob <## "smp agent error: BROKER {brokerAddress = \"smp://LcJUMfVhwD8yxjAiSaDzzGF3-kLG4Uh0Fl_ZIjrRwjI=@localhost:7003\", brokerErr = TIMEOUT}"
@@ -312,6 +315,7 @@ testRetryConnectingClientTimeout ps = do
withTestChatCfgOpts ps cfg' opts' "bob" $ \bob -> do
bob ##> ("/_connect plan 1 " <> inv)
bob <## "invitation link: ok to connect"
_sLinkData <- getTermLine bob
bob ##> ("/_connect 1 " <> inv)
bob <## "confirmation sent!"
@@ -478,6 +482,7 @@ testPlanInvitationLinkOk =
inv <- getInvitation alice
bob ##> ("/_connect plan 1 " <> inv)
bob <## "invitation link: ok to connect"
_sLinkData <- getTermLine bob
bob ##> ("/c " <> inv)
bob <## "confirmation sent!"
@@ -487,6 +492,7 @@ testPlanInvitationLinkOk =
bob ##> ("/_connect plan 1 " <> inv)
bob <## "invitation link: ok to connect" -- conn_req_inv is forgotten after connection
_sLinkData <- getTermLine bob
alice <##> bob
testPlanInvitationLinkOwn :: HasCallStack => TestParams -> IO ()
@@ -510,6 +516,7 @@ testPlanInvitationLinkOwn ps =
alice ##> ("/_connect plan 1 " <> inv)
alice <## "invitation link: ok to connect" -- conn_req_inv is forgotten after connection
_sLinkData <- getTermLine alice
threadDelay 100000
alice @@@ [("@alice_1", lastChatFeature), ("@alice_2", lastChatFeature)]
alice `send` "@alice_2 hi"
+3
View File
@@ -2425,10 +2425,12 @@ testPlanGroupLinkLeaveRejoin =
bob ##> ("/_connect plan 1 " <> gLink)
bob <## "group link: ok to connect"
_sLinkData <- getTermLine bob
let gLinkSchema2 = linkAnotherSchema gLink
bob ##> ("/_connect plan 1 " <> gLinkSchema2)
bob <## "group link: ok to connect"
_sLinkData <- getTermLine bob
bob ##> ("/c " <> gLink)
bob <## "connection request sent!"
@@ -3357,6 +3359,7 @@ testPlanGroupLinkKnown =
bob ##> ("/_connect plan 1 " <> gLink)
bob <## "group link: ok to connect"
_sLinkData <- getTermLine bob
bob ##> ("/c " <> gLink)
bob <## "connection request sent!"
+67 -4
View File
@@ -102,10 +102,13 @@ chatProfileTests = do
it "SimpleX links" testGroupPrefsSimplexLinksForRole
it "set user, contact and group UI theme" testSetUITheme
describe "short links" $ do
it "should connect via one-time inviation" testShortLinkInvitation
it "should plan and connect via one-time inviation" testPlanShortLinkInvitation
it "should connect via one-time invitation" testShortLinkInvitation
it "should plan and connect via one-time invitation" testPlanShortLinkInvitation
it "should connect via contact address" testShortLinkContactAddress
it "should join group" testShortLinkJoinGroup
describe "connection via prepared entity" $ do
it "prepare contact using invitation short link data and connect" testShortLinkInvitationPrepareContact
it "prepare contact using address short link data and connect" testShortLinkAddressPrepareContact
testUpdateProfile :: HasCallStack => TestParams -> IO ()
testUpdateProfile =
@@ -285,6 +288,7 @@ testRetryAcceptingViaContactLink ps = testChatCfgOpts2 cfg' opts' aliceProfile b
alice <## "server disconnected localhost ()"
bob ##> ("/_connect plan 1 " <> cLink)
bob <## "contact address: ok to connect"
_sLinkData <- getTermLine bob
bob ##> ("/_connect 1 " <> cLink)
bob <##. "smp agent error: BROKER"
withSmpServer' serverCfg' $ do
@@ -292,6 +296,7 @@ testRetryAcceptingViaContactLink ps = testChatCfgOpts2 cfg' opts' aliceProfile b
threadDelay 250000
bob ##> ("/_connect plan 1 " <> cLink)
bob <## "contact address: ok to connect"
_sLinkData <- getTermLine bob
bob ##> ("/_connect 1 " <> cLink)
alice <#? bob
alice <## "server disconnected localhost ()"
@@ -701,6 +706,7 @@ testBusinessAddress = testChat3 businessProfile aliceProfile {fullName = "Alice
biz <## "auto_accept on, business"
bob ##> ("/_connect plan 1 " <> cLink)
bob <## "contact address: ok to connect"
_sLinkData <- getTermLine bob
bob ##> ("/c " <> cLink)
bob <## "connection request sent!"
bob ##> ("/_connect plan 1 " <> cLink)
@@ -886,6 +892,7 @@ testPlanAddressOkKnown =
bob ##> ("/_connect plan 1 " <> cLink)
bob <## "contact address: ok to connect"
_sLinkData <- getTermLine bob
bob ##> ("/c " <> cLink)
alice <#? bob
@@ -1068,10 +1075,12 @@ testPlanAddressContactDeletedReconnected =
bob ##> ("/_connect plan 1 " <> cLink)
bob <## "contact address: ok to connect"
_sLinkData <- getTermLine bob
let cLinkSchema2 = linkAnotherSchema cLink
bob ##> ("/_connect plan 1 " <> cLinkSchema2)
bob <## "contact address: ok to connect"
_sLinkData <- getTermLine bob
bob ##> ("/c " <> cLink)
bob <## "connection request sent!"
@@ -2593,7 +2602,7 @@ testShortLinkInvitation :: HasCallStack => TestParams -> IO ()
testShortLinkInvitation =
testChat2 aliceProfile bobProfile $ \alice bob -> do
alice ##> "/c short"
inv <- getShortInvitation alice
(inv, _) <- getShortInvitation alice
bob ##> ("/c " <> inv)
bob <## "confirmation sent!"
concurrently_
@@ -2608,13 +2617,14 @@ testPlanShortLinkInvitation :: HasCallStack => TestParams -> IO ()
testPlanShortLinkInvitation =
testChat3 aliceProfile bobProfile cathProfile $ \alice bob cath -> do
alice ##> "/c short"
inv <- getShortInvitation alice
(inv, _) <- getShortInvitation alice
alice ##> ("/_connect plan 1 " <> inv)
alice <## "invitation link: own link"
alice ##> ("/_connect plan 1 " <> slSimplexScheme inv)
alice <## "invitation link: own link"
bob ##> ("/_connect plan 1 " <> inv)
bob <## "invitation link: ok to connect"
_sLinkData <- getTermLine bob
-- nobody else can connect
cath ##> ("/_connect plan 1 " <> inv)
cath <##. "error: connection authorization failed"
@@ -2623,9 +2633,11 @@ testPlanShortLinkInvitation =
-- bob can retry "plan"
bob ##> ("/_connect plan 1 " <> inv)
bob <## "invitation link: ok to connect"
_sLinkData <- getTermLine bob
-- with simplex: scheme too
bob ##> ("/_connect plan 1 " <> slSimplexScheme inv)
bob <## "invitation link: ok to connect"
_sLinkData <- getTermLine bob
bob ##> ("/c " <> inv)
bob <## "confirmation sent!"
concurrently_
@@ -2669,6 +2681,7 @@ testShortLinkContactAddress =
sName <- showName cc
cc ##> ("/_connect plan 1 " <> cLink)
cc <## "contact address: ok to connect"
_sLinkData <- getTermLine cc
cc ##> ("/c " <> cLink)
alice <#? cc
alice ##> ("/ac " <> name)
@@ -2738,6 +2751,7 @@ testShortLinkJoinGroup =
sName <- showName cc
cc ##> ("/_connect plan 1 " <> link)
cc <## "group link: ok to connect"
_sLinkData <- getTermLine cc
cc ##> ("/c " <> link)
cc <## "connection request sent!"
alice <## (sName <> ": accepting request to join group #team...")
@@ -2747,3 +2761,52 @@ testShortLinkJoinGroup =
cc <## "#team: joining the group..."
cc <## "#team: you joined the group"
]
testShortLinkInvitationPrepareContact :: HasCallStack => TestParams -> IO ()
testShortLinkInvitationPrepareContact =
testChat2 aliceProfile bobProfile $
\alice bob -> do
alice ##> "/_connect 1 short=on"
(shortLink, fullLink) <- getShortInvitation alice
bob ##> ("/_connect plan 1 " <> shortLink)
bob <## "invitation link: ok to connect"
contactSLinkData <- getTermLine bob
bob ##> ("/_prepare contact 1 " <> fullLink <> " " <> shortLink <> " " <> contactSLinkData)
bob <## "alice: contact is prepared"
bob ##> "/_connect contact @2 text hello"
bob
<### [ "alice: connection started",
WithTime "@alice hello"
]
alice <# "bob> hello"
concurrently_
(bob <## "alice (Alice): contact is connected")
(alice <## "bob (Bob): contact is connected")
alice <##> bob
testShortLinkAddressPrepareContact :: HasCallStack => TestParams -> IO ()
testShortLinkAddressPrepareContact =
testChat2 aliceProfile bobProfile $
\alice bob -> do
alice ##> "/ad short"
(shortLink, fullLink) <- getShortContactLink alice True
bob ##> ("/_connect plan 1 " <> shortLink)
bob <## "contact address: ok to connect"
contactSLinkData <- getTermLine bob
bob ##> ("/_prepare contact 1 " <> fullLink <> " " <> shortLink <> " " <> contactSLinkData)
bob <## "alice: contact is prepared"
bob ##> "/_connect contact @2 text hello"
bob
<### [ "alice: connection started",
WithTime "@alice hello"
]
-- TODO [short links] for alice create message from contact request
alice <## "bob (Bob) wants to connect to you!"
alice <## "to accept: /ac bob"
alice <## "to reject: /rc bob (the sender will NOT be notified)"
alice ##> "/ac bob"
alice <## "bob (Bob): accepting contact request, you can send messages to contact"
concurrently_
(bob <## "alice (Alice): contact is connected")
(alice <## "bob (Bob): contact is connected")
alice <##> bob
+12 -5
View File
@@ -505,20 +505,27 @@ dropPartialReceipt_ msg = case splitAt 2 msg of
_ -> Nothing
getInvitation :: HasCallStack => TestCC -> IO String
getInvitation = getInvitation_ False
getInvitation cc = do
(inv, _) <- getInvitation_ False cc
pure inv
getShortInvitation :: HasCallStack => TestCC -> IO String
getShortInvitation :: HasCallStack => TestCC -> IO (String, String)
getShortInvitation = getInvitation_ True
getInvitation_ :: HasCallStack => Bool -> TestCC -> IO String
getInvitation_ :: HasCallStack => Bool -> TestCC -> IO (String, String)
getInvitation_ short cc = do
cc <## "pass this invitation link to your contact (via another channel):"
cc <## ""
inv <- getTermLine cc
cc <## ""
cc <## "and ask them to connect: /c <invitation_link_above>"
when short $ cc <##. "The invitation link for old clients: https://simplex.chat/invitation#"
pure inv
fullLink <-
if short
then do
cc <##. "The invitation link for old clients:"
getTermLine cc
else pure ""
pure (inv, fullLink)
getShortContactLink :: HasCallStack => TestCC -> Bool -> IO (String, String)
getShortContactLink cc created = do