From ec300a76eb6b9591edfe81e1bce875ef8a5668d8 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Thu, 7 Sep 2017 00:44:39 +0200 Subject: [PATCH] Handled some more errors that can be generated when creating SSHKey --- hosting/forms.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hosting/forms.py b/hosting/forms.py index a4076339..64de0276 100644 --- a/hosting/forms.py +++ b/hosting/forms.py @@ -98,8 +98,8 @@ class UserHostingKeyForm(forms.ModelForm): return self.data.get('public_key') KEY_ERROR_MESSAGE = _("Please input a proper SSH key") openssh_pubkey_str = self.data.get('public_key') - ssh_key = SSHKey(openssh_pubkey_str) try: + ssh_key = SSHKey(openssh_pubkey_str) ssh_key.parse() except InvalidKeyException as err: logger.error( @@ -109,6 +109,14 @@ class UserHostingKeyForm(forms.ModelForm): logger.error( "NotImplementedError while parsing ssh key {0}".format(err)) raise forms.ValidationError(KEY_ERROR_MESSAGE) + except UnicodeDecodeError as u: + logger.error( + "UnicodeDecodeError while parsing ssh key {0}".format(u)) + raise forms.ValidationError(KEY_ERROR_MESSAGE) + except ValueError as v: + logger.error( + "ValueError while parsing ssh key {0}".format(v)) + raise forms.ValidationError(KEY_ERROR_MESSAGE) return openssh_pubkey_str def clean_name(self):