From 0a6ab83bc5563b6275c2ed0fa8957ea0383b2040 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 7 Oct 2015 16:28:11 -0700 Subject: [PATCH] test distinctness of encryption nonces --- src/wormhole/test/test_blocking.py | 23 +++++++++++++++++++++++ src/wormhole/test/test_twisted.py | 22 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/wormhole/test/test_blocking.py b/src/wormhole/test/test_blocking.py index 64f2ffd..324732e 100644 --- a/src/wormhole/test/test_blocking.py +++ b/src/wormhole/test/test_blocking.py @@ -116,6 +116,29 @@ class Blocking(ServerBase, unittest.TestCase): d.addCallback(_done) return d + def test_same_message(self): + # the two sides use random nonces for their messages, so it's ok for + # both to try and send the same body: they'll result in distinct + # encrypted messages + w1 = Wormhole(APPID, self.relayurl) + w2 = Wormhole(APPID, self.relayurl) + d = deferToThread(w1.get_code) + def _got_code(code): + w2.set_code(code) + return self.doBoth([w1.send_data, b"data"], + [w2.send_data, b"data"]) + d.addCallback(_got_code) + def _sent(res): + return self.doBoth([w1.get_data], [w2.get_data]) + d.addCallback(_sent) + def _done(dl): + (dataX, dataY) = dl + self.assertEqual(dataX, b"data") + self.assertEqual(dataY, b"data") + return self.doBoth([w1.close], [w2.close]) + d.addCallback(_done) + return d + def test_interleaved(self): w1 = Wormhole(APPID, self.relayurl) w2 = Wormhole(APPID, self.relayurl) diff --git a/src/wormhole/test/test_twisted.py b/src/wormhole/test/test_twisted.py index ec789b5..3628fcf 100644 --- a/src/wormhole/test/test_twisted.py +++ b/src/wormhole/test/test_twisted.py @@ -106,6 +106,28 @@ class Basic(ServerBase, unittest.TestCase): d.addCallback(_done) return d + def test_same_message(self): + # the two sides use random nonces for their messages, so it's ok for + # both to try and send the same body: they'll result in distinct + # encrypted messages + w1 = Wormhole(APPID, self.relayurl) + w2 = Wormhole(APPID, self.relayurl) + d = w1.get_code() + def _got_code(code): + w2.set_code(code) + return self.doBoth(w1.send_data(b"data"), w2.send_data(b"data")) + d.addCallback(_got_code) + def _sent(res): + return self.doBoth(w1.get_data(), w2.get_data()) + d.addCallback(_sent) + def _done(dl): + (dataX, dataY) = dl + self.assertEqual(dataX, b"data") + self.assertEqual(dataY, b"data") + return self.doBoth(w1.close(), w2.close()) + d.addCallback(_done) + return d + def test_interleaved(self): w1 = Wormhole(APPID, self.relayurl) w2 = Wormhole(APPID, self.relayurl)