[Pkg-privacy-commits] [obfsproxy] 112/353: Make the unittests work with Twisted trial.

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:01:47 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository obfsproxy.

commit 6800c6addab33b1a1d643066ac58a37998a99968
Author: George Kadianakis <desnacked at riseup.net>
Date:   Wed Feb 6 17:18:40 2013 +0000

    Make the unittests work with Twisted trial.
    
    Trial does not support the setUpClass() unittest method, and it
    expects all TestCase method names to begin with "test_".
---
 obfsproxy/test/test_aes.py                 | 28 +++++++++++-----------------
 obfsproxy/test/transports/test_obfs3_dh.py |  2 +-
 2 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/obfsproxy/test/test_aes.py b/obfsproxy/test/test_aes.py
index 6b6ff59..cdc5e25 100644
--- a/obfsproxy/test/test_aes.py
+++ b/obfsproxy/test/test_aes.py
@@ -5,15 +5,8 @@ from Crypto.Util import Counter
 
 import obfsproxy.common.aes as aes
 
-class testAES_CTR_128_NIST(unittest.TestCase):
-    @classmethod
-    def setUpClass(cls):
-        key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c"
-        iv = "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"
-
-        cls.ctr = Counter.new(128, initial_value=long(iv.encode('hex'), 16))
-        cls.cipher = AES.new(key, AES.MODE_CTR, counter=cls.ctr)
 
+class testAES_CTR_128_NIST(unittest.TestCase):
     def _helper_test_vector(self, input_block, output_block, plaintext, ciphertext):
         self.assertEqual(long(input_block.encode('hex'), 16), self.ctr.next_value())
 
@@ -22,7 +15,14 @@ class testAES_CTR_128_NIST(unittest.TestCase):
 
         # XXX how do we extract the keystream out of the AES object?
 
-    def test_1(self):
+    def test_nist(self):
+        # Prepare the cipher
+        key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c"
+        iv = "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"
+
+        self.ctr = Counter.new(128, initial_value=long(iv.encode('hex'), 16))
+        self.cipher = AES.new(key, AES.MODE_CTR, counter=self.ctr)
+
         input_block = "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"
         output_block = "\xec\x8c\xdf\x73\x98\x60\x7c\xb0\xf2\xd2\x16\x75\xea\x9e\xa1\xe4"
         plaintext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
@@ -30,7 +30,6 @@ class testAES_CTR_128_NIST(unittest.TestCase):
 
         self._helper_test_vector(input_block, output_block, plaintext, ciphertext)
 
-    def test_2(self):
         input_block = "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xff\x00"
         output_block = "\x36\x2b\x7c\x3c\x67\x73\x51\x63\x18\xa0\x77\xd7\xfc\x50\x73\xae"
         plaintext = "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
@@ -38,7 +37,6 @@ class testAES_CTR_128_NIST(unittest.TestCase):
 
         self._helper_test_vector(input_block, output_block, plaintext, ciphertext)
 
-    def test_3(self):
         input_block = "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xff\x01"
         output_block = "\x6a\x2c\xc3\x78\x78\x89\x37\x4f\xbe\xb4\xc8\x1b\x17\xba\x6c\x44"
         plaintext = "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"
@@ -46,7 +44,6 @@ class testAES_CTR_128_NIST(unittest.TestCase):
 
         self._helper_test_vector(input_block, output_block, plaintext, ciphertext)
 
-    def test_4(self):
         input_block = "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xff\x02"
         output_block = "\xe8\x9c\x39\x9f\xf0\xf1\x98\xc6\xd4\x0a\x31\xdb\x15\x6c\xab\xfe"
         plaintext = "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10"
@@ -55,15 +52,12 @@ class testAES_CTR_128_NIST(unittest.TestCase):
         self._helper_test_vector(input_block, output_block, plaintext, ciphertext)
 
 class testAES_CTR_128_simple(unittest.TestCase):
-    @classmethod
-    def setUpClass(cls):
-        cls.key = "\xe3\xb0\xc4\x42\x98\xfc\x1c\x14\x9a\xfb\xf4\xc8\x99\x6f\xb9\x24"
-        cls.iv = "\x27\xae\x41\xe4\x64\x9b\x93\x4c\xa4\x95\x99\x1b\x78\x52\xb8\x55"
-
     def test_encrypt_decrypt_small_ASCII(self):
         """
         Validate that decryption and encryption work as intended on a small ASCII string.
         """
+        self.key = "\xe3\xb0\xc4\x42\x98\xfc\x1c\x14\x9a\xfb\xf4\xc8\x99\x6f\xb9\x24"
+        self.iv = "\x27\xae\x41\xe4\x64\x9b\x93\x4c\xa4\x95\x99\x1b\x78\x52\xb8\x55"
 
         test_string = "This unittest kills fascists."
 
diff --git a/obfsproxy/test/transports/test_obfs3_dh.py b/obfsproxy/test/transports/test_obfs3_dh.py
index 3da04b9..a81962a 100644
--- a/obfsproxy/test/transports/test_obfs3_dh.py
+++ b/obfsproxy/test/transports/test_obfs3_dh.py
@@ -3,7 +3,7 @@ import unittest
 import obfsproxy.transports.obfs3_dh as obfs3_dh
 
 class test_uniform_dh(unittest.TestCase):
-    def test(self):
+    def test_uniform_dh(self):
         alice = obfs3_dh.UniformDH()
         bob = obfs3_dh.UniformDH()
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/obfsproxy.git



More information about the Pkg-privacy-commits mailing list