From 4d5d6c7c85cc562d9b4e4a606785edc58b4bef1d Mon Sep 17 00:00:00 2001 From: clowwindy Date: Thu, 11 Dec 2014 17:47:12 +0800 Subject: [PATCH] add unit tests in encrypt --- shadowsocks/encrypt.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/shadowsocks/encrypt.py b/shadowsocks/encrypt.py index 0f6aba8..7c5329f 100644 --- a/shadowsocks/encrypt.py +++ b/shadowsocks/encrypt.py @@ -163,3 +163,29 @@ def encrypt_all(password, method, op, data): cipher = m(method, key, iv, op) result.append(cipher.update(data)) return b''.join(result) + + +def test_encryptor(): + from os import urandom + plain = urandom(10240) + for method in method_supported.keys(): + logging.warn('testing %s' % method.decode('utf-8')) + encryptor = Encryptor(b'key', method) + cipher = encryptor.encrypt(plain) + decryptor = Encryptor(b'key', method) + plain2 = decryptor.decrypt(cipher) + assert plain == plain2 + + +def test_encrypt_all(): + from os import urandom + plain = urandom(10240) + for method in method_supported.keys(): + cipher = encrypt_all(b'key', method, 1, plain) + plain2 = encrypt_all(b'key', method, 0, cipher) + assert plain == plain2 + + +if __name__ == '__main__': + test_encrypt_all() + test_encryptor()