Mercurial > kallithea
changeset 7774:e53f1db2b839
ssh: when adding a new public key, if no description is provided and the SSH key itself has a comment, use that as description
Based on work by Ilya Beda <ir4y.ix@gmail.com> on
https://bitbucket.org/ir4y/rhodecode/commits/branch/ssh_server_support , also
heavily modified by Mads Kiilerich.
author | Christian Oyarzun <oyarzun@gmail.com> |
---|---|
date | Mon, 17 Nov 2014 14:42:45 -0500 |
parents | 3b147c38b674 |
children | 9e1d4409d9ef |
files | kallithea/model/ssh_key.py kallithea/tests/functional/test_admin_users.py kallithea/tests/functional/test_my_account.py |
diffstat | 3 files changed, 5 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/model/ssh_key.py Mon Nov 17 14:42:45 2014 -0500 +++ b/kallithea/model/ssh_key.py Mon Nov 17 14:42:45 2014 -0500 @@ -45,9 +45,11 @@ Will raise SshKeyModelException on errors """ try: - ssh.parse_pub_key(public_key) + keytype, pub, comment = ssh.parse_pub_key(public_key) except ssh.SshKeyParseError as e: raise SshKeyModelException(_('SSH key %r is invalid: %s') % (safe_str(public_key), e.message)) + if not description.strip(): + description = comment.strip() user = User.guess_instance(user)
--- a/kallithea/tests/functional/test_admin_users.py Mon Nov 17 14:42:45 2014 -0500 +++ b/kallithea/tests/functional/test_admin_users.py Mon Nov 17 14:42:45 2014 -0500 @@ -553,7 +553,7 @@ self.checkSessionFlash(response, 'SSH key %s successfully added' % fingerprint) response.follow() ssh_key = UserSshKeys.query().filter(UserSshKeys.user_id == user_id).one() - assert ssh_key.description == description + assert ssh_key.description == u'me@localhost' response = self.app.post(url('edit_user_ssh_keys_delete', id=user_id), {'del_public_key': ssh_key.public_key,
--- a/kallithea/tests/functional/test_my_account.py Mon Nov 17 14:42:45 2014 -0500 +++ b/kallithea/tests/functional/test_my_account.py Mon Nov 17 14:42:45 2014 -0500 @@ -285,7 +285,7 @@ response.follow() user_id = response.session['authuser']['user_id'] ssh_key = UserSshKeys.query().filter(UserSshKeys.user_id == user_id).one() - assert ssh_key.description == description + assert ssh_key.description == u'me@localhost' response = self.app.post(url('my_account_ssh_keys_delete'), {'del_public_key': ssh_key.public_key,