8000 #7645 correct missing constraints on queue name and acceptable charac… by rjmcginness · Pull Request #7701 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

#7645 correct missing constraints on queue name and acc 8000 eptable charac… #7701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 0 commits into from

Conversation

rjmcginness
Copy link

fix: correct missing constraints on queue name and acceptable characters

#7645

Copy link
Member
@thrau thrau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the contribution @rjmcginness

this one's a headscratcher to me because we already have a method for asserting the queue name, but it's apparently not in use. we do also have assert methods in the sqs queue model itself, which are used, so i'm not sure why these exceptions wouldn't show up

def _assert_queue_name(self, name):
if not re.match(r"^[a-zA-Z0-9_-]{1,80}$", name):
raise InvalidParameterValue(
"Can only include alphanumeric characters, hyphens, or underscores. 1 to 80 in length"
)

verifying the queue name directly in create_queue makes sense to me, but we could maybe re-use the method we already have (linked in it a comment). and then remove the validation from the SqsQueue class accordingly. i just want to avoid having the same code in three different ways.

and it would be great to add snapshot validated tests. if that's too much of a bother for you, i'm happy to help.

Comment on lines 140 to 145
@pytest.mark.only_localstack
def test_queue_name_too_long(self, sqs_create_queue, snapshot):
with pytest.raises(InvalidParameterValue) as e:
sqs_create_queue(QueueName=(81 * "a"))

snapshot.match("queue_name_invalid_character", e.value.response)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like something we could test with snapshotting. here are a couple of examples. if you don't have an AWS account you want to test it with, then i'm happy to help with tests.

@pytest.mark.aws_validated
def test_fifo_queue_requires_suffix(self, sqs_create_queue):
queue_name = f"invalid-{short_uid()}"
attributes = {"FifoQueue": "true"}
with pytest.raises(Exception) as e:
sqs_create_queue(QueueName=queue_name, Attributes=attributes)
e.match("InvalidParameterValue")
@pytest.mark.aws_validated
def test_standard_queue_cannot_have_fifo_suffix(self, sqs_create_queue):
queue_name = f"queue-{short_uid()}.fifo"
with pytest.raises(Exception) as e:
sqs_create_queue(QueueName=queue_name)
e.match("InvalidParameterValue")

Comment on lines 674 to 678
def _verify_valid_queue_name(self, queue_name: str):
name_re = re.compile(sqs_constants.QUEUE_NAME_REGEX + "{" + f"{len(queue_name)}" + "}")
if not queue_name or len(queue_name) > 80 or name_re.match(queue_name) is None:
error_msg = "Can only include alphanumeric characters, hyphens, or underscores. 1 to 80 in length"
raise InvalidParameterValue(error_msg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we actually already have a method for this:

def assert_queue_name(queue_name: str, fifo: bool = False):
if queue_name.endswith(".fifo"):
if not fifo:
# Standard queues with .fifo suffix are not allowed
raise InvalidParameterValue(
"Can only include alphanumeric characters, hyphens, or underscores. 1 to 80 in length"
)
# The .fifo suffix counts towards the 80-character queue name quota.
queue_name = queue_name[:-5] + "_fifo"
# slashes are actually not allowed, but we've allowed it explicitly in localstack
if not re.match(r"^[a-zA-Z0-9/_-]{1,80}$", queue_name):
raise InvalidParameterValue(
"Can only include alphanumeric characters, hyphens, or underscores. 1 to 80 in length"
)

@rjmcginness
Copy link
Author

@thrau Thank you, Thomas. Yes, makes perfect sense. I can try to do this, though it might not be quick. I will try to investigate why the other method is not working and use that in the place I added the new one.

@dominikschubert dominikschubert temporarily deployed to localstack-ext-tests February 17, 2023 10:23 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0