Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #38 -- Return 400 if the given step is not found #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions formtools/wizard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.utils.decorators import classonlymethod
from django.utils.translation import ugettext as _
from django.utils import six
from django.http import HttpResponseBadRequest

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

# Check if form was refreshed
management_form = ManagementForm(self.request.POST, prefix=self.prefix)

field = '%s-current_step' % self.prefix
step_name = management_form.data.get(field, '')
if step_name not in dir(self.steps):
return HttpResponseBadRequest('Unknown step %s' % step_name)

if not management_form.is_valid():
raise ValidationError(
_('ManagementForm data is missing or has been tampered.'),
Expand Down
13 changes: 13 additions & 0 deletions tests/wizard/wizardtests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,19 @@ def test_form_refresh(self):
self.assertEqual(response.status_code, 200)


@skipIfCustomUser
@override_settings(ROOT_URLCONF='tests.wizard.wizardtests.urls')
class InvalidStepTests(TestCase):
def test_unknown_step_400(self):
for step in ('"', 'invalid-step', '-'):
response = self.client.post('/wiz_session/', {
'form1-name': 'Pony',
'form1-thirsty': '2',
'session_contact_wizard-current_step': step,
})
self.assertEqual(response.status_code, 400)


@skipIfCustomUser
@override_settings(ROOT_URLCONF='tests.wizard.wizardtests.urls')
class SessionWizardTests(WizardTests, TestCase):
Expand Down