@@ -53,18 +53,21 @@ import Data.ByteString.Char8 (ByteString)
5353import qualified Data.ByteString.Char8 as B
5454import Data.List.NonEmpty (NonEmpty (.. ))
5555import qualified Data.List.NonEmpty as L
56+ import Data.Text (Text )
57+ import qualified Data.Text as T
5658import Data.Text.Encoding (encodeUtf8 )
59+ import qualified Data.Text.IO as TIO
5760import NtfClient
5861import SMPAgentClient (agentCfg , initAgentServers , initAgentServers2 , testDB , testDB2 , testNtfServer , testNtfServer2 )
59- import SMPClient (cfg , cfgVPrev , testPort , testPort2 , testStoreLogFile2 , testStoreMsgsDir2 , withSmpServer , withSmpServerConfigOn , withSmpServerStoreLogOn , withSmpServerStoreMsgLogOn )
62+ import SMPClient (cfg , cfgVPrev , testPort , testPort2 , testStoreLogFile2 , testStoreMsgsDir2 , withSmpServer , withSmpServerConfigOn , withSmpServerStoreLogOn , withSmpServerStoreMsgLogOn , xit'' )
6063import Simplex.Messaging.Agent hiding (createConnection , joinConnection , sendMessage )
6164import Simplex.Messaging.Agent.Client (ProtocolTestFailure (.. ), ProtocolTestStep (.. ), withStore' )
6265import Simplex.Messaging.Agent.Env.SQLite (AgentConfig , Env (.. ), InitialAgentServers )
6366import Simplex.Messaging.Agent.Protocol hiding (CON , CONF , INFO , SENT )
6467import Simplex.Messaging.Agent.Store.AgentStore (getSavedNtfToken )
6568import Simplex.Messaging.Agent.Store.Common (withTransaction )
66- import Simplex.Messaging.Agent.Store.Interface (closeDBStore , reopenDBStore )
6769import qualified Simplex.Messaging.Agent.Store.DB as DB
70+ import Simplex.Messaging.Agent.Store.Interface (closeDBStore , reopenDBStore )
6871import qualified Simplex.Messaging.Crypto as C
6972import Simplex.Messaging.Encoding.String
7073import Simplex.Messaging.Notifications.Protocol
@@ -117,6 +120,12 @@ notificationTests t = do
117120 it " should keep working with active token until replaced" $
118121 withAPNSMockServer $ \ apns ->
119122 testNtfTokenChangeServers t apns
123+ xit'' " should re-register token in NTInvalid status after register attempt" $
124+ withAPNSMockServer $ \ apns ->
125+ testNtfTokenReRegisterInvalid t apns
126+ xit'' " should re-register token in NTInvalid status after checking token" $
127+ withAPNSMockServer $ \ apns ->
128+ testNtfTokenReRegisterInvalidOnCheck t apns
120129 describe " notification server tests" $ do
121130 it " should pass" $ testRunNTFServerTests t testNtfServer `shouldReturn` Nothing
122131 let srv1 = testNtfServer {keyHash = " 1234" }
@@ -459,6 +468,58 @@ testNtfTokenChangeServers t apns =
459468 tkn <- registerTestToken a " qwer" NMInstant apns
460469 checkNtfToken a tkn >>= \ r -> liftIO $ r `shouldBe` NTActive
461470
471+ testNtfTokenReRegisterInvalid :: ATransport -> APNSMockServer -> IO ()
472+ testNtfTokenReRegisterInvalid t apns = do
473+ tkn <- withNtfServerStoreLog t $ \ _ -> do
474+ withAgent 1 agentCfg initAgentServers testDB $ \ a -> runRight $ do
475+ tkn <- registerTestToken a " abcd" NMInstant apns
476+ NTActive <- checkNtfToken a tkn
477+ pure tkn
478+
479+ threadDelay 250000
480+ -- start server to compact
481+ withNtfServerStoreLog t $ \ _ -> pure ()
482+
483+ threadDelay 250000
484+ replaceSubstringInFile ntfTestStoreLogFile " tokenStatus=ACTIVE" " tokenStatus=INVALID"
485+
486+ threadDelay 250000
487+ withNtfServerStoreLog t $ \ _ -> do
488+ withAgent 1 agentCfg initAgentServers testDB $ \ a -> runRight_ $ do
489+ NTInvalid Nothing <- registerNtfToken a tkn NMInstant
490+ tkn1 <- registerTestToken a " abcd" NMInstant apns
491+ NTActive <- checkNtfToken a tkn1
492+ pure ()
493+
494+ replaceSubstringInFile :: FilePath -> Text -> Text -> IO ()
495+ replaceSubstringInFile filePath oldText newText = do
496+ content <- TIO. readFile filePath
497+ let newContent = T. replace oldText newText content
498+ TIO. writeFile filePath newContent
499+
500+ testNtfTokenReRegisterInvalidOnCheck :: ATransport -> APNSMockServer -> IO ()
501+ testNtfTokenReRegisterInvalidOnCheck t apns = do
502+ tkn <- withNtfServerStoreLog t $ \ _ -> do
503+ withAgent 1 agentCfg initAgentServers testDB $ \ a -> runRight $ do
504+ tkn <- registerTestToken a " abcd" NMInstant apns
505+ NTActive <- checkNtfToken a tkn
506+ pure tkn
507+
508+ threadDelay 250000
509+ -- start server to compact
510+ withNtfServerStoreLog t $ \ _ -> pure ()
511+
512+ threadDelay 250000
513+ replaceSubstringInFile ntfTestStoreLogFile " tokenStatus=ACTIVE" " tokenStatus=INVALID"
514+
515+ threadDelay 250000
516+ withNtfServerStoreLog t $ \ _ -> do
517+ withAgent 1 agentCfg initAgentServers testDB $ \ a -> runRight_ $ do
518+ NTInvalid Nothing <- checkNtfToken a tkn
519+ tkn1 <- registerTestToken a " abcd" NMInstant apns
520+ NTActive <- checkNtfToken a tkn1
521+ pure ()
522+
462523testRunNTFServerTests :: ATransport -> NtfServer -> IO (Maybe ProtocolTestFailure )
463524testRunNTFServerTests t srv =
464525 withNtfServerOn t ntfTestPort $
0 commit comments