Skip to content

Commit 11ff7d0

Browse files
committed
test, change pattern
1 parent 1834ad4 commit 11ff7d0

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/Simplex/Messaging/Agent/Protocol.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@ shortenShortLink presetSrvs = \case
15291529
Nothing -> False
15301530

15311531
pattern SMPServerOnlyHost :: TransportHost -> SMPServer
1532-
pattern SMPServerOnlyHost h = SMPServer [h] "" (C.KeyHash "")
1532+
pattern SMPServerOnlyHost h = SMPServer (h :| []) "" (C.KeyHash "")
15331533

15341534
-- the servers passed to this function should be all preset servers, not servers configured by the user.
15351535
restoreShortLink :: NonEmpty SMPServer -> ConnShortLink m -> ConnShortLink m

tests/AgentTests/ConnectionRequestTests.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,19 @@ connectionRequestTests =
293293
let contact = CSLContact SLSServer CCTContact
294294
shortenShortLink [srv] (contact srv (LinkKey "0123456789abcdef0123456789abcdef"))
295295
`shouldBe` contact shortSrv (LinkKey "0123456789abcdef0123456789abcdef")
296+
-- won't shorten link that uses only onion host from preset server
297+
shortenShortLink [srv] (contact srvOnion (LinkKey "0123456789abcdef0123456789abcdef"))
298+
`shouldBe` contact srvOnion (LinkKey "0123456789abcdef0123456789abcdef")
299+
-- will shorten link that uses only public host from preset server
300+
shortenShortLink [srv] (contact srv1 (LinkKey "0123456789abcdef0123456789abcdef"))
301+
`shouldBe` contact shortSrv (LinkKey "0123456789abcdef0123456789abcdef")
296302
shortenShortLink [srv] (contact srv2 (LinkKey "0123456789abcdef0123456789abcdef"))
297303
`shouldBe` contact srv2 (LinkKey "0123456789abcdef0123456789abcdef")
298304
restoreShortLink [srv] (contact shortSrv (LinkKey "0123456789abcdef0123456789abcdef"))
299305
`shouldBe` contact srv (LinkKey "0123456789abcdef0123456789abcdef")
306+
-- won't change link that has only public host of preset server with keyhash
307+
restoreShortLink [srv] (contact srv1 (LinkKey "0123456789abcdef0123456789abcdef"))
308+
`shouldBe` contact srv1 (LinkKey "0123456789abcdef0123456789abcdef")
300309
restoreShortLink [srv2] (contact shortSrv (LinkKey "0123456789abcdef0123456789abcdef"))
301310
`shouldBe` contact shortSrv (LinkKey "0123456789abcdef0123456789abcdef")
302311
restoreShortLink [srv] (contact srv2 (LinkKey "0123456789abcdef0123456789abcdef"))
@@ -307,5 +316,8 @@ connectionRequestTests =
307316
shortSrv :: SMPServer
308317
shortSrv = SMPServer "smp.simplex.im" "" (C.KeyHash "")
309318

319+
srvOnion :: SMPServer
320+
srvOnion = SMPServer "jjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion" "" (C.KeyHash "\215m\248\251")
321+
310322
srv2 :: SMPServer
311323
srv2 = SMPServer "smp2.simplex.im,jjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion" "" (C.KeyHash "\215m\248\251")

0 commit comments

Comments
 (0)