Ticket #6607: 6607_3.patch
File 6607_3.patch, 4.9 KB (added by , 9 years ago) |
---|
-
twisted/conch/test/test_ckeygen.py
68 68 self.assertEqual( 69 69 self.stdout.getvalue(), 70 70 '768 3d:13:5f:cb:c9:79:8a:93:06:27:65:bc:3d:0b:8f:af temp\n') 71 71 72 73 def test_printFingerprintDefultKeyfile(self): 74 """ 75 L{printFingerprint} should provide a default keyfile if nothing is 76 specified. 77 """ 78 def fake_input(str): 79 return '' 80 filename = self.mktemp() 81 FilePath(filename).setContent(publicRSA_openssh) 82 printFingerprint( 83 {'filename':''}, default_file=filename, _raw_input=fake_input) 84 self.assertEqual( 85 self.stdout.getvalue(), 86 '768 3d:13:5f:cb:c9:79:8a:93:06:27:65:bc:3d:0b:8f:af temp\n') 72 87 88 73 89 def test_saveKey(self): 74 90 """ 75 91 L{_saveKey} writes the private and public parts of a key to two … … 131 147 pubKey.toString('openssh')) 132 148 133 149 150 def test_displayPublicKeyDefaultKeyfile(self): 151 """ 152 L{displayPublicKey} should provide a default keyfile if nothing is 153 specified. 154 """ 155 def fake_input(str): 156 return '' 157 filename = self.mktemp() 158 pubKey = Key.fromString(publicRSA_openssh) 159 FilePath(filename).setContent(privateRSA_openssh) 160 displayPublicKey( 161 {'filename': ''}, default_file=filename, 162 _raw_input=fake_input) 163 self.assertEqual( 164 self.stdout.getvalue().strip('\n'), 165 pubKey.toString('openssh')) 166 167 134 168 def test_displayPublicKeyEncrypted(self): 135 169 """ 136 170 L{displayPublicKey} prints out the public key associated with a given … … 338 372 self.assertEqual( 339 373 'Could not change passphrase: key not encrypted', str(error)) 340 374 self.assertEqual(publicRSA_openssh, FilePath(filename).getContent()) 375 376 377 def test_changePassphraseDefaultkeyfile(self): 378 """ 379 L{changePassPhrase} should provide a default for keyfile if nothing 380 is specified. 381 """ 382 def fake_input(str): 383 return '' 384 385 oldNewConfirm = makeGetpass('encrypted', 'newpass', 'newpass') 386 self.patch(getpass, 'getpass', oldNewConfirm) 387 388 filename = self.mktemp() 389 FilePath(filename).setContent(privateRSA_openssh_encrypted) 390 391 try: 392 changePassPhrase({'filename': ''}, default_file=filename, 393 _raw_input=fake_input) 394 except IOError: 395 self.fail() -
twisted/conch/topfiles/6607.feature
1 ckeygen now provides default keyfile for --fingerprint,--showpub and --changepass. -
twisted/conch/scripts/ckeygen.py
99 99 100 100 101 101 102 def printFingerprint(options): 102 def _getFilename(default_file, _raw_input): 103 filename = os.path.expanduser(default_file) 104 filename = _raw_input( 105 'Enter file in which the key is (%s): ' % filename 106 ).strip() or filename 107 return filename 108 109 110 111 def printFingerprint(options, default_file='~/.ssh/id_rsa', _raw_input=raw_input): 103 112 if not options['filename']: 104 filename = os.path.expanduser('~/.ssh/id_rsa') 105 options['filename'] = raw_input('Enter file in which the key is (%s): ' % filename) 113 options['filename'] = _getFilename(default_file, _raw_input) 106 114 if os.path.exists(options['filename']+'.pub'): 107 115 options['filename'] += '.pub' 108 116 try: … … 118 126 119 127 120 128 121 def changePassPhrase(options ):129 def changePassPhrase(options, default_file='~/.ssh/id_rsa', _raw_input=raw_input): 122 130 if not options['filename']: 123 filename = os.path.expanduser('~/.ssh/id_rsa') 124 options['filename'] = raw_input( 125 'Enter file in which the key is (%s): ' % filename) 131 options['filename'] = _getFilename(default_file, _raw_input) 126 132 try: 127 133 key = keys.Key.fromFile(options['filename']).keyObject 128 134 except keys.EncryptedKeyError as e: … … 168 174 169 175 170 176 171 def displayPublicKey(options ):177 def displayPublicKey(options, default_file='~/.ssh/id_rsa', _raw_input=raw_input): 172 178 if not options['filename']: 173 filename = os.path.expanduser('~/.ssh/id_rsa') 174 options['filename'] = raw_input('Enter file in which the key is (%s): ' % filename) 179 options['filename'] = _getFilename(default_file, _raw_input) 175 180 try: 176 181 key = keys.Key.fromFile(options['filename']).keyObject 177 182 except keys.EncryptedKeyError: