Check that users can’t skip steps in send test

Because we put the step in the URL, users could:
- skip ahead to a later step
- navigate to a step which doesn’t exist (ie an index greater than the
  number of placeholders)

This commit adds some checks to do the sensible thing in the unlikely
event that either of these situations occur.
This commit is contained in:
Chris Hill-Scott
2017-05-22 11:49:15 +01:00
parent c8a64aeb19
commit cd7c27925c
2 changed files with 126 additions and 1 deletions

View File

@@ -177,6 +177,11 @@ def send_test(service_id, template_id):
@user_has_permissions('send_texts', 'send_emails', 'send_letters')
def send_test_step(service_id, template_id, step_index):
if 'send_test_values' not in session:
return redirect(url_for(
'.send_test', service_id=service_id, template_id=template_id
))
template = service_api_client.get_service_template(service_id, template_id)['data']
if not session.get('send_test_letter_page_count'):
@@ -201,7 +206,12 @@ def send_test_step(service_id, template_id, step_index):
if len(placeholders) == 0:
return make_and_upload_csv_file(service_id, template)
current_placeholder = placeholders[step_index]
try:
current_placeholder = placeholders[step_index]
except IndexError:
return redirect(url_for(
'.send_test', service_id=service_id, template_id=template_id
))
optional_placeholder = (current_placeholder in optional_address_columns)
form = get_placeholder_form_instance(
current_placeholder,