[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [obfsproxy/master] Add PacketMorpher unittests.



commit 55fa261c83174b3e241241cf7b66ed3f629c7f88
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date:   Mon Apr 14 15:14:14 2014 +0300

    Add PacketMorpher unittests.
---
 obfsproxy/test/transports/test_scramblesuit.py |   36 ++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/obfsproxy/test/transports/test_scramblesuit.py b/obfsproxy/test/transports/test_scramblesuit.py
index 3392b5f..8481fab 100644
--- a/obfsproxy/test/transports/test_scramblesuit.py
+++ b/obfsproxy/test/transports/test_scramblesuit.py
@@ -21,6 +21,8 @@ import obfsproxy.transports.scramblesuit.scramblesuit as scramblesuit
 import obfsproxy.transports.scramblesuit.message as message
 import obfsproxy.transports.scramblesuit.state as state
 import obfsproxy.transports.scramblesuit.ticket as ticket
+import obfsproxy.transports.scramblesuit.packetmorpher as packetmorpher
+import obfsproxy.transports.scramblesuit.probdist as probdist
 
 
 # Disable all logging as it would yield plenty of warning and error
@@ -418,5 +420,39 @@ class TicketTest( unittest.TestCase ):
             else:
                 self.assertTrue(ss.receiveTicket(buf))
 
+class PacketMorpher( unittest.TestCase ):
+
+    def test1_calcPadding( self ):
+
+        def checkDistribution( dist ):
+            pm = packetmorpher.new(dist)
+            for i in xrange(0, const.MTU + 2):
+                padLen = pm.calcPadding(i)
+                self.assertTrue(const.HDR_LENGTH <= \
+                                padLen < \
+                                (const.MTU + const.HDR_LENGTH))
+
+        # Test randomly generated distributions.
+        for i in xrange(0, 100):
+            checkDistribution(None)
+
+        # Test border-case distributions.
+        checkDistribution(probdist.new(lambda: 0))
+        checkDistribution(probdist.new(lambda: 1))
+        checkDistribution(probdist.new(lambda: const.MTU))
+        checkDistribution(probdist.new(lambda: const.MTU + 1))
+
+    def test2_getPadding( self ):
+        pm = packetmorpher.new()
+        sendCrypter = mycrypto.PayloadCrypter()
+        sendCrypter.setSessionKey("A" * 32,  "A" * 8)
+        sendHMAC = "A" * 32
+
+        for i in xrange(0, const.MTU + 2):
+            padLen = len(pm.getPadding(sendCrypter, sendHMAC, i))
+            self.assertTrue(const.HDR_LENGTH <= padLen < const.MTU + \
+                            const.HDR_LENGTH)
+
+
 if __name__ == '__main__':
     unittest.main()



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits