From 074dc36e6b277b5ffc6ac910fdc11934e38959f4 Mon Sep 17 00:00:00 2001 From: Robey Pointer Date: Tue, 1 Aug 2006 11:21:43 -0700 Subject: [PATCH] [project @ robey@lag.net-20060801182143-088ff687e0945937] use hexlify in tests --- tests/test_hostkeys.py | 7 ++++--- tests/test_kex.py | 33 +++++++++++++++++---------------- tests/test_pkey.py | 11 ++++++----- tests/test_sftp.py | 7 ++++--- tests/test_transport.py | 13 +++++++++---- tests/test_util.py | 3 ++- 6 files changed, 42 insertions(+), 32 deletions(-) diff --git a/tests/test_hostkeys.py b/tests/test_hostkeys.py index 798252c..dc43e79 100644 --- a/tests/test_hostkeys.py +++ b/tests/test_hostkeys.py @@ -21,6 +21,7 @@ Some unit tests for HostKeys. """ import base64 +from binascii import hexlify import os import unittest import paramiko @@ -56,7 +57,7 @@ class HostKeysTest (unittest.TestCase): self.assertEquals(2, len(hostdict)) self.assertEquals(1, len(hostdict.values()[0])) self.assertEquals(1, len(hostdict.values()[1])) - fp = paramiko.util.hexify(hostdict['secure.example.com']['ssh-rsa'].get_fingerprint()) + fp = hexlify(hostdict['secure.example.com']['ssh-rsa'].get_fingerprint()).upper() self.assertEquals('E6684DB30E109B67B70FF1DC5C7F1363', fp) def test_2_add(self): @@ -66,7 +67,7 @@ class HostKeysTest (unittest.TestCase): hostdict.add(hh, 'ssh-rsa', key) self.assertEquals(3, len(hostdict)) x = hostdict['foo.example.com'] - fp = paramiko.util.hexify(x['ssh-rsa'].get_fingerprint()) + fp = hexlify(x['ssh-rsa'].get_fingerprint()).upper() self.assertEquals('7EC91BB336CB6D810B124B1353C32396', fp) self.assert_(hostdict.check('foo.example.com', key)) @@ -78,7 +79,7 @@ class HostKeysTest (unittest.TestCase): self.assert_(not hostdict.has_key('not.example.com')) x = hostdict.get('secure.example.com', None) self.assert_(x is not None) - fp = paramiko.util.hexify(x['ssh-rsa'].get_fingerprint()) + fp = hexlify(x['ssh-rsa'].get_fingerprint()).upper() self.assertEquals('E6684DB30E109B67B70FF1DC5C7F1363', fp) i = 0 for key in hostdict: diff --git a/tests/test_kex.py b/tests/test_kex.py index 3ab95b0..dae338b 100644 --- a/tests/test_kex.py +++ b/tests/test_kex.py @@ -22,6 +22,7 @@ Some unit tests for the key exchange protocols. """ +from binascii import hexlify import unittest import paramiko.util from paramiko.kex_group1 import KexGroup1 @@ -92,7 +93,7 @@ class KexTest (unittest.TestCase): kex = KexGroup1(transport) kex.start_kex() x = '1E000000807E2DDB1743F3487D6545F04F1C8476092FB912B013626AB5BCEB764257D88BBA64243B9F348DF7B41B8C814A995E00299913503456983FFB9178D3CD79EB6D55522418A8ABF65375872E55938AB99A84A0B5FC8A1ECC66A7C3766E7E0F80B7CE2C9225FC2DD683F4764244B72963BBB383F529DCF0C5D17740B8A2ADBE9208D4' - self.assertEquals(x, paramiko.util.hexify(str(transport._message))) + self.assertEquals(x, hexlify(str(transport._message)).upper()) self.assertEquals((paramiko.kex_group1._MSG_KEXDH_REPLY,), transport._expect) # fake "reply" @@ -104,7 +105,7 @@ class KexTest (unittest.TestCase): kex.parse_next(paramiko.kex_group1._MSG_KEXDH_REPLY, msg) H = '03079780F3D3AD0B3C6DB30C8D21685F367A86D2' self.assertEquals(self.K, transport._K) - self.assertEquals(H, paramiko.util.hexify(transport._H)) + self.assertEquals(H, hexlify(transport._H).upper()) self.assertEquals(('fake-host-key', 'fake-sig'), transport._verify) self.assert_(transport._activated) @@ -122,8 +123,8 @@ class KexTest (unittest.TestCase): H = 'B16BF34DD10945EDE84E9C1EF24A14BFDC843389' x = '1F0000000866616B652D6B6579000000807E2DDB1743F3487D6545F04F1C8476092FB912B013626AB5BCEB764257D88BBA64243B9F348DF7B41B8C814A995E00299913503456983FFB9178D3CD79EB6D55522418A8ABF65375872E55938AB99A84A0B5FC8A1ECC66A7C3766E7E0F80B7CE2C9225FC2DD683F4764244B72963BBB383F529DCF0C5D17740B8A2ADBE9208D40000000866616B652D736967' self.assertEquals(self.K, transport._K) - self.assertEquals(H, paramiko.util.hexify(transport._H)) - self.assertEquals(x, paramiko.util.hexify(str(transport._message))) + self.assertEquals(H, hexlify(transport._H).upper()) + self.assertEquals(x, hexlify(str(transport._message)).upper()) self.assert_(transport._activated) def test_3_gex_client(self): @@ -132,7 +133,7 @@ class KexTest (unittest.TestCase): kex = KexGex(transport) kex.start_kex() x = '22000004000000080000002000' - self.assertEquals(x, paramiko.util.hexify(str(transport._message))) + self.assertEquals(x, hexlify(str(transport._message)).upper()) self.assertEquals((paramiko.kex_gex._MSG_KEXDH_GEX_GROUP,), transport._expect) msg = Message() @@ -141,7 +142,7 @@ class KexTest (unittest.TestCase): msg.rewind() kex.parse_next(paramiko.kex_gex._MSG_KEXDH_GEX_GROUP, msg) x = '20000000807E2DDB1743F3487D6545F04F1C8476092FB912B013626AB5BCEB764257D88BBA64243B9F348DF7B41B8C814A995E00299913503456983FFB9178D3CD79EB6D55522418A8ABF65375872E55938AB99A84A0B5FC8A1ECC66A7C3766E7E0F80B7CE2C9225FC2DD683F4764244B72963BBB383F529DCF0C5D17740B8A2ADBE9208D4' - self.assertEquals(x, paramiko.util.hexify(str(transport._message))) + self.assertEquals(x, hexlify(str(transport._message)).upper()) self.assertEquals((paramiko.kex_gex._MSG_KEXDH_GEX_REPLY,), transport._expect) msg = Message() @@ -152,7 +153,7 @@ class KexTest (unittest.TestCase): kex.parse_next(paramiko.kex_gex._MSG_KEXDH_GEX_REPLY, msg) H = 'A265563F2FA87F1A89BF007EE90D58BE2E4A4BD0' self.assertEquals(self.K, transport._K) - self.assertEquals(H, paramiko.util.hexify(transport._H)) + self.assertEquals(H, hexlify(transport._H).upper()) self.assertEquals(('fake-host-key', 'fake-sig'), transport._verify) self.assert_(transport._activated) @@ -162,7 +163,7 @@ class KexTest (unittest.TestCase): kex = KexGex(transport) kex.start_kex(_test_old_style=True) x = '1E00000800' - self.assertEquals(x, paramiko.util.hexify(str(transport._message))) + self.assertEquals(x, hexlify(str(transport._message)).upper()) self.assertEquals((paramiko.kex_gex._MSG_KEXDH_GEX_GROUP,), transport._expect) msg = Message() @@ -171,7 +172,7 @@ class KexTest (unittest.TestCase): msg.rewind() kex.parse_next(paramiko.kex_gex._MSG_KEXDH_GEX_GROUP, msg) x = '20000000807E2DDB1743F3487D6545F04F1C8476092FB912B013626AB5BCEB764257D88BBA64243B9F348DF7B41B8C814A995E00299913503456983FFB9178D3CD79EB6D55522418A8ABF65375872E55938AB99A84A0B5FC8A1ECC66A7C3766E7E0F80B7CE2C9225FC2DD683F4764244B72963BBB383F529DCF0C5D17740B8A2ADBE9208D4' - self.assertEquals(x, paramiko.util.hexify(str(transport._message))) + self.assertEquals(x, hexlify(str(transport._message)).upper()) self.assertEquals((paramiko.kex_gex._MSG_KEXDH_GEX_REPLY,), transport._expect) msg = Message() @@ -182,7 +183,7 @@ class KexTest (unittest.TestCase): kex.parse_next(paramiko.kex_gex._MSG_KEXDH_GEX_REPLY, msg) H = 'A265563F2FA87F1A89BF007EE90D58BE2E4A4BD0' self.assertEquals(self.K, transport._K) - self.assertEquals(H, paramiko.util.hexify(transport._H)) + self.assertEquals(H, hexlify(transport._H).upper()) self.assertEquals(('fake-host-key', 'fake-sig'), transport._verify) self.assert_(transport._activated) @@ -200,7 +201,7 @@ class KexTest (unittest.TestCase): msg.rewind() kex.parse_next(paramiko.kex_gex._MSG_KEXDH_GEX_REQUEST, msg) x = '1F0000008100FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF0000000102' - self.assertEquals(x, paramiko.util.hexify(str(transport._message))) + self.assertEquals(x, hexlify(str(transport._message)).upper()) self.assertEquals((paramiko.kex_gex._MSG_KEXDH_GEX_INIT,), transport._expect) msg = Message() @@ -211,8 +212,8 @@ class KexTest (unittest.TestCase): H = 'CE754197C21BF3452863B4F44D0B3951F12516EF' x = '210000000866616B652D6B6579000000807E2DDB1743F3487D6545F04F1C8476092FB912B013626AB5BCEB764257D88BBA64243B9F348DF7B41B8C814A995E00299913503456983FFB9178D3CD79EB6D55522418A8ABF65375872E55938AB99A84A0B5FC8A1ECC66A7C3766E7E0F80B7CE2C9225FC2DD683F4764244B72963BBB383F529DCF0C5D17740B8A2ADBE9208D40000000866616B652D736967' self.assertEquals(K, transport._K) - self.assertEquals(H, paramiko.util.hexify(transport._H)) - self.assertEquals(x, paramiko.util.hexify(str(transport._message))) + self.assertEquals(H, hexlify(transport._H).upper()) + self.assertEquals(x, hexlify(str(transport._message)).upper()) self.assert_(transport._activated) def test_6_gex_server_with_old_client(self): @@ -227,7 +228,7 @@ class KexTest (unittest.TestCase): msg.rewind() kex.parse_next(paramiko.kex_gex._MSG_KEXDH_GEX_REQUEST_OLD, msg) x = '1F0000008100FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF0000000102' - self.assertEquals(x, paramiko.util.hexify(str(transport._message))) + self.assertEquals(x, hexlify(str(transport._message)).upper()) self.assertEquals((paramiko.kex_gex._MSG_KEXDH_GEX_INIT,), transport._expect) msg = Message() @@ -238,6 +239,6 @@ class KexTest (unittest.TestCase): H = 'B41A06B2E59043CEFC1AE16EC31F1E2D12EC455B' x = '210000000866616B652D6B6579000000807E2DDB1743F3487D6545F04F1C8476092FB912B013626AB5BCEB764257D88BBA64243B9F348DF7B41B8C814A995E00299913503456983FFB9178D3CD79EB6D55522418A8ABF65375872E55938AB99A84A0B5FC8A1ECC66A7C3766E7E0F80B7CE2C9225FC2DD683F4764244B72963BBB383F529DCF0C5D17740B8A2ADBE9208D40000000866616B652D736967' self.assertEquals(K, transport._K) - self.assertEquals(H, paramiko.util.hexify(transport._H)) - self.assertEquals(x, paramiko.util.hexify(str(transport._message))) + self.assertEquals(H, hexlify(transport._H).upper()) + self.assertEquals(x, hexlify(str(transport._message)).upper()) self.assert_(transport._activated) diff --git a/tests/test_pkey.py b/tests/test_pkey.py index d5419cd..6a645f7 100644 --- a/tests/test_pkey.py +++ b/tests/test_pkey.py @@ -20,6 +20,7 @@ Some unit tests for public/private key objects. """ +from binascii import hexlify, unhexlify import StringIO import unittest from paramiko import RSAKey, DSSKey, Message, util, randpool @@ -76,14 +77,14 @@ class KeyTest (unittest.TestCase): def test_1_generate_key_bytes(self): from Crypto.Hash import MD5 key = util.generate_key_bytes(MD5, '\x01\x02\x03\x04', 'happy birthday', 30) - exp = util.unhexify('61E1F272F4C1C4561586BD322498C0E924672780F47BB37DDA7D54019E64') + exp = unhexlify('61E1F272F4C1C4561586BD322498C0E924672780F47BB37DDA7D54019E64') self.assertEquals(exp, key) def test_2_load_rsa(self): key = RSAKey.from_private_key_file('tests/test_rsa.key') self.assertEquals('ssh-rsa', key.get_name()) exp_rsa = FINGER_RSA.split()[1].replace(':', '') - my_rsa = util.hexify(key.get_fingerprint()).lower() + my_rsa = hexlify(key.get_fingerprint()) self.assertEquals(exp_rsa, my_rsa) self.assertEquals(PUB_RSA.split()[1], key.get_base64()) self.assertEquals(1024, key.get_bits()) @@ -99,7 +100,7 @@ class KeyTest (unittest.TestCase): key = RSAKey.from_private_key_file('tests/test_rsa_password.key', 'television') self.assertEquals('ssh-rsa', key.get_name()) exp_rsa = FINGER_RSA.split()[1].replace(':', '') - my_rsa = util.hexify(key.get_fingerprint()).lower() + my_rsa = hexlify(key.get_fingerprint()) self.assertEquals(exp_rsa, my_rsa) self.assertEquals(PUB_RSA.split()[1], key.get_base64()) self.assertEquals(1024, key.get_bits()) @@ -108,7 +109,7 @@ class KeyTest (unittest.TestCase): key = DSSKey.from_private_key_file('tests/test_dss.key') self.assertEquals('ssh-dss', key.get_name()) exp_dss = FINGER_DSS.split()[1].replace(':', '') - my_dss = util.hexify(key.get_fingerprint()).lower() + my_dss = hexlify(key.get_fingerprint()) self.assertEquals(exp_dss, my_dss) self.assertEquals(PUB_DSS.split()[1], key.get_base64()) self.assertEquals(1024, key.get_bits()) @@ -124,7 +125,7 @@ class KeyTest (unittest.TestCase): key = DSSKey.from_private_key_file('tests/test_dss_password.key', 'television') self.assertEquals('ssh-dss', key.get_name()) exp_dss = FINGER_DSS.split()[1].replace(':', '') - my_dss = util.hexify(key.get_fingerprint()).lower() + my_dss = hexlify(key.get_fingerprint()) self.assertEquals(exp_dss, my_dss) self.assertEquals(PUB_DSS.split()[1], key.get_base64()) self.assertEquals(1024, key.get_bits()) diff --git a/tests/test_sftp.py b/tests/test_sftp.py index 3377621..1e2785d 100755 --- a/tests/test_sftp.py +++ b/tests/test_sftp.py @@ -23,6 +23,7 @@ a real actual sftp server is contacted, and a new folder is created there to do test file operations in (so no existing files will be harmed). """ +from binascii import hexlify import logging import os import random @@ -589,12 +590,12 @@ class SFTPTest (unittest.TestCase): try: f = sftp.open(FOLDER + '/kitty.txt', 'r') sum = f.check('sha1') - self.assertEquals('91059CFC6615941378D413CB5ADAF4C5EB293402', paramiko.util.hexify(sum)) + self.assertEquals('91059CFC6615941378D413CB5ADAF4C5EB293402', hexlify(sum).upper()) sum = f.check('md5', 0, 512) - self.assertEquals('93DE4788FCA28D471516963A1FE3856A', paramiko.util.hexify(sum)) + self.assertEquals('93DE4788FCA28D471516963A1FE3856A', hexlify(sum).upper()) sum = f.check('md5', 0, 0, 510) self.assertEquals('EB3B45B8CD55A0707D99B177544A319F373183D241432BB2157AB9E46358C4AC90370B5CADE5D90336FC1716F90B36D6', - paramiko.util.hexify(sum)) + hexlify(sum).upper()) f.close() finally: sftp.unlink(FOLDER + '/kitty.txt') diff --git a/tests/test_transport.py b/tests/test_transport.py index 75d3341..e102fe0 100644 --- a/tests/test_transport.py +++ b/tests/test_transport.py @@ -20,10 +20,15 @@ Some unit tests for the ssh2 protocol in Transport. """ -import sys, time, threading, unittest +from binascii import hexlify, unhexlify import select +import sys +import time +import threading +import unittest + from paramiko import Transport, SecurityOptions, ServerInterface, RSAKey, DSSKey, \ - SSHException, BadAuthenticationType, InteractiveQuery, util, ChannelException + SSHException, BadAuthenticationType, InteractiveQuery, ChannelException from paramiko import AUTH_FAILED, AUTH_PARTIALLY_SUCCESSFUL, AUTH_SUCCESSFUL from paramiko import OPEN_SUCCEEDED, OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED from loop import LoopSocket @@ -132,11 +137,11 @@ class TransportTest (unittest.TestCase): def test_2_compute_key(self): self.tc.K = 123281095979686581523377256114209720774539068973101330872763622971399429481072519713536292772709507296759612401802191955568143056534122385270077606457721553469730659233569339356140085284052436697480759510519672848743794433460113118986816826624865291116513647975790797391795651716378444844877749505443714557929L - self.tc.H = util.unhexify('0C8307CDE6856FF30BA93684EB0F04C2520E9ED3') + self.tc.H = unhexlify('0C8307CDE6856FF30BA93684EB0F04C2520E9ED3') self.tc.session_id = self.tc.H key = self.tc._compute_key('C', 32) self.assertEquals('207E66594CA87C44ECCBA3B3CD39FDDB378E6FDB0F97C54B2AA0CFBF900CD995', - util.hexify(key)) + hexlify(key).upper()) def test_3_simple(self): """ diff --git a/tests/test_util.py b/tests/test_util.py index c99c1c9..36da2bf 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -22,6 +22,7 @@ Some unit tests for utility functions. """ +from binascii import hexlify import cStringIO import os import unittest @@ -97,7 +98,7 @@ class UtilTest (unittest.TestCase): self.assertEquals(2, len(hostdict)) self.assertEquals(1, len(hostdict.values()[0])) self.assertEquals(1, len(hostdict.values()[1])) - fp = paramiko.util.hexify(hostdict['secure.example.com']['ssh-rsa'].get_fingerprint()) + fp = hexlify(hostdict['secure.example.com']['ssh-rsa'].get_fingerprint()).upper() self.assertEquals('E6684DB30E109B67B70FF1DC5C7F1363', fp) finally: os.unlink('hostfile.temp')