Do not allow spaces as key pair name
This fixes a bug where spaces were treated as a valid key pair name. Change-Id: Ie0dc31111db3753b8fb9f31159da9fb43d5a74aa Closes-Bug: #1509217
This commit is contained in:
@@ -29,10 +29,11 @@ from openstack_dashboard import api
|
||||
|
||||
NEW_LINES = re.compile(r"\r|\n")
|
||||
|
||||
KEYPAIR_NAME_REGEX = re.compile(r"^[\w\- ]+$", re.UNICODE)
|
||||
KEYPAIR_NAME_REGEX = re.compile(r"^\w+(?:[- ]\w+)*$", re.UNICODE)
|
||||
KEYPAIR_ERROR_MESSAGES = {
|
||||
'invalid': _('Key pair name may only contain letters, '
|
||||
'numbers, underscores, spaces and hyphens.')}
|
||||
'numbers, underscores, spaces, and hyphens '
|
||||
'and may not be white space.')}
|
||||
|
||||
|
||||
class CreateKeypair(forms.SelfHandlingForm):
|
||||
|
@@ -182,6 +182,19 @@ class KeyPairViewTests(test.TestCase):
|
||||
msg = six.text_type(KEYPAIR_ERROR_MESSAGES['invalid'])
|
||||
self.assertFormErrors(res, count=1, message=msg)
|
||||
|
||||
def test_import_keypair_space_key_name(self):
|
||||
key_name = " "
|
||||
public_key = "ABCDEF"
|
||||
|
||||
formData = {'method': 'ImportKeypair',
|
||||
'name': key_name,
|
||||
'public_key': public_key}
|
||||
url = reverse('horizon:project:access_and_security:keypairs:import')
|
||||
res = self.client.post(url, formData, follow=True)
|
||||
self.assertEqual(res.redirect_chain, [])
|
||||
msg = six.text_type(KEYPAIR_ERROR_MESSAGES['invalid'])
|
||||
self.assertFormErrors(res, count=1, message=msg)
|
||||
|
||||
@test.create_stubs({api.nova: ("keypair_create",)})
|
||||
def test_generate_keypair_exception(self):
|
||||
keypair = self.keypairs.first()
|
||||
|
Reference in New Issue
Block a user