From 73ebebef5c4aea0512cb26ac013a303445688146 Mon Sep 17 00:00:00 2001 From: "Evgeny @ SimpleX Chat" <259188159+evgeny-simplex@users.noreply.github.com> Date: Mon, 29 Jun 2026 06:46:57 +0000 Subject: [PATCH] fix tests --- tests/ChatTests/Names.hs | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/tests/ChatTests/Names.hs b/tests/ChatTests/Names.hs index 5af5c3e668..db33ff8cd7 100644 --- a/tests/ChatTests/Names.hs +++ b/tests/ChatTests/Names.hs @@ -6,15 +6,16 @@ module ChatTests.Names where import ChatClient import ChatTests.DBUtils import ChatTests.Utils -import Control.Concurrent.Async (concurrently_) import qualified Data.Text as T import NameResolver import Simplex.Messaging.SimplexName (SimplexNameDomain (..), SimplexNameInfo (..), SimplexNameType (..), SimplexTLD (..)) import Test.Hspec hiding (it) chatNamesTests :: SpecWith TestParams -chatNamesTests = +chatNamesTests = do it "connect by resolved name" testConnectByName + it "connect by name not claimed in link profile is rejected" testConnectByNameNotClaimed + it "connect by unregistered name fails to resolve" testConnectByNameNotFound testConnectByName :: HasCallStack => TestParams -> IO () testConnectByName ps = withSmpServerAndNames $ \reg -> @@ -25,9 +26,28 @@ testConnectByName ps = withSmpServerAndNames $ \reg -> alice ##> "/ad" (shortLink, _) <- getContactLinks alice True registerName reg aliceName (contactNameRecord "alice" (T.pack shortLink)) + alice ##> "/_set_name 1 @alice.simplex" + alice <## "new contact address set" bob ##> "/c @alice.simplex" - alice <#? bob - alice ##> "/ac bob" - concurrently_ - (bob <## "alice (Alice): contact is connected") - (alice <## "bob (Bob): contact is connected") + bob <## "contact address: known prepared contact alice" + bob <## "simplex name: @alice.simplex (verified)" + +testConnectByNameNotClaimed :: HasCallStack => TestParams -> IO () +testConnectByNameNotClaimed ps = withSmpServerAndNames $ \reg -> + testChat2 aliceProfile bobProfile (test reg) ps + where + aliceName = SimplexNameInfo NTContact (SimplexNameDomain TLDSimplex "alice" []) + test reg alice bob = do + alice ##> "/ad" + (shortLink, _) <- getContactLinks alice True + registerName reg aliceName (contactNameRecord "alice" (T.pack shortLink)) + bob ##> "/c @alice.simplex" + bob <## "simplex name @alice.simplex is not included in the connection link's profile" + +testConnectByNameNotFound :: HasCallStack => TestParams -> IO () +testConnectByNameNotFound ps = withSmpServerAndNames $ \_reg -> + testChat2 aliceProfile bobProfile test ps + where + test _alice bob = do + bob ##> "/c @nobody.simplex" + bob .<## "smpErr = NAME {nameErr = NOT_FOUND}}"