Skip to content

Commit bef622b

Browse files
committed
Fix #38 -- Return 400 if the given step is not found
1 parent 8ea0272 commit bef622b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

formtools/wizard/views.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from django.utils.decorators import classonlymethod
1010
from django.utils.translation import ugettext as _
1111
from django.utils import six
12+
from django.http import HttpResponseBadRequest
1213

1314
from .storage import get_storage
1415
from .storage.exceptions import NoFileStorageConfigured
@@ -271,6 +272,12 @@ def post(self, *args, **kwargs):
271272

272273
# Check if form was refreshed
273274
management_form = ManagementForm(self.request.POST, prefix=self.prefix)
275+
276+
field = '%s-current_step' % self.prefix
277+
step_name = management_form.data.get(field, '')
278+
if step_name not in dir(self.steps):
279+
return HttpResponseBadRequest('Unknown step %s' % step_name)
280+
274281
if not management_form.is_valid():
275282
raise ValidationError(
276283
_('ManagementForm data is missing or has been tampered.'),

tests/wizard/wizardtests/tests.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,19 @@ def test_form_refresh(self):
233233
self.assertEqual(response.status_code, 200)
234234

235235

236+
@skipIfCustomUser
237+
@override_settings(ROOT_URLCONF='tests.wizard.wizardtests.urls')
238+
class InvalidStepTests(TestCase):
239+
def test_unknown_step_400(self):
240+
for step in ('"', 'invalid-step', '-'):
241+
response = self.client.post('/wiz_session/', {
242+
'form1-name': 'Pony',
243+
'form1-thirsty': '2',
244+
'session_contact_wizard-current_step': step,
245+
})
246+
self.assertEqual(response.status_code, 400)
247+
248+
236249
@skipIfCustomUser
237250
@override_settings(ROOT_URLCONF='tests.wizard.wizardtests.urls')
238251
class SessionWizardTests(WizardTests, TestCase):

0 commit comments

Comments
 (0)