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

@@ -47,7 +47,7 @@ from app.utils import (
)
@main.route("/services/<service_id>/jobs")
@main.route("/services/<uuid:service_id>/jobs")
@user_has_permissions()
def view_jobs(service_id):
page = int(request.args.get('page', 1))
@@ -81,7 +81,7 @@ def view_jobs(service_id):
)
@main.route("/services/<service_id>/jobs/<job_id>")
@main.route("/services/<uuid:service_id>/jobs/<uuid:job_id>")
@user_has_permissions()
def view_job(service_id, job_id):
job = job_api_client.get_job(service_id, job_id)['data']
@@ -130,7 +130,7 @@ def view_job(service_id, job_id):
)
@main.route("/services/<service_id>/jobs/<job_id>.csv")
@main.route("/services/<uuid:service_id>/jobs/<uuid:job_id>.csv")
@user_has_permissions('view_activity')
def view_job_csv(service_id, job_id):
job = job_api_client.get_job(service_id, job_id)['data']
@@ -164,14 +164,14 @@ def view_job_csv(service_id, job_id):
)
@main.route("/services/<service_id>/jobs/<job_id>", methods=['POST'])
@main.route("/services/<uuid:service_id>/jobs/<uuid:job_id>", methods=['POST'])
@user_has_permissions('send_messages')
def cancel_job(service_id, job_id):
job_api_client.cancel_job(service_id, job_id)
return redirect(url_for('main.service_dashboard', service_id=service_id))
@main.route("/services/<service_id>/jobs/<uuid:job_id>/cancel", methods=['GET', 'POST'])
@main.route("/services/<uuid:service_id>/jobs/<uuid:job_id>/cancel", methods=['GET', 'POST'])
@user_has_permissions()
def cancel_letter_job(service_id, job_id):
if request.method == 'POST':
@@ -196,7 +196,7 @@ def cancel_letter_job(service_id, job_id):
return view_job(service_id, job_id)
@main.route("/services/<service_id>/jobs/<job_id>.json")
@main.route("/services/<uuid:service_id>/jobs/<uuid:job_id>.json")
@user_has_permissions()
def view_job_updates(service_id, job_id):
@@ -212,8 +212,8 @@ def view_job_updates(service_id, job_id):
))
@main.route('/services/<service_id>/notifications', methods=['GET', 'POST'])
@main.route('/services/<service_id>/notifications/<message_type>', methods=['GET', 'POST'])
@main.route('/services/<uuid:service_id>/notifications', methods=['GET', 'POST'])
@main.route('/services/<uuid:service_id>/notifications/<message_type>', methods=['GET', 'POST'])
@user_has_permissions()
def view_notifications(service_id, message_type=None):
return render_template(
@@ -236,8 +236,8 @@ def view_notifications(service_id, message_type=None):
)
@main.route('/services/<service_id>/notifications.json', methods=['GET', 'POST'])
@main.route('/services/<service_id>/notifications/<message_type>.json', methods=['GET', 'POST'])
@main.route('/services/<uuid:service_id>/notifications.json', methods=['GET', 'POST'])
@main.route('/services/<uuid:service_id>/notifications/<message_type>.json', methods=['GET', 'POST'])
@user_has_permissions()
def get_notifications_as_json(service_id, message_type=None):
return jsonify(get_notifications(
@@ -245,7 +245,7 @@ def get_notifications_as_json(service_id, message_type=None):
))
@main.route('/services/<service_id>/notifications/<message_type>.csv', endpoint="view_notifications_csv")
@main.route('/services/<uuid:service_id>/notifications/<message_type>.csv', endpoint="view_notifications_csv")
@user_has_permissions()
def get_notifications(service_id, message_type, status_override=None):
# TODO get the api to return count of pages as well.