From 8e55b55f3a2856998a8cbed2fa05a83fd583db86 Mon Sep 17 00:00:00 2001 From: wanghao Date: Tue, 13 Jun 2017 09:58:30 +0800 Subject: [PATCH] Fix the creation issue when special meanings words in queue name Now when using zaqarclient to create a queue with some special meanings words like '#' and '%', then cli will return the queue with the name has created successfully, but in zaqar server side, the name is not as same as the client side. Change-Id: Ia776bb4f7253b1698ec97702e0fc69704b97ed7e Closes-Bug: #1584639 --- ...add-validation-for-queue-name-6e417870cc257308.yaml | 9 +++++++++ zaqarclient/queues/v1/queues.py | 10 ++++++++++ zaqarclient/tests/queues/queues.py | 6 ++++++ 3 files changed, 25 insertions(+) create mode 100644 releasenotes/notes/add-validation-for-queue-name-6e417870cc257308.yaml diff --git a/releasenotes/notes/add-validation-for-queue-name-6e417870cc257308.yaml b/releasenotes/notes/add-validation-for-queue-name-6e417870cc257308.yaml new file mode 100644 index 0000000..e39cd0a --- /dev/null +++ b/releasenotes/notes/add-validation-for-queue-name-6e417870cc257308.yaml @@ -0,0 +1,9 @@ +--- +fixes: + - Fix the creation issue when special meanings words in queue name. + When using zaqarclient to create a queue with some special + meanings words like "#" and "%", then cli will return the queue + with the name has created successfully, but in zaqar server side, + the name is not as same as the client side. + Add the check for some special meanings words, it will raise error message + when using those words in queue name. diff --git a/zaqarclient/queues/v1/queues.py b/zaqarclient/queues/v1/queues.py index 718fbb9..3c1a0bb 100644 --- a/zaqarclient/queues/v1/queues.py +++ b/zaqarclient/queues/v1/queues.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import re + from zaqarclient._i18n import _ # noqa from zaqarclient import errors from zaqarclient.queues.v1 import claim as claim_api @@ -20,6 +22,10 @@ from zaqarclient.queues.v1 import core from zaqarclient.queues.v1 import iterator from zaqarclient.queues.v1 import message +# NOTE(wanghao): This is copied from Zaqar server side, so if server have +# updated it someday, we should update it here to keep consistent. +QUEUE_NAME_REGEX = re.compile('^[a-zA-Z0-9_\-]+$') + class Queue(object): @@ -45,6 +51,10 @@ class Queue(object): if name == "": raise ValueError(_('Queue name does not have a value')) + if not QUEUE_NAME_REGEX.match(str(name)): + raise ValueError(_('The queue name may only contain ASCII ' + 'letters, digits, underscores and dashes.')) + # NOTE(flaper87) Queue Info self._name = name self._metadata = metadata diff --git a/zaqarclient/tests/queues/queues.py b/zaqarclient/tests/queues/queues.py index 88ca1d2..046b341 100644 --- a/zaqarclient/tests/queues/queues.py +++ b/zaqarclient/tests/queues/queues.py @@ -71,6 +71,12 @@ class QueuesV1QueueUnitTest(base.QueuesTestBase): def test_queue_valid_name(self): self.assertRaises(ValueError, self.client.queue, "") + def test_queue_valid_name_with_pound(self): + self.assertRaises(ValueError, self.client.queue, "123#456") + + def test_queue_valid_name_with_percent(self): + self.assertRaises(ValueError, self.client.queue, "123%456") + def test_queue_delete(self): with mock.patch.object(self.transport, 'send', autospec=True) as send_method: