diff --git a/manilaclient/osc/v2/share.py b/manilaclient/osc/v2/share.py index 7abfefc24..3093b3406 100644 --- a/manilaclient/osc/v2/share.py +++ b/manilaclient/osc/v2/share.py @@ -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 diff --git a/manilaclient/tests/unit/osc/v2/test_share.py b/manilaclient/tests/unit/osc/v2/test_share.py index cfb7f7e55..1654b1bff 100644 --- a/manilaclient/tests/unit/osc/v2/test_share.py +++ b/manilaclient/tests/unit/osc/v2/test_share.py @@ -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): diff --git a/manilaclient/tests/unit/v2/test_shell.py b/manilaclient/tests/unit/v2/test_shell.py index 0126de665..07dd17993 100644 --- a/manilaclient/tests/unit/v2/test_shell.py +++ b/manilaclient/tests/unit/v2/test_shell.py @@ -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") diff --git a/manilaclient/v2/shell.py b/manilaclient/v2/shell.py index e778fc078..b8243a994 100644 --- a/manilaclient/v2/shell.py +++ b/manilaclient/v2/shell.py @@ -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: diff --git a/releasenotes/notes/bug-1909477-fix-forbid-users-to-create-shares-with-the-name-none-cfb0a59baa597803.yaml b/releasenotes/notes/bug-1909477-fix-forbid-users-to-create-shares-with-the-name-none-cfb0a59baa597803.yaml new file mode 100644 index 000000000..339b80445 --- /dev/null +++ b/releasenotes/notes/bug-1909477-fix-forbid-users-to-create-shares-with-the-name-none-cfb0a59baa597803.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + `Launchpad bug 1909477 `_ + has been fixed by prevent sending the share creation request with any capitalization of + the name "None".