Avoid any capitalization of the name "None"
Forbid users to create shares with all case variations of the name "None". Forbid share creation with any case variants of the name "None" Use capitalize method to avoid any case variation of the word none case variant regardless of case variants Closes-Bug: #1909477 Change-Id: I2627da92c93b2f021a48ac1fc158e8e19ca2d176
This commit is contained in:
parent
301274dbfe
commit
1597bf6deb
@ -194,6 +194,11 @@ class CreateShare(command.ShowOne):
|
||||
# TODO(s0ru): the table shows 'Field', 'Value'
|
||||
share_client = self.app.client_manager.share
|
||||
|
||||
if parsed_args.name:
|
||||
if parsed_args.name.capitalize() == 'None':
|
||||
raise apiclient_exceptions.CommandError(
|
||||
"Share name cannot be with the value 'None'")
|
||||
|
||||
if parsed_args.share_type:
|
||||
share_type = apiutils.find_resource(share_client.share_types,
|
||||
parsed_args.share_type).id
|
||||
|
@ -14,6 +14,7 @@
|
||||
#
|
||||
|
||||
import argparse
|
||||
import ddt
|
||||
from unittest import mock
|
||||
import uuid
|
||||
|
||||
@ -70,6 +71,7 @@ class TestShare(manila_fakes.TestShare):
|
||||
return shares
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestShareCreate(TestShare):
|
||||
|
||||
def setUp(self):
|
||||
@ -360,6 +362,28 @@ class TestShareCreate(TestShare):
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
|
||||
@ddt.data('None', 'NONE', 'none')
|
||||
def test_create_share_with_the_name_none(self, name):
|
||||
arglist = [
|
||||
'--name', name,
|
||||
self.new_share.share_proto,
|
||||
str(self.new_share.size),
|
||||
'--share-type', self.share_type.id,
|
||||
]
|
||||
verifylist = [
|
||||
('name', name),
|
||||
('share_proto', self.new_share.share_proto),
|
||||
('size', self.new_share.size),
|
||||
('share_type', self.share_type.id),
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
|
||||
|
||||
class TestShareDelete(TestShare):
|
||||
|
||||
|
@ -2201,6 +2201,12 @@ class ShellTest(test_utils.TestCase):
|
||||
self.assertRaises(
|
||||
exceptions.CommandError, self.run_command, "create nfs 1")
|
||||
|
||||
@ddt.data('None', 'NONE', 'none')
|
||||
def test_create_share_with_the_name_none(self, name):
|
||||
self.assertRaises(
|
||||
exceptions.CommandError, self.run_command,
|
||||
"create nfs 1 --name %s --share-type test_type" % name)
|
||||
|
||||
def test_allow_access_cert(self):
|
||||
self.run_command("access-allow 1234 cert client.example.com")
|
||||
|
||||
|
@ -986,9 +986,10 @@ def do_create(cs, args):
|
||||
if args.snapshot_id:
|
||||
snapshot = _find_share_snapshot(cs, args.snapshot_id).id
|
||||
|
||||
if args.name == 'None':
|
||||
raise exceptions.CommandError(
|
||||
"Share name cannot be with the value 'None'")
|
||||
if args.name:
|
||||
if args.name.capitalize() == 'None':
|
||||
raise exceptions.CommandError(
|
||||
"Share name cannot be with the value 'None'")
|
||||
|
||||
if not args.share_type:
|
||||
try:
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
`Launchpad bug 1909477 <https://bugs.launchpad.net/python-manilaclient/+bug/1909477>`_
|
||||
has been fixed by prevent sending the share creation request with any capitalization of
|
||||
the name "None".
|
Loading…
Reference in New Issue
Block a user