Require IDs to be UUIDs in URLS

We mostly rely on the API returning a 404 to generate 404s for trying
to get things with non-UUID IDs. This is fine, except our tests often
mock these API calls. So it could look like everything is working fine,
except the thing your passing in might never be a valid UUID, and thus
would 404 in a non-test environment.

So this commit:
1. uses the `uuid` URL converter everywhere there’s something that looks
   like an ID in a URL parameter
2.  adds a test which automates checking for 1.
This commit is contained in:
Chris Hill-Scott
2019-11-04 11:07:55 +00:00
parent 554a852e2d
commit ef335e7601
26 changed files with 283 additions and 233 deletions

View File

@@ -48,7 +48,7 @@ from app.utils import (
)
@main.route("/services/<service_id>/notification/<uuid:notification_id>")
@main.route("/services/<uuid:service_id>/notification/<uuid:notification_id>")
@user_has_permissions('view_activity', 'send_messages')
def view_notification(service_id, notification_id):
notification = notification_api_client.get_notification(service_id, str(notification_id))
@@ -162,7 +162,7 @@ def view_notification(service_id, notification_id):
)
@main.route("/services/<service_id>/notification/<uuid:notification_id>/cancel", methods=['GET', 'POST'])
@main.route("/services/<uuid:service_id>/notification/<uuid:notification_id>/cancel", methods=['GET', 'POST'])
@user_has_permissions('view_activity', 'send_messages')
def cancel_letter(service_id, notification_id):
@@ -180,7 +180,7 @@ def get_preview_error_image():
return file.read()
@main.route("/services/<service_id>/notification/<uuid:notification_id>.<filetype>")
@main.route("/services/<uuid:service_id>/notification/<uuid:notification_id>.<filetype>")
@user_has_permissions('view_activity')
def view_letter_notification_as_preview(
service_id, notification_id, filetype, with_metadata=False
@@ -207,7 +207,7 @@ def view_letter_notification_as_preview(
return display_file
@main.route("/services/<service_id>/notification/<notification_id>.json")
@main.route("/services/<uuid:service_id>/notification/<uuid:notification_id>.json")
@user_has_permissions('view_activity', 'send_messages')
def view_notification_updates(service_id, notification_id):
return jsonify(**get_single_notification_partials(
@@ -241,7 +241,7 @@ def get_all_personalisation_from_notification(notification):
return notification['personalisation']
@main.route("/services/<service_id>/download-notifications.csv")
@main.route("/services/<uuid:service_id>/download-notifications.csv")
@user_has_permissions('view_activity')
def download_notifications_csv(service_id):
filter_args = parse_filter_args(request.args)