@@ -86,6 +86,7 @@ serverTests = do
8686 describe " Message notifications" $ do
8787 testMessageNotifications
8888 testMessageServiceNotifications
89+ testServiceNotificationsTwoRestarts
8990 describe " Message expiration" $ do
9091 testMsgExpireOnSend
9192 testMsgExpireOnInterval
@@ -1091,7 +1092,6 @@ testMessageServiceNotifications =
10911092 (rcvNtfPubDhKey, _) <- atomically $ C. generateKeyPair g
10921093 Resp " 1" _ (NID nId _) <- signSendRecv rh rKey (" 1" , rId, NKEY nPub rcvNtfPubDhKey)
10931094 serviceKeys@ (_, servicePK) <- atomically $ C. generateKeyPair g
1094- -- TODO [certs] we need to get certificate fingerprint and include it into signed over for NSUB commands
10951095 testNtfServiceClient t serviceKeys $ \ nh1 -> do
10961096 -- can't subscribe without service signature in service connection
10971097 Resp " 2a" _ (ERR SERVICE ) <- signSendRecv nh1 nKey (" 2a" , nId, NSUB )
@@ -1155,6 +1155,51 @@ testMessageServiceNotifications =
11551155 Resp " " _ (NMSG _ _) <- tGet1 nh
11561156 pure ()
11571157
1158+ testServiceNotificationsTwoRestarts :: SpecWith (ASrvTransport , AStoreType )
1159+ testServiceNotificationsTwoRestarts =
1160+ it " subscribe notifier as service and deliver notifications after two restarts" $ \ ps@ (ATransport t, _) -> do
1161+ g <- C. newRandom
1162+ (sPub, sKey) <- atomically $ C. generateAuthKeyPair C. SEd25519 g
1163+ (nPub, nKey) <- atomically $ C. generateAuthKeyPair C. SEd25519 g
1164+ serviceKeys@ (_, servicePK) <- atomically $ C. generateKeyPair g
1165+ (rcvNtfPubDhKey, _) <- atomically $ C. generateKeyPair g
1166+ (rId, rKey, sId, dec, serviceId) <- withSmpServerStoreLogOn ps testPort $ runTest2 t $ \ sh rh -> do
1167+ (sId, rId, rKey, dhShared) <- createAndSecureQueue rh sPub
1168+ let dec = decryptMsgV3 dhShared
1169+ Resp " 0" _ (NID nId _) <- signSendRecv rh rKey (" 0" , rId, NKEY nPub rcvNtfPubDhKey)
1170+ testNtfServiceClient t serviceKeys $ \ nh -> do
1171+ Resp " 1" _ (SOK (Just serviceId)) <- serviceSignSendRecv nh nKey servicePK (" 1" , nId, NSUB )
1172+ deliverMessage rh rId rKey sh sId sKey nh " hello" dec
1173+ pure (rId, rKey, sId, dec, serviceId)
1174+ threadDelay 250000
1175+ withSmpServerStoreLogOn ps testPort $ runTest2 t $ \ sh rh ->
1176+ testNtfServiceClient t serviceKeys $ \ nh -> do
1177+ Resp " 2.1" serviceId' (SOKS n) <- signSendRecv nh (C. APrivateAuthKey C. SEd25519 servicePK) (" 2.1" , serviceId, NSUBS )
1178+ n `shouldBe` 1
1179+ Resp " 2.2" _ (SOK Nothing ) <- signSendRecv rh rKey (" 2.2" , rId, SUB )
1180+ serviceId' `shouldBe` serviceId
1181+ deliverMessage rh rId rKey sh sId sKey nh " hello 2" dec
1182+ threadDelay 250000
1183+ withSmpServerStoreLogOn ps testPort $ runTest2 t $ \ sh rh ->
1184+ testNtfServiceClient t serviceKeys $ \ nh -> do
1185+ Resp " 3.1" _ (SOKS n) <- signSendRecv nh (C. APrivateAuthKey C. SEd25519 servicePK) (" 3.1" , serviceId, NSUBS )
1186+ n `shouldBe` 1
1187+ Resp " 3.2" _ (SOK Nothing ) <- signSendRecv rh rKey (" 3.2" , rId, SUB )
1188+ deliverMessage rh rId rKey sh sId sKey nh " hello 3" dec
1189+ where
1190+ runTest2 :: Transport c => TProxy c 'TServer -> (THandleSMP c 'TClient -> THandleSMP c 'TClient -> IO a ) -> ThreadId -> IO a
1191+ runTest2 _ test' server = do
1192+ a <- testSMPClient $ \ h1 -> testSMPClient $ \ h2 -> test' h1 h2
1193+ killThread server
1194+ pure a
1195+ deliverMessage rh rId rKey sh sId sKey nh msgText dec = do
1196+ Resp " msg-1" _ OK <- signSendRecv sh sKey (" msg-1" , sId, _SEND' msgText)
1197+ Resp " " _ (Msg mId msg) <- tGet1 rh
1198+ Resp " msg-2" _ OK <- signSendRecv rh rKey (" msg-2" , rId, ACK mId)
1199+ (dec mId msg, Right msgText) #== " delivered from queue"
1200+ Resp " " _ (NMSG _ _) <- tGet1 nh
1201+ pure ()
1202+
11581203testMsgExpireOnSend :: SpecWith (ASrvTransport , AStoreType )
11591204testMsgExpireOnSend =
11601205 it " should expire messages that are not received before messageTTL on SEND" $ \ (ATransport (t :: TProxy c 'TServer), msType) -> do
0 commit comments