summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_hostkeys.py73
-rw-r--r--tests/test_util.py28
2 files changed, 99 insertions, 2 deletions
diff --git a/tests/test_hostkeys.py b/tests/test_hostkeys.py
new file mode 100644
index 00000000..13426387
--- /dev/null
+++ b/tests/test_hostkeys.py
@@ -0,0 +1,73 @@
+#!/usr/bin/python
+
+# Copyright (C) 2006 Robey Pointer <robey@lag.net>
+#
+# This file is part of paramiko.
+#
+# Paramiko is free software; you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# Paramiko is distrubuted in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with Paramiko; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+"""
+Some unit tests for HostKeys.
+"""
+
+import base64
+import os
+import unittest
+import paramiko
+
+
+test_hosts_file = """\
+secure.example.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA1PD6U2/TVxET6lkpKhOk5r\
+9q/kAYG6sP9f5zuUYP8i7FOFp/6ncCEbbtg/lB+A3iidyxoSWl+9jtoyyDOOVX4UIDV9G11Ml8om3\
+D+jrpI9cycZHqilK0HmxDeCuxbwyMuaCygU9gS2qoRvNLWZk70OpIKSSpBo0Wl3/XUmz9uhc=
+happy.example.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA8bP1ZA7DCZDB9J0s50l31M\
+BGQ3GQ/Fc7SX6gkpXkwcZryoi4kNFhHu5LvHcZPdxXV1D+uTMfGS1eyd2Yz/DoNWXNAl8TI0cAsW\
+5ymME3bQ4J/k1IKxCtz/bAlAqFgKoc+EolMziDYqWIATtW0rYTJvzGAzTmMj80/QpsFH+Pc2M=
+"""
+
+keyblob = """\
+AAAAB3NzaC1yc2EAAAABIwAAAIEA8bP1ZA7DCZDB9J0s50l31MBGQ3GQ/Fc7SX6gkpXkwcZryoi4k\
+NFhHu5LvHcZPdxXV1D+uTMfGS1eyd2Yz/DoNWXNAl8TI0cAsW5ymME3bQ4J/k1IKxCtz/bAlAqFgK\
+oc+EolMziDYqWIATtW0rYTJvzGAzTmMj80/QpsFH+Pc2M="""
+
+
+class HostKeysTest (unittest.TestCase):
+
+ def setUp(self):
+ f = open('hostfile.temp', 'w')
+ f.write(test_hosts_file)
+ f.close()
+
+ def tearDown(self):
+ os.unlink('hostfile.temp')
+
+ def test_1_load(self):
+ hostdict = paramiko.HostKeys('hostfile.temp')
+ 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())
+ self.assertEquals('E6684DB30E109B67B70FF1DC5C7F1363', fp)
+
+ def test_2_add(self):
+ hostdict = paramiko.HostKeys('hostfile.temp')
+ hh = '|1|BMsIC6cUIP2zBuXR3t2LRcJYjzM=|hpkJMysjTk/+zzUUzxQEa2ieq6c='
+ key = paramiko.RSAKey(data=base64.decodestring(keyblob))
+ 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())
+ self.assertEquals('7EC91BB336CB6D810B124B1353C32396', fp)
+ self.assertTrue(hostdict.check('foo.example.com', key))
diff --git a/tests/test_util.py b/tests/test_util.py
index fa8c029b..83852b06 100644
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -23,6 +23,7 @@ Some unit tests for utility functions.
"""
import cStringIO
+import os
import unittest
from Crypto.Hash import SHA
import paramiko.util
@@ -43,10 +44,17 @@ Host spoo.example.com
Crazy something else
"""
+test_hosts_file = """\
+secure.example.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA1PD6U2/TVxET6lkpKhOk5r\
+9q/kAYG6sP9f5zuUYP8i7FOFp/6ncCEbbtg/lB+A3iidyxoSWl+9jtoyyDOOVX4UIDV9G11Ml8om3\
+D+jrpI9cycZHqilK0HmxDeCuxbwyMuaCygU9gS2qoRvNLWZk70OpIKSSpBo0Wl3/XUmz9uhc=
+happy.example.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA8bP1ZA7DCZDB9J0s50l31M\
+BGQ3GQ/Fc7SX6gkpXkwcZryoi4kNFhHu5LvHcZPdxXV1D+uTMfGS1eyd2Yz/DoNWXNAl8TI0cAsW\
+5ymME3bQ4J/k1IKxCtz/bAlAqFgKoc+EolMziDYqWIATtW0rYTJvzGAzTmMj80/QpsFH+Pc2M=
+"""
-class UtilTest (unittest.TestCase):
- K = 14730343317708716439807310032871972459448364195094179797249681733965528989482751523943515690110179031004049109375612685505881911274101441415545039654102474376472240501616988799699744135291070488314748284283496055223852115360852283821334858541043710301057312858051901453919067023103730011648890038847384890504L
+class UtilTest (unittest.TestCase):
def setUp(self):
pass
@@ -78,3 +86,19 @@ class UtilTest (unittest.TestCase):
x = paramiko.util.generate_key_bytes(SHA, 'ABCDEFGH', 'This is my secret passphrase.', 64)
hex = ''.join(['%02x' % ord(c) for c in x])
self.assertEquals(hex, '9110e2f6793b69363e58173e9436b13a5a4b339005741d5c680e505f57d871347b4239f14fb5c46e857d5e100424873ba849ac699cea98d729e57b3e84378e8b')
+
+ def test_4_host_keys(self):
+ f = open('hostfile.temp', 'w')
+ f.write(test_hosts_file)
+ f.close()
+ try:
+ hostdict = paramiko.util.load_host_keys('hostfile.temp')
+ 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())
+ self.assertEquals('E6684DB30E109B67B70FF1DC5C7F1363', fp)
+ finally:
+ os.unlink('hostfile.temp')
+
+