1
# Copyright (c) 2008 Twisted Matrix Laboratories.
2
# See LICENSE for details.
5
Tests for L{twisted.conch.scripts.ckeygen}.
9
from StringIO import StringIO
15
skip = "PyCrypto and pyasn1 required for twisted.conch.scripts.ckeygen."
17
from twisted.conch.ssh.keys import Key
18
from twisted.conch.scripts.ckeygen import printFingerprint, _saveKey
20
from twisted.python.filepath import FilePath
21
from twisted.trial.unittest import TestCase
22
from twisted.conch.test.keydata import publicRSA_openssh, privateRSA_openssh
26
class KeyGenTests(TestCase):
28
Tests for various functions used to implement the I{ckeygen} script.
32
Patch C{sys.stdout} with a L{StringIO} instance to tests can make
33
assertions about what's printed.
35
self.stdout = StringIO()
36
self.patch(sys, 'stdout', self.stdout)
39
def test_printFingerprint(self):
41
L{printFingerprint} writes a line to standard out giving the number of
42
bits of the key, its fingerprint, and the basename of the file from it
45
filename = self.mktemp()
46
FilePath(filename).setContent(publicRSA_openssh)
47
printFingerprint({'filename': filename})
49
self.stdout.getvalue(),
50
'768 3d:13:5f:cb:c9:79:8a:93:06:27:65:bc:3d:0b:8f:af temp\n')
53
def test_saveKey(self):
55
L{_saveKey} writes the private and public parts of a key to two
56
different files and writes a report of this to standard out.
58
base = FilePath(self.mktemp())
60
filename = base.child('id_rsa').path
61
key = Key.fromString(privateRSA_openssh)
64
{'filename': filename, 'pass': 'passphrase'})
66
self.stdout.getvalue(),
67
"Your identification has been saved in %s\n"
68
"Your public key has been saved in %s.pub\n"
69
"The key fingerprint is:\n"
70
"3d:13:5f:cb:c9:79:8a:93:06:27:65:bc:3d:0b:8f:af\n" % (
75
base.child('id_rsa').getContent(), None, 'passphrase'),
78
Key.fromString(base.child('id_rsa.pub').getContent()),