Ticket #6607: 6607_2.patch
File 6607_2.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':''},raw_input=fake_input,default_file = filename) 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 try: 161 displayPublicKey( 162 {'filename': ''},raw_input=fake_input, 163 default_file=filename) 164 except: 165 self.fail() 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': ''},raw_input=fake_input,default_file=filename) 393 except: 394 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 printFingerprint(options,raw_input=raw_input,default_file='~/.ssh/id_rsa'): 103 103 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) 104 filename = os.path.expanduser(default_file) 105 options['filename'] = raw_input( 106 'Enter file in which the key is (%s): ' % filename 107 ).strip() or filename 106 108 if os.path.exists(options['filename']+'.pub'): 107 109 options['filename'] += '.pub' 108 110 try: … … 118 120 119 121 120 122 121 def changePassPhrase(options ):123 def changePassPhrase(options,raw_input=raw_input,default_file='~/.ssh/id_rsa'): 122 124 if not options['filename']: 123 filename = os.path.expanduser( '~/.ssh/id_rsa')125 filename = os.path.expanduser(default_file) 124 126 options['filename'] = raw_input( 125 'Enter file in which the key is (%s): ' % filename) 127 'Enter file in which the key is (%s): ' % filename 128 ).strip() or filename 126 129 try: 127 130 key = keys.Key.fromFile(options['filename']).keyObject 128 131 except keys.EncryptedKeyError as e: … … 168 171 169 172 170 173 171 def displayPublicKey(options ):174 def displayPublicKey(options,raw_input=raw_input,default_file='~/.ssh/id_rsa'): 172 175 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) 176 filename = os.path.expanduser(default_file) 177 options['filename'] = raw_input( 178 'Enter file in which the key is (%s): ' % filename 179 ).strip() or filename 175 180 try: 176 181 key = keys.Key.fromFile(options['filename']).keyObject 177 182 except keys.EncryptedKeyError: