Skip to content

Commit

Permalink
fix: resource policy generation for {path+} (#1580)
Browse files Browse the repository at this point in the history
  • Loading branch information
sriram-mv authored May 29, 2020
1 parent b255f51 commit d168f37
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion samtranslator/swagger/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,4 +1193,5 @@ def safe_compare_regex_with_string(regex, data):

@staticmethod
def get_path_without_trailing_slash(path):
return re.sub(r"{([a-zA-Z0-9._-]+|proxy\+)}", "*", path)
# convert greedy paths to such as {greedy+}, {proxy+} to "*"
return re.sub(r"{([a-zA-Z0-9._-]+|[a-zA-Z0-9._-]+\+|proxy\+)}", "*", path)
17 changes: 17 additions & 0 deletions tests/model/eventsources/test_api_event_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ def test_get_permission_with_trailing_slash(self):

self.assertEqual(arn, "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/foo")

@patch("boto3.session.Session.region_name", "eu-west-2")
def test_get_permission_with_path_parameter_to_any_path(self):
self.api_event_source.Path = "/foo/{userId+}"
cfn = self.api_event_source.to_cloudformation(function=self.func, explicit_api={})

perm = cfn[0]
self.assertIsInstance(perm, LambdaPermission)

try:
arn = self._extract_path_from_arn("{}PermissionProd".format(self.logical_id), perm)
except AttributeError:
self.fail("Permission class isn't valid")

self.assertEqual(
arn, "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/foo/*"
)

@patch("boto3.session.Session.region_name", "eu-west-2")
def test_get_permission_with_path_parameter(self):
self.api_event_source.Path = "/foo/{userId}/bar"
Expand Down

0 comments on commit d168f37

Please sign in to comment.