From 50baea11d8cf8b3f091f4c6170b462eac6ab247d Mon Sep 17 00:00:00 2001 From: James Saryerwinnie Date: Wed, 26 Jul 2017 14:20:59 -0700 Subject: [PATCH] Validate route cannot be the empty string This results in an opaque error message when you try to deploy. --- chalice/deploy/deployer.py | 2 ++ tests/unit/deploy/test_deployer.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/chalice/deploy/deployer.py b/chalice/deploy/deployer.py index 91785ef8bc..828e03ff5d 100644 --- a/chalice/deploy/deployer.py +++ b/chalice/deploy/deployer.py @@ -89,6 +89,8 @@ def validate_routes(routes): # # * any routes that end with a trailing slash. for route_name, methods in routes.items(): + if not route_name: + raise ValueError("Route cannot be the empty string") if route_name != '/' and route_name.endswith('/'): raise ValueError("Route cannot end with a trailing slash: %s" % route_name) diff --git a/tests/unit/deploy/test_deployer.py b/tests/unit/deploy/test_deployer.py index 579985d089..692606ec60 100644 --- a/tests/unit/deploy/test_deployer.py +++ b/tests/unit/deploy/test_deployer.py @@ -315,6 +315,14 @@ def test_trailing_slash_routes_result_in_error(): validate_configuration(config) +def test_empty_route_results_in_error(): + app = Chalice('appname') + app.routes = {'': {}} + config = Config.create(chalice_app=app) + with pytest.raises(ValueError): + validate_configuration(config) + + def test_validate_python_version_invalid(): config = mock.Mock(spec=Config) config.lambda_python_version = 'python1.0'