mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-07-11 22:48:56 +00:00
test: cover profile image size limit and address server
Adds tests for two new capabilities: - profile image size validation rejects oversized images - /_address with a server pins the address to the requested SMP server
This commit is contained in:
@@ -47,6 +47,7 @@ chatProfileTests = do
|
||||
describe "user profiles" $ do
|
||||
it "update user profile and notify contacts" testUpdateProfile
|
||||
it "update user profile with image" testUpdateProfileImage
|
||||
it "reject profile image that is too large" testSetProfileImageTooLarge
|
||||
it "use multiword profile names" testMultiWordProfileNames
|
||||
it "present supporter badge to contacts" testUserBadgeBroadcast
|
||||
it "supporter badge sent to contact connecting after attach" testUserBadgeOnConnect
|
||||
@@ -57,6 +58,7 @@ chatProfileTests = do
|
||||
it "supporter badge sent to contact connecting via address" testUserBadgeContactAddress
|
||||
describe "user contact link" $ do
|
||||
it "create and connect via contact link" testUserContactLink
|
||||
it "create address on specified server" testCreateAddressOnServer
|
||||
it "retry connecting via contact link" testRetryConnectingViaContactLink
|
||||
it "add contact link to profile" testProfileLink
|
||||
it "auto accept contact requests" testUserContactLinkAutoAccept
|
||||
@@ -423,6 +425,24 @@ testUpdateProfileImage =
|
||||
bob <## "use @alice2 <message> to send messages"
|
||||
(bob </)
|
||||
|
||||
testSetProfileImageTooLarge :: HasCallStack => TestParams -> IO ()
|
||||
testSetProfileImageTooLarge =
|
||||
testChat2 aliceProfile bobProfile $
|
||||
\alice bob -> do
|
||||
connectUsers alice bob
|
||||
-- image within the size limit is accepted
|
||||
alice ##> "/set profile image data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIAQMAAAD+wSzIAAAABlBMVEX///+/v7+jQ3Y5AAAADklEQVQI12P4AIX8EAgALgAD/aNpbtEAAAAASUVORK5CYII="
|
||||
alice <## "profile image updated"
|
||||
-- image over the size limit is rejected;
|
||||
-- the long command wraps in the virtual terminal, so drain echo lines until the error
|
||||
alice `send` ("/set profile image data:image/png;base64," <> replicate 12500 'A')
|
||||
let errPrefix = "bad chat command: Profile image is too large"
|
||||
expectError = do
|
||||
l <- getTermLine alice
|
||||
unless (take (length errPrefix) l == errPrefix) expectError
|
||||
expectError
|
||||
(bob </)
|
||||
|
||||
testMultiWordProfileNames :: HasCallStack => TestParams -> IO ()
|
||||
testMultiWordProfileNames =
|
||||
testChat3 aliceProfile' bobProfile' cathProfile' $
|
||||
@@ -529,6 +549,32 @@ testUserContactLink =
|
||||
alice @@@ [("@cath", lastChatFeature), ("@bob", "hey")]
|
||||
alice <##> cath
|
||||
|
||||
testCreateAddressOnServer :: HasCallStack => TestParams -> IO ()
|
||||
testCreateAddressOnServer ps = testChat aliceProfile test ps
|
||||
where
|
||||
tmp = tmpPath ps
|
||||
-- second SMP server, distinct from alice's configured server (localhost:7001)
|
||||
altServer = "smp://LcJUMfVhwD8yxjAiSaDzzGF3-kLG4Uh0Fl_ZIjrRwjI=:server_password@localhost:7003"
|
||||
altServerCfg =
|
||||
smpServerCfg
|
||||
{ transports = [("7003", transport @TLS, False)],
|
||||
serverStoreCfg = persistentServerStoreCfg tmp
|
||||
}
|
||||
test alice = do
|
||||
withSmpServer' altServerCfg $ do
|
||||
-- without a server the address is created on the configured server (7001)
|
||||
alice ##> "/_address 1"
|
||||
(_, defaultLink) <- getContactLinks alice True
|
||||
defaultLink `shouldContain` "localhost%3A7001" -- server is URL-encoded in the link
|
||||
alice ##> "/_delete_address 1"
|
||||
alice <## "Your chat address is deleted - accepted contacts will remain connected."
|
||||
alice <## "To create a new chat address use /ad"
|
||||
-- with a server the address is pinned to the requested server (7003)
|
||||
alice ##> ("/_address 1 " <> altServer)
|
||||
(_, pinnedLink) <- getContactLinks alice True
|
||||
pinnedLink `shouldContain` "localhost%3A7003"
|
||||
alice <## "disconnected 1 connections on server localhost"
|
||||
|
||||
testRetryConnectingViaContactLink :: HasCallStack => TestParams -> IO ()
|
||||
testRetryConnectingViaContactLink ps = testChatCfgOpts2 cfg' opts' aliceProfile bobProfile test ps
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user