mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-23 10:15:57 +00:00
* core: add fields to chat relay profiles * wip * wip * fix * fix * fix * enable tests * schema * api --------- Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com> Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com>
183 lines
7.1 KiB
Haskell
183 lines
7.1 KiB
Haskell
module ChatTests.ChatRelays where
|
|
|
|
import ChatClient
|
|
import ChatTests.DBUtils
|
|
import ChatTests.Utils
|
|
import Control.Concurrent (threadDelay)
|
|
import Test.Hspec hiding (it)
|
|
|
|
chatRelayTests :: SpecWith TestParams
|
|
chatRelayTests = do
|
|
describe "configure chat relays" $ do
|
|
it "get and set chat relays" testGetSetChatRelays
|
|
it "re-add soft-deleted relay by same address" testReAddRelaySameAddress
|
|
it "re-add soft-deleted relay by same name" testReAddRelaySameName
|
|
it "test chat relay" testChatRelayTest
|
|
it "relay profile updated in address" testRelayProfileUpdateInAddress
|
|
|
|
testGetSetChatRelays :: HasCallStack => TestParams -> IO ()
|
|
testGetSetChatRelays ps =
|
|
withNewTestChat ps "alice" aliceProfile $ \alice ->
|
|
withNewTestChatOpts ps relayTestOpts "bob" bobProfile $ \bob -> do
|
|
withNewTestChatOpts ps relayTestOpts "cath" cathProfile $ \cath -> do
|
|
bob ##> "/ad"
|
|
(bobSLink, _cLink) <- getContactLinks bob True
|
|
|
|
cath ##> "/ad"
|
|
(cathSLink, _cLink) <- getContactLinks cath True
|
|
|
|
alice ##> ("/relays name=bob_relay " <> bobSLink)
|
|
alice <## "ok"
|
|
|
|
alice ##> "/relays"
|
|
alice <## "Your servers"
|
|
alice <## " Chat relays"
|
|
alice <## (" bob_relay: " <> bobSLink)
|
|
|
|
alice ##> ("/relays name=cath_relay " <> cathSLink)
|
|
alice <## "ok"
|
|
|
|
alice ##> "/relays"
|
|
alice <## "Your servers"
|
|
alice <## " Chat relays"
|
|
alice <## (" cath_relay: " <> cathSLink)
|
|
|
|
alice ##> ("/relays name=bob_relay " <> bobSLink <> " name=cath_relay " <> cathSLink)
|
|
alice <## "ok"
|
|
|
|
alice ##> "/relays"
|
|
alice <## "Your servers"
|
|
alice <## " Chat relays"
|
|
alice
|
|
<### [ ConsoleString $ " bob_relay: " <> bobSLink,
|
|
ConsoleString $ " cath_relay: " <> cathSLink
|
|
]
|
|
|
|
-- Relay used by a channel is soft-deleted (referenced in group_relays).
|
|
-- Re-adding with same address should un-delete it.
|
|
testReAddRelaySameAddress :: HasCallStack => TestParams -> IO ()
|
|
testReAddRelaySameAddress ps =
|
|
withNewTestChat ps "alice" aliceProfile $ \alice ->
|
|
withNewTestChatOpts ps relayTestOpts "bob" bobProfile $ \bob ->
|
|
withNewTestChatOpts ps relayTestOpts "cath" cathProfile $ \cath -> do
|
|
bob ##> "/ad"
|
|
(bobSLink, _cLink) <- getContactLinks bob True
|
|
cath ##> "/ad"
|
|
(cathSLink, _cLink) <- getContactLinks cath True
|
|
|
|
-- Configure bob as relay and create channel (creates group_relays reference)
|
|
alice ##> ("/relays name=bob_relay " <> bobSLink)
|
|
alice <## "ok"
|
|
createChannelWithRelay "team" alice bob
|
|
|
|
-- Replace bob_relay with cath_relay (bob_relay is soft-deleted, referenced in group_relays)
|
|
alice ##> ("/relays name=cath_relay " <> cathSLink)
|
|
alice <## "ok"
|
|
|
|
alice ##> "/relays"
|
|
alice <## "Your servers"
|
|
alice <## " Chat relays"
|
|
alice <## (" cath_relay: " <> cathSLink)
|
|
|
|
-- Re-add with same address but different name - should succeed (un-deletes soft-deleted row by address)
|
|
alice ##> ("/relays name=bob_relay2 " <> bobSLink)
|
|
alice <## "ok"
|
|
|
|
alice ##> "/relays"
|
|
alice <## "Your servers"
|
|
alice <## " Chat relays"
|
|
alice <## (" bob_relay2: " <> bobSLink)
|
|
|
|
-- Relay used by a channel is soft-deleted (referenced in group_relays).
|
|
-- Re-adding with same name and same address should un-delete it.
|
|
testReAddRelaySameName :: HasCallStack => TestParams -> IO ()
|
|
testReAddRelaySameName ps =
|
|
withNewTestChat ps "alice" aliceProfile $ \alice ->
|
|
withNewTestChatOpts ps relayTestOpts "bob" bobProfile $ \bob ->
|
|
withNewTestChatOpts ps relayTestOpts "cath" cathProfile $ \cath -> do
|
|
bob ##> "/ad"
|
|
(bobSLink, _cLink) <- getContactLinks bob True
|
|
cath ##> "/ad"
|
|
(cathSLink, _cLink) <- getContactLinks cath True
|
|
|
|
-- Configure bob as relay named "my_relay" and create channel
|
|
alice ##> ("/relays name=my_relay " <> bobSLink)
|
|
alice <## "ok"
|
|
createChannelWithRelay "team" alice bob
|
|
|
|
-- Replace with cath_relay (my_relay is soft-deleted)
|
|
alice ##> ("/relays name=cath_relay " <> cathSLink)
|
|
alice <## "ok"
|
|
|
|
-- Re-add with same name and same address - should succeed (un-deletes by address match)
|
|
alice ##> ("/relays name=my_relay " <> bobSLink)
|
|
alice <## "ok"
|
|
|
|
alice ##> "/relays"
|
|
alice <## "Your servers"
|
|
alice <## " Chat relays"
|
|
alice <## (" my_relay: " <> bobSLink)
|
|
|
|
testChatRelayTest :: HasCallStack => TestParams -> IO ()
|
|
testChatRelayTest ps =
|
|
withNewTestChat ps "alice" aliceProfile $ \alice ->
|
|
withNewTestChatOpts ps relayTestOpts "bob" bobProfile $ \bob ->
|
|
withNewTestChat ps "cath" cathProfile $ \cath -> do
|
|
-- Setup: bob (relay) creates address
|
|
bob ##> "/ad"
|
|
(bobSLink, _cLink) <- getContactLinks bob True
|
|
|
|
-- Setup: cath (normal user) creates address
|
|
cath ##> "/ad"
|
|
(cathSLink, _cLink) <- getContactLinks cath True
|
|
|
|
-- Scenario 1: Happy path - test relay address succeeds
|
|
alice ##> ("/relay test " <> bobSLink)
|
|
alice <## "relay test passed, profile: bob (Bob)"
|
|
|
|
-- Scenario 2: Non-relay address - cath is not a relay user,
|
|
-- her address has ContactShortLinkData, not RelayAddressLinkData
|
|
alice ##> ("/relay test " <> cathSLink)
|
|
alice <##. "relay test failed at RTSDecodeLink, error: "
|
|
|
|
-- Scenario 3: Deleted address - bob deletes his address
|
|
bob ##> "/da"
|
|
bob <## "Your chat address is deleted - accepted contacts will remain connected."
|
|
bob <## "To create a new chat address use /ad"
|
|
alice ##> ("/relay test " <> bobSLink)
|
|
alice <##. "relay test failed at RTSGetLink, error: "
|
|
|
|
testRelayProfileUpdateInAddress :: HasCallStack => TestParams -> IO ()
|
|
testRelayProfileUpdateInAddress ps =
|
|
withNewTestChat ps "alice" aliceProfile $ \alice ->
|
|
withNewTestChatOpts ps relayTestOpts "bob" bobProfile $ \bob -> do
|
|
bob ##> "/ad"
|
|
(bobSLink, _cLink) <- getContactLinks bob True
|
|
|
|
alice ##> ("/relay test " <> bobSLink)
|
|
alice <## "relay test passed, profile: bob (Bob)"
|
|
|
|
bob ##> "/p bob2 Bob relay"
|
|
bob <## "user profile is changed to bob2 (Bob relay) (your 0 contacts are notified)"
|
|
|
|
threadDelay 100000
|
|
|
|
alice ##> ("/relay test " <> bobSLink)
|
|
alice <## "relay test passed, profile: bob2 (Bob relay)"
|
|
|
|
-- Create a public group with relay=1, wait for relay to join
|
|
createChannelWithRelay :: HasCallStack => String -> TestCC -> TestCC -> IO ()
|
|
createChannelWithRelay gName owner relay = do
|
|
owner ##> ("/public group relays=1 #" <> gName)
|
|
owner <## ("group #" <> gName <> " is created")
|
|
owner <## "wait for selected relay(s) to join, then you can invite members via group link"
|
|
concurrentlyN_
|
|
[ do
|
|
owner <## ("#" <> gName <> ": group link relays updated, current relays:")
|
|
owner <## " - relay id 1: active"
|
|
owner <## "group link:"
|
|
_ <- getTermLine owner
|
|
pure (),
|
|
relay <## ("#" <> gName <> ": you joined the group as relay")
|
|
]
|