Skip to content
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

fix: catch error caused by improper event configuration #845

Merged
merged 1 commit into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions samtranslator/plugins/api/implicit_api_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,11 @@ def _process_api_events(self, function, api_events, template, condition=None):
self._add_implicit_api_id_if_necessary(event_properties)

api_id = self._get_api_id(event_properties)
path = event_properties["Path"]
method = event_properties["Method"]
try:
path = event_properties["Path"]
method = event_properties["Method"]
except KeyError as e:
raise InvalidEventException(logicalId, "Event is missing key {}.".format(e))
api_dict = self.api_conditions.setdefault(api_id, {})
method_conditions = api_dict.setdefault(path, {})
method_conditions[method] = condition
Expand Down
25 changes: 25 additions & 0 deletions tests/plugins/api/test_implicit_api_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,31 @@ def test_must_work_with_api_events(self):

function_events_mock.update.assert_called_with(api_events)

def test_must_verify_expected_keys_exist(self):

api_events = {
"Api1": {
"Type": "Api",
"Properties": {
"Path": "/",
"Methid": "POST"
}
}
}

template = Mock()
function_events_mock = Mock()
function = SamResource({
"Type": SamResourceType.Function.value,
"Properties": {
"Events": function_events_mock
}
})
function_events_mock.update = Mock()

with self.assertRaises(InvalidEventException) as context:
self.plugin._process_api_events(function, api_events, template)

def test_must_skip_events_without_properties(self):

api_events = {
Expand Down