From cba1b2e18026d1f45ba5e6536d2313c5be5c4201 Mon Sep 17 00:00:00 2001 From: Jovan Zivanov Date: Thu, 26 Dec 2019 16:30:06 +0100 Subject: [PATCH] [codecommit] fix repository name check --- moto/codecommit/responses.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/moto/codecommit/responses.py b/moto/codecommit/responses.py index 3e2cf2539..3c6fdc5ea 100644 --- a/moto/codecommit/responses.py +++ b/moto/codecommit/responses.py @@ -6,13 +6,23 @@ from .models import codecommit_backends from .exceptions import InvalidRepositoryNameException +def _is_repository_name_valid(repository_name): + name_regex = re.compile(r"[\w\.-]+") + result = name_regex.split(repository_name) + if len(result) > 0: + for match in result: + if len(match) > 0: + return False + return True + + class CodeCommitResponse(BaseResponse): @property def codecommit_backend(self): return codecommit_backends[self.region] def create_repository(self): - if not self._is_repository_name_valid(self._get_param("repositoryName")): + if not _is_repository_name_valid(self._get_param("repositoryName")): raise InvalidRepositoryNameException() repository_metadata = self.codecommit_backend.create_repository( @@ -24,7 +34,7 @@ class CodeCommitResponse(BaseResponse): return json.dumps({"repositoryMetadata": repository_metadata}) def get_repository(self): - if not self._is_repository_name_valid(self._get_param("repositoryName")): + if not _is_repository_name_valid(self._get_param("repositoryName")): raise InvalidRepositoryNameException() repository_metadata = self.codecommit_backend.get_repository( @@ -34,7 +44,7 @@ class CodeCommitResponse(BaseResponse): return json.dumps({"repositoryMetadata": repository_metadata}) def delete_repository(self): - if not self._is_repository_name_valid(self._get_param("repositoryName")): + if not _is_repository_name_valid(self._get_param("repositoryName")): raise InvalidRepositoryNameException() repository_id = self.codecommit_backend.delete_repository( @@ -45,8 +55,3 @@ class CodeCommitResponse(BaseResponse): return json.dumps({"repositoryId": repository_id}) return json.dumps({}) - - def _is_repository_name_valid(self, repository_name): - name_regex = re.compile(r"[\w\.-]+") - result = name_regex.fullmatch(repository_name) - return result