From cf3c7d152a540f445035156e68a5dbb2e259530a Mon Sep 17 00:00:00 2001 From: shum Date: Thu, 4 Jun 2026 16:07:12 +0000 Subject: [PATCH] chat: test outgoing Profile carries simplexName from User profile userProfileDirect, userProfileInGroup' and redactedMemberProfile already pass simplexName through via fromLocalProfile (Task 1) once the embedded LocalProfile field is populated (previous commit). Lock that behavior in with focused unit tests: - userProfileDirect with Just simplexName -> wire Profile.simplexName Just - userProfileDirect with Nothing -> wire Nothing - userProfileDirect with an incognito Profile overlay -> wire Nothing (incognito identity must not leak the user's registered name) - userProfileInGroup' pass-through - redactedMemberProfile pass-through (forwarded member profiles) --- tests/ProtocolTests.hs | 59 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/tests/ProtocolTests.hs b/tests/ProtocolTests.hs index 245ad8bd42..fc67580750 100644 --- a/tests/ProtocolTests.hs +++ b/tests/ProtocolTests.hs @@ -9,6 +9,7 @@ module ProtocolTests where import qualified Data.Aeson as J import Data.ByteString.Char8 (ByteString) import Data.Time.Clock.System (SystemTime (..), systemToUTCTime) +import Simplex.Chat.Library.Internal (redactedMemberProfile, userProfileInGroup') import Simplex.Chat.Protocol import Simplex.Chat.Types import Simplex.Chat.Types.Preferences @@ -22,7 +23,9 @@ import Simplex.Messaging.Version import Test.Hspec protocolTests :: Spec -protocolTests = decodeChatMessageTest +protocolTests = do + decodeChatMessageTest + outgoingProfileSimplexNameTest srv :: SMPServer srv = SMPServer "smp.simplex.im" "5223" (C.KeyHash "\215m\248\251") @@ -321,3 +324,57 @@ decodeChatMessageTest = describe "Chat message encoding/decoding" $ do it "x.ok" $ "{\"v\":\"1\",\"event\":\"x.ok\",\"params\":{}}" ==# XOk + +testUser :: Maybe SimplexNameInfo -> User +testUser sn = + User + { userId = 1, + agentUserId = AgentUserId 1, + userContactId = 1, + localDisplayName = "alice", + profile = + LocalProfile + { profileId = 1, + displayName = "alice", + fullName = "Alice", + shortDescr = Nothing, + image = Nothing, + contactLink = Nothing, + simplexName = sn, + preferences = Nothing, + peerType = Nothing, + localAlias = "" + }, + fullPreferences = fullPreferences' Nothing, + activeUser = True, + activeOrder = 1, + viewPwdHash = Nothing, + showNtfs = True, + sendRcptsContacts = True, + sendRcptsSmallGroups = True, + autoAcceptMemberContacts = False, + userMemberProfileUpdatedAt = Nothing, + userChatRelay = BoolDef False, + clientService = BoolDef False, + uiThemes = Nothing + } + +outgoingProfileSimplexNameTest :: Spec +outgoingProfileSimplexNameTest = describe "outgoing Profile carries User.profile.simplexName" $ do + it "userProfileDirect passes simplexName through to wire Profile" $ do + let Profile {simplexName = sn} = userProfileDirect (testUser (Just testSimplexName)) Nothing Nothing True + sn `shouldBe` Just testSimplexName + it "userProfileDirect with Nothing on User.profile leaves wire simplexName Nothing" $ do + let Profile {simplexName = sn} = userProfileDirect (testUser Nothing) Nothing Nothing True + sn `shouldBe` Nothing + it "userProfileDirect with incognito profile suppresses simplexName" $ do + let incognito = Profile {displayName = "anon", fullName = "", shortDescr = Nothing, image = Nothing, contactLink = Nothing, simplexName = Nothing, peerType = Nothing, preferences = Nothing} + Profile {simplexName = sn} = userProfileDirect (testUser (Just testSimplexName)) (Just incognito) Nothing True + sn `shouldBe` Nothing + it "userProfileInGroup' passes simplexName through" $ do + let Profile {simplexName = sn} = userProfileInGroup' (testUser (Just testSimplexName)) True Nothing + sn `shouldBe` Just testSimplexName + it "redactedMemberProfile preserves simplexName" $ do + let p0 = Profile {displayName = "alice", fullName = "Alice", shortDescr = Nothing, image = Nothing, contactLink = Nothing, simplexName = Just testSimplexName, peerType = Nothing, preferences = Nothing} + Profile {simplexName = sn} = redactedMemberProfile True p0 + sn `shouldBe` Just testSimplexName