summaryrefslogtreecommitdiffstats
path: root/tests/test_ipapython
diff options
context:
space:
mode:
authorJan Cholasta <jcholast@redhat.com>2012-09-03 09:33:30 -0400
committerRob Crittenden <rcritten@redhat.com>2012-09-06 19:11:57 -0400
commit46ad724301e301d1bc96216b8873e704a37d35e3 (patch)
tree908bb30a22e372cf110be7d0e40f4e9a22c469bc /tests/test_ipapython
parent0f81268ec4a006625c8286ac7c6f5fed5aab7346 (diff)
downloadfreeipa-46ad724301e301d1bc96216b8873e704a37d35e3.tar.gz
freeipa-46ad724301e301d1bc96216b8873e704a37d35e3.tar.xz
freeipa-46ad724301e301d1bc96216b8873e704a37d35e3.zip
Use OpenSSH-style public keys as the preferred format of SSH public keys.
Public keys in the old format (raw RFC 4253 blob) are automatically converted to OpenSSH-style public keys. OpenSSH-style public keys are now stored in LDAP. Changed sshpubkeyfp to be an output parameter, as that is what it actually is. Allow parameter normalizers to be used on values of any type, not just unicode, so that public key blobs (which are str) can be normalized to OpenSSH-style public keys. ticket 2932, 2935
Diffstat (limited to 'tests/test_ipapython')
-rw-r--r--tests/test_ipapython/test_ssh.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/test_ipapython/test_ssh.py b/tests/test_ipapython/test_ssh.py
new file mode 100644
index 000000000..2640af50d
--- /dev/null
+++ b/tests/test_ipapython/test_ssh.py
@@ -0,0 +1,76 @@
+# Authors:
+# Jan Cholasta <jcholast@redhat.com>
+#
+# Copyright (C) 2011 Red Hat
+# see file 'COPYING' for use and warranty information
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+Test the `ipapython/ssh.py` module.
+"""
+
+import base64
+import nose
+
+from ipapython import ssh
+
+class CheckPublicKey:
+ def __init__(self, pk):
+ self.description = "Test SSH public key parsing (%s)" % repr(pk)
+
+ def __call__(self, pk, out):
+ try:
+ parsed = ssh.SSHPublicKey(pk)
+ assert parsed.openssh() == out
+ except Exception, e:
+ assert type(e) is out
+
+def test_public_key_parsing():
+ b64 = 'AAAAB3NzaC1yc2EAAAADAQABAAABAQDGAX3xAeLeaJggwTqMjxNwa6XHBUAikXPGMzEpVrlLDCZtv00djsFTBi38PkgxBJVkgRWMrcBsr/35lq7P6w8KGIwA8GI48Z0qBS2NBMJ2u9WQ2hjLN6GdMlo77O0uJY3251p12pCVIS/bHRSq8kHO2No8g7KA9fGGcagPfQH+ee3t7HUkpbQkFTmbPPN++r3V8oVUk5LxbryB3UIIVzNmcSIn3JrXynlvui4MixvrtX6zx+O/bBo68o8/eZD26QrahVbA09fivrn/4h3TM019Eu/c2jOdckfU3cHUV/3Tno5d6JicibyaoDDK7S/yjdn5jhaz8MSEayQvFkZkiF0L'
+ raw = base64.b64decode(b64)
+ openssh = 'ssh-rsa %s' % b64
+
+ pks = [
+ ('\xff', UnicodeDecodeError),
+
+ (raw, openssh),
+ ('\0\0\0\x04none', u'none AAAABG5vbmU='),
+ ('\0\0\0', ValueError),
+ ('\0\0\0\0', ValueError),
+ ('\0\0\0\x01', ValueError),
+ ('\0\0\0\x01\xff', ValueError),
+
+ (b64, openssh),
+ (unicode(b64), openssh),
+ (u'\n%s\n\n' % b64, openssh),
+ (u'AAAABG5vbmU=', u'none AAAABG5vbmU='),
+ (u'AAAAB', ValueError),
+
+ (openssh, openssh),
+ (unicode(openssh), openssh),
+ (u'none AAAABG5vbmU=', u'none AAAABG5vbmU='),
+ (u'\t \t ssh-rsa \t \t%s\t \tthis is a comment\t \t ' % b64,
+ u'%s this is a comment' % openssh),
+ (u'opt3,opt2="\tx ",opt1,opt2="\\"x " %s comment ' % openssh,
+ u'opt1,opt2="\\"x ",opt3 %s comment' % openssh),
+ (u'ssh-rsa\n%s' % b64, ValueError),
+ (u'ssh-rsa\t%s' % b64, ValueError),
+ (u'vanitas %s' % b64, ValueError),
+ (u'@opt %s' % openssh, ValueError),
+ (u'opt=val %s' % openssh, ValueError),
+ (u'opt, %s' % openssh, ValueError),
+ ]
+
+ for pk in pks:
+ yield (CheckPublicKey(pk[0]),) + pk