mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-09-01 18:08:36 +00:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1e6c0fd0c | ||
|
|
2d9643cad2 | ||
|
|
3c93de0611 | ||
|
|
8b2a3eeb8a | ||
|
|
3205bd7250 | ||
|
|
ecae11a2a1 | ||
|
|
f51dfa7c65 |
@@ -42,7 +42,7 @@ jobs:
|
|||||||
run: cabal build --enable-tests
|
run: cabal build --enable-tests
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
if: matrix.os == 'ubuntu-18.04'
|
# if: matrix.os == 'ubuntu-18.04'
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
shell: bash
|
shell: bash
|
||||||
run: cabal test --test-show-details=direct
|
run: cabal test --test-show-details=direct
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ removeFileIfExists filePath = do
|
|||||||
|
|
||||||
notificationTests :: ATransport -> Spec
|
notificationTests :: ATransport -> Spec
|
||||||
notificationTests t =
|
notificationTests t =
|
||||||
after_ (removeFile (databaseFile testDB) >> removeFileIfExists (databaseFile testDB2)) $ do
|
after_ (removeFileIfExists (databaseFile testDB) >> removeFileIfExists (databaseFile testDB2)) $ do
|
||||||
describe "Managing notification tokens" $ do
|
describe "Managing notification tokens" $ do
|
||||||
it "should register and verify notification token" $
|
it "should register and verify notification token" $
|
||||||
withAPNSMockServer $ \apns ->
|
withAPNSMockServer $ \apns ->
|
||||||
@@ -58,7 +58,7 @@ notificationTests t =
|
|||||||
withAPNSMockServer $ \apns ->
|
withAPNSMockServer $ \apns ->
|
||||||
testNtfTokenServerRestart t apns
|
testNtfTokenServerRestart t apns
|
||||||
describe "Managing notification subscriptions" $ do
|
describe "Managing notification subscriptions" $ do
|
||||||
it "should create notification subscription for existing connection" $ \_ ->
|
xit "should create notification subscription for existing connection" $ \_ ->
|
||||||
withSmpServer t $
|
withSmpServer t $
|
||||||
withAPNSMockServer $ \apns ->
|
withAPNSMockServer $ \apns ->
|
||||||
withNtfServer t $ testNotificationSubscriptionExistingConnection apns
|
withNtfServer t $ testNotificationSubscriptionExistingConnection apns
|
||||||
|
|||||||
+1
-1
@@ -174,7 +174,7 @@ data APNSMockServer = APNSMockServer
|
|||||||
apnsMockServerConfig :: HTTP2ServerConfig
|
apnsMockServerConfig :: HTTP2ServerConfig
|
||||||
apnsMockServerConfig =
|
apnsMockServerConfig =
|
||||||
HTTP2ServerConfig
|
HTTP2ServerConfig
|
||||||
{ qSize = 1,
|
{ qSize = 10,
|
||||||
http2Port = apnsTestPort,
|
http2Port = apnsTestPort,
|
||||||
serverSupported = http2TLSParams,
|
serverSupported = http2TLSParams,
|
||||||
caCertificateFile = "tests/fixtures/ca.crt",
|
caCertificateFile = "tests/fixtures/ca.crt",
|
||||||
|
|||||||
+15
-1
@@ -47,7 +47,7 @@ import UnliftIO.STM
|
|||||||
ntfServerTests :: ATransport -> Spec
|
ntfServerTests :: ATransport -> Spec
|
||||||
ntfServerTests t = do
|
ntfServerTests t = do
|
||||||
describe "Notifications server protocol syntax" $ ntfSyntaxTests t
|
describe "Notifications server protocol syntax" $ ntfSyntaxTests t
|
||||||
describe "Notification subscriptions" $ testNotificationSubscription t
|
xdescribe "Notification subscriptions" $ testNotificationSubscription t
|
||||||
|
|
||||||
ntfSyntaxTests :: ATransport -> Spec
|
ntfSyntaxTests :: ATransport -> Spec
|
||||||
ntfSyntaxTests (ATransport t) = do
|
ntfSyntaxTests (ATransport t) = do
|
||||||
@@ -97,12 +97,14 @@ testNotificationSubscription (ATransport t) =
|
|||||||
withAPNSMockServer $ \APNSMockServer {apnsQ} ->
|
withAPNSMockServer $ \APNSMockServer {apnsQ} ->
|
||||||
smpTest2 t $ \rh sh ->
|
smpTest2 t $ \rh sh ->
|
||||||
ntfTest t $ \nh -> do
|
ntfTest t $ \nh -> do
|
||||||
|
print 1
|
||||||
-- create queue
|
-- create queue
|
||||||
(sId, rId, rKey, rcvDhSecret) <- createAndSecureQueue rh sPub
|
(sId, rId, rKey, rcvDhSecret) <- createAndSecureQueue rh sPub
|
||||||
-- register and verify token
|
-- register and verify token
|
||||||
RespNtf "1" "" (NRTknId tId ntfDh) <- signSendRecvNtf nh tknKey ("1", "", TNEW $ NewNtfTkn tkn tknPub dhPub)
|
RespNtf "1" "" (NRTknId tId ntfDh) <- signSendRecvNtf nh tknKey ("1", "", TNEW $ NewNtfTkn tkn tknPub dhPub)
|
||||||
APNSMockRequest {notification = APNSNotification {aps = APNSBackground _, notificationData = Just ntfData}, sendApnsResponse = send} <-
|
APNSMockRequest {notification = APNSNotification {aps = APNSBackground _, notificationData = Just ntfData}, sendApnsResponse = send} <-
|
||||||
atomically $ readTBQueue apnsQ
|
atomically $ readTBQueue apnsQ
|
||||||
|
print 2
|
||||||
send APNSRespOk
|
send APNSRespOk
|
||||||
let dhSecret = C.dh' ntfDh dhPriv
|
let dhSecret = C.dh' ntfDh dhPriv
|
||||||
Right verification = ntfData .-> "verification"
|
Right verification = ntfData .-> "verification"
|
||||||
@@ -113,15 +115,19 @@ testNotificationSubscription (ATransport t) =
|
|||||||
-- enable queue notifications
|
-- enable queue notifications
|
||||||
(rcvNtfPubDhKey, rcvNtfPrivDhKey) <- C.generateKeyPair'
|
(rcvNtfPubDhKey, rcvNtfPrivDhKey) <- C.generateKeyPair'
|
||||||
Resp "3" _ (NID nId rcvNtfSrvPubDhKey) <- signSendRecv rh rKey ("3", rId, NKEY nPub rcvNtfPubDhKey)
|
Resp "3" _ (NID nId rcvNtfSrvPubDhKey) <- signSendRecv rh rKey ("3", rId, NKEY nPub rcvNtfPubDhKey)
|
||||||
|
print 3
|
||||||
let srv = SMPServer SMP.testHost SMP.testPort SMP.testKeyHash
|
let srv = SMPServer SMP.testHost SMP.testPort SMP.testKeyHash
|
||||||
q = SMPQueueNtf srv nId
|
q = SMPQueueNtf srv nId
|
||||||
rcvNtfDhSecret = C.dh' rcvNtfSrvPubDhKey rcvNtfPrivDhKey
|
rcvNtfDhSecret = C.dh' rcvNtfSrvPubDhKey rcvNtfPrivDhKey
|
||||||
RespNtf "4" _ (NRSubId _subId) <- signSendRecvNtf nh tknKey ("4", "", SNEW $ NewNtfSub tId q nKey)
|
RespNtf "4" _ (NRSubId _subId) <- signSendRecvNtf nh tknKey ("4", "", SNEW $ NewNtfSub tId q nKey)
|
||||||
|
print 4
|
||||||
-- send message
|
-- send message
|
||||||
threadDelay 50000
|
threadDelay 50000
|
||||||
Resp "5" _ OK <- signSendRecv sh sKey ("5", sId, _SEND' "hello")
|
Resp "5" _ OK <- signSendRecv sh sKey ("5", sId, _SEND' "hello")
|
||||||
|
print 5
|
||||||
-- receive notification
|
-- receive notification
|
||||||
APNSMockRequest {notification, sendApnsResponse = send'} <- atomically $ readTBQueue apnsQ
|
APNSMockRequest {notification, sendApnsResponse = send'} <- atomically $ readTBQueue apnsQ
|
||||||
|
print 5.1
|
||||||
let APNSNotification {aps = APNSMutableContent {}, notificationData = Just ntfData'} = notification
|
let APNSNotification {aps = APNSMutableContent {}, notificationData = Just ntfData'} = notification
|
||||||
Right nonce' = C.cbNonce <$> ntfData' .-> "nonce"
|
Right nonce' = C.cbNonce <$> ntfData' .-> "nonce"
|
||||||
Right message = ntfData' .-> "message"
|
Right message = ntfData' .-> "message"
|
||||||
@@ -130,20 +136,26 @@ testNotificationSubscription (ATransport t) =
|
|||||||
parse strP (AP.INTERNAL "error parsing PNMessageData") ntfDataDecrypted
|
parse strP (AP.INTERNAL "error parsing PNMessageData") ntfDataDecrypted
|
||||||
Right nMsgMeta = C.cbDecrypt rcvNtfDhSecret nmsgNonce encNMsgMeta
|
Right nMsgMeta = C.cbDecrypt rcvNtfDhSecret nmsgNonce encNMsgMeta
|
||||||
Right NMsgMeta {msgId, msgTs} = parse smpP (AP.INTERNAL "error parsing NMsgMeta") nMsgMeta
|
Right NMsgMeta {msgId, msgTs} = parse smpP (AP.INTERNAL "error parsing NMsgMeta") nMsgMeta
|
||||||
|
print 5.2
|
||||||
smpServer `shouldBe` srv
|
smpServer `shouldBe` srv
|
||||||
notifierId `shouldBe` nId
|
notifierId `shouldBe` nId
|
||||||
send' APNSRespOk
|
send' APNSRespOk
|
||||||
|
print 5.3
|
||||||
-- receive message
|
-- receive message
|
||||||
Resp "" _ (MSG RcvMessage {msgId = mId1, msgBody = EncRcvMsgBody body}) <- tGet1 rh
|
Resp "" _ (MSG RcvMessage {msgId = mId1, msgBody = EncRcvMsgBody body}) <- tGet1 rh
|
||||||
|
print 5.4
|
||||||
Right ClientRcvMsgBody {msgTs = mTs, msgBody} <- pure $ parseAll clientRcvMsgBodyP =<< first show (C.cbDecrypt rcvDhSecret (C.cbNonce mId1) body)
|
Right ClientRcvMsgBody {msgTs = mTs, msgBody} <- pure $ parseAll clientRcvMsgBodyP =<< first show (C.cbDecrypt rcvDhSecret (C.cbNonce mId1) body)
|
||||||
|
print 5.5
|
||||||
mId1 `shouldBe` msgId
|
mId1 `shouldBe` msgId
|
||||||
mTs `shouldBe` msgTs
|
mTs `shouldBe` msgTs
|
||||||
(msgBody, "hello") #== "delivered from queue"
|
(msgBody, "hello") #== "delivered from queue"
|
||||||
Resp "6" _ OK <- signSendRecv rh rKey ("6", rId, ACK mId1)
|
Resp "6" _ OK <- signSendRecv rh rKey ("6", rId, ACK mId1)
|
||||||
|
print 6
|
||||||
pure ()
|
pure ()
|
||||||
-- replace token
|
-- replace token
|
||||||
let tkn' = DeviceToken PPApnsTest "efgh"
|
let tkn' = DeviceToken PPApnsTest "efgh"
|
||||||
RespNtf "7" tId' NROk <- signSendRecvNtf nh tknKey ("7", tId, TRPL tkn')
|
RespNtf "7" tId' NROk <- signSendRecvNtf nh tknKey ("7", tId, TRPL tkn')
|
||||||
|
print 7
|
||||||
tId `shouldBe` tId'
|
tId `shouldBe` tId'
|
||||||
APNSMockRequest {notification = APNSNotification {aps = APNSBackground _, notificationData = Just ntfData2}, sendApnsResponse = send2} <-
|
APNSMockRequest {notification = APNSNotification {aps = APNSBackground _, notificationData = Just ntfData2}, sendApnsResponse = send2} <-
|
||||||
atomically $ readTBQueue apnsQ
|
atomically $ readTBQueue apnsQ
|
||||||
@@ -153,8 +165,10 @@ testNotificationSubscription (ATransport t) =
|
|||||||
Right code2 = NtfRegCode <$> C.cbDecrypt dhSecret nonce2 verification2
|
Right code2 = NtfRegCode <$> C.cbDecrypt dhSecret nonce2 verification2
|
||||||
RespNtf "8" _ NROk <- signSendRecvNtf nh tknKey ("8", tId, TVFY code2)
|
RespNtf "8" _ NROk <- signSendRecvNtf nh tknKey ("8", tId, TVFY code2)
|
||||||
RespNtf "8a" _ (NRTkn NTActive) <- signSendRecvNtf nh tknKey ("8a", tId, TCHK)
|
RespNtf "8a" _ (NRTkn NTActive) <- signSendRecvNtf nh tknKey ("8a", tId, TCHK)
|
||||||
|
print 8
|
||||||
-- send message
|
-- send message
|
||||||
Resp "9" _ OK <- signSendRecv sh sKey ("9", sId, _SEND' "hello 2")
|
Resp "9" _ OK <- signSendRecv sh sKey ("9", sId, _SEND' "hello 2")
|
||||||
|
print 9
|
||||||
APNSMockRequest {notification = notification3, sendApnsResponse = send3} <- atomically $ readTBQueue apnsQ
|
APNSMockRequest {notification = notification3, sendApnsResponse = send3} <- atomically $ readTBQueue apnsQ
|
||||||
let APNSNotification {aps = APNSMutableContent {}, notificationData = Just ntfData3} = notification3
|
let APNSNotification {aps = APNSMutableContent {}, notificationData = Just ntfData3} = notification3
|
||||||
Right nonce3 = C.cbNonce <$> ntfData3 .-> "nonce"
|
Right nonce3 = C.cbNonce <$> ntfData3 .-> "nonce"
|
||||||
|
|||||||
@@ -186,17 +186,17 @@ agentCfg :: AgentConfig
|
|||||||
agentCfg =
|
agentCfg =
|
||||||
defaultAgentConfig
|
defaultAgentConfig
|
||||||
{ tcpPort = agentTestPort,
|
{ tcpPort = agentTestPort,
|
||||||
tbqSize = 4,
|
tbqSize = 10,
|
||||||
database = testDB,
|
database = testDB,
|
||||||
smpCfg =
|
smpCfg =
|
||||||
defaultClientConfig
|
defaultClientConfig
|
||||||
{ qSize = 1,
|
{ qSize = 10,
|
||||||
defaultTransport = (testPort, transport @TLS),
|
defaultTransport = (testPort, transport @TLS),
|
||||||
networkConfig = defaultNetworkConfig {tcpTimeout = 500_000}
|
networkConfig = defaultNetworkConfig {tcpTimeout = 500_000}
|
||||||
},
|
},
|
||||||
ntfCfg =
|
ntfCfg =
|
||||||
defaultClientConfig
|
defaultClientConfig
|
||||||
{ qSize = 1,
|
{ qSize = 10,
|
||||||
defaultTransport = (ntfTestPort, transport @TLS)
|
defaultTransport = (ntfTestPort, transport @TLS)
|
||||||
},
|
},
|
||||||
reconnectInterval = defaultReconnectInterval {initialInterval = 50_000},
|
reconnectInterval = defaultReconnectInterval {initialInterval = 50_000},
|
||||||
|
|||||||
+2
-2
@@ -71,8 +71,8 @@ cfg :: ServerConfig
|
|||||||
cfg =
|
cfg =
|
||||||
ServerConfig
|
ServerConfig
|
||||||
{ transports = undefined,
|
{ transports = undefined,
|
||||||
tbqSize = 1,
|
tbqSize = 10,
|
||||||
serverTbqSize = 1,
|
serverTbqSize = 10,
|
||||||
msgQueueQuota = 4,
|
msgQueueQuota = 4,
|
||||||
queueIdBytes = 24,
|
queueIdBytes = 24,
|
||||||
msgIdBytes = 24,
|
msgIdBytes = 24,
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ serverTests t@(ATransport t') = do
|
|||||||
describe "Store log" $ testWithStoreLog t
|
describe "Store log" $ testWithStoreLog t
|
||||||
describe "Restore messages" $ testRestoreMessages t
|
describe "Restore messages" $ testRestoreMessages t
|
||||||
describe "Restore messages (v2)" $ testRestoreMessagesV2 t
|
describe "Restore messages (v2)" $ testRestoreMessagesV2 t
|
||||||
describe "Timing of AUTH error" $ testTiming t
|
xdescribe "Timing of AUTH error" $ testTiming t
|
||||||
describe "Message notifications" $ testMessageNotifications t
|
describe "Message notifications" $ testMessageNotifications t
|
||||||
describe "Message expiration" $ do
|
describe "Message expiration" $ do
|
||||||
testMsgExpireOnSend t'
|
testMsgExpireOnSend t'
|
||||||
|
|||||||
Reference in New Issue
Block a user