summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobey Pointer <robey@lag.net>2005-02-15 15:48:47 +0000
committerRobey Pointer <robey@lag.net>2005-02-15 15:48:47 +0000
commitfb2d7bbdddeefd7c519c5a300b2f810fb364884f (patch)
treea7c2a512898ad49f8b83dea08464e63a9291526c
parentc7d56a309d8a1e0b9999cc39e24697f3d45eedcf (diff)
[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-146]
raise better exception on empty key raise a clearer exception when trying to create an empty key.
-rw-r--r--README1
-rw-r--r--paramiko/dsskey.py4
-rw-r--r--paramiko/rsakey.py6
-rw-r--r--tests/test_transport.py34
4 files changed, 41 insertions, 4 deletions
diff --git a/README b/README
index d522dc6f..149f0ab5 100644
--- a/README
+++ b/README
@@ -221,4 +221,3 @@ v0.9 FEAROW
* ctr forms of ciphers are missing (blowfish-ctr, aes128-ctr, aes256-ctr)
* server mode needs better documentation
-* the error message from this is confusing as hell: DSSKey()
diff --git a/paramiko/dsskey.py b/paramiko/dsskey.py
index 09952b9d..f1fe5ae1 100644
--- a/paramiko/dsskey.py
+++ b/paramiko/dsskey.py
@@ -47,7 +47,9 @@ class DSSKey (PKey):
if vals is not None:
self.p, self.q, self.g, self.y = vals
else:
- if (msg is None) or (msg.get_string() != 'ssh-dss'):
+ if msg is None:
+ raise SSHException('Key object may not be empty')
+ if msg.get_string() != 'ssh-dss':
raise SSHException('Invalid key')
self.p = msg.get_mpint()
self.q = msg.get_mpint()
diff --git a/paramiko/rsakey.py b/paramiko/rsakey.py
index e9e7d01a..595b29ed 100644
--- a/paramiko/rsakey.py
+++ b/paramiko/rsakey.py
@@ -39,7 +39,7 @@ class RSAKey (PKey):
data.
"""
- def __init__(self, msg=None, data='', filename=None, password=None, vals=None):
+ def __init__(self, msg=None, data=None, filename=None, password=None, vals=None):
if filename is not None:
self._from_private_key_file(filename, password)
return
@@ -48,7 +48,9 @@ class RSAKey (PKey):
if vals is not None:
self.e, self.n = vals
else:
- if (msg is None) or (msg.get_string() != 'ssh-rsa'):
+ if msg is None:
+ raise SSHException('Key object may not be empty')
+ if msg.get_string() != 'ssh-rsa':
raise SSHException('Invalid key')
self.e = msg.get_mpint()
self.n = msg.get_mpint()
diff --git a/tests/test_transport.py b/tests/test_transport.py
index 3e51485d..71ca140d 100644
--- a/tests/test_transport.py
+++ b/tests/test_transport.py
@@ -311,3 +311,37 @@ class TransportTest (unittest.TestCase):
self.assertEquals('communist j. cat\n', f.readline())
chan.close()
self.assertEquals('', f.readline())
+
+ def test_9_exit_status(self):
+ """
+ verify that get_exit_status() works.
+ """
+ host_key = RSAKey.from_private_key_file('tests/test_rsa.key')
+ public_host_key = RSAKey(data=str(host_key))
+ self.ts.add_server_key(host_key)
+ event = threading.Event()
+ server = NullServer()
+ self.assert_(not event.isSet())
+ self.ts.start_server(event, server)
+ self.tc.ultra_debug = True
+ self.tc.connect(hostkey=public_host_key)
+ self.tc.auth_password(username='slowdive', password='pygmalion')
+ event.wait(1.0)
+ self.assert_(event.isSet())
+ self.assert_(self.ts.is_active())
+
+ chan = self.tc.open_session()
+ schan = self.ts.accept(1.0)
+ self.assert_(chan.exec_command('yes'))
+ schan.send('Hello there.\n')
+ # trigger an EOF
+ schan.shutdown_read()
+ schan.shutdown_write()
+ schan.send_exit_status(23)
+ schan.close()
+
+ f = chan.makefile()
+ self.assertEquals('Hello there.\n', f.readline())
+ self.assertEquals('', f.readline())
+ self.assertEquals(23, chan.recv_exit_status())
+ chan.close()