Skip to content

Commit 32e0eb5

Browse files
authored
Merge pull request #300 from peopledoc/deprecate-get-method-for-validation-endpoint
Disallow GET method for user-data validation URL
2 parents 6c40f3b + 0c54452 commit 32e0eb5

File tree

7 files changed

+35
-72
lines changed

7 files changed

+35
-72
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ master (unreleased)
77

88
- Added tests against the ``formidable.yml`` schema definition of Forms (#295).
99
- Fixed various items in the schema definition (#297).
10+
- Validation endpoint for **user data** doesn't allow GET method anymore (#300).
1011

1112
Release 1.3.0 (2018-02-14)
1213
==========================

demo/tests/test_integration.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -391,15 +391,11 @@ class MyForm(FormidableForm):
391391
class TestValidationEndPoint(FormidableAPITestCase):
392392

393393
url = 'formidable:form_validation'
394-
method = 'get'
395394

396395
def setUp(self):
397396
super(TestValidationEndPoint, self).setUp()
398397
self.formidable = MyForm.to_formidable(label='title')
399398

400-
def get_method(self):
401-
return getattr(self.client, self.method)
402-
403399
def test_validate_data_ok(self):
404400
parameters = {
405401
'first_name': 'Guillaume',
@@ -408,8 +404,7 @@ def test_validate_data_ok(self):
408404
session = self.client.session
409405
session['role'] = 'padawan'
410406
session.save()
411-
func = self.get_method()
412-
res = func(
407+
res = self.client.post(
413408
reverse(self.url, args=[self.formidable.pk]),
414409
parameters, format='json'
415410
)
@@ -424,8 +419,7 @@ def test_formidable_does_not_exist(self):
424419
session = self.client.session
425420
session['role'] = 'padawan'
426421
session.save()
427-
func = self.get_method()
428-
res = func(
422+
res = self.client.post(
429423
reverse(self.url, args=[9999]),
430424
parameters, format='json'
431425
)
@@ -438,8 +432,7 @@ def test_validate_data_ko(self):
438432
session = self.client.session
439433
session['role'] = 'padawan'
440434
session.save()
441-
func = self.get_method()
442-
res = func(
435+
res = self.client.post(
443436
reverse(self.url, args=[self.formidable.pk]),
444437
parameters, format='json'
445438
)
@@ -459,8 +452,7 @@ class WithFile(FormidableForm):
459452
session = self.client.session
460453
session['role'] = 'padawan'
461454
session.save()
462-
func = self.get_method()
463-
res = func(
455+
res = self.client.post(
464456
reverse(self.url, args=[formidable.pk]),
465457
parameters, format='json'
466458
)
@@ -501,8 +493,7 @@ class WithFile(FormidableForm):
501493

502494
# The checkbox is checked.
503495
parameters = {'checkbox': True}
504-
func = self.get_method()
505-
res = func(
496+
res = self.client.post(
506497
reverse(self.url, args=[formidable.pk]),
507498
parameters, format='json'
508499
)
@@ -512,20 +503,28 @@ class WithFile(FormidableForm):
512503

513504
# The checkbox is NOT checked.
514505
parameters = {'checkbox': False}
515-
func = self.get_method()
516-
res = func(
506+
res = self.client.post(
517507
reverse(self.url, args=[formidable.pk]),
518508
parameters, format='json'
519509
)
520510
# We still don't validate file fields.
521511
self.assertEqual(res.status_code, 204)
522512

513+
def test_unallowed_method(self):
514+
parameters = {
515+
'first_name': 'Guillaume',
516+
'last_name': 'Gérard',
517+
}
518+
session = self.client.session
519+
session['role'] = 'padawan'
520+
session.save()
521+
# As of 1.4.0, GET is disallowed.
522+
res = self.client.get(
523+
reverse(self.url, args=[self.formidable.pk]),
524+
parameters, format='json'
525+
)
526+
self.assertEqual(res.status_code, 405)
523527

524-
class TestValidationFromSchemaEndPoint(TestValidationEndPoint):
525528

529+
class TestValidationFromSchemaEndPoint(TestValidationEndPoint):
526530
url = 'form_validation_schema'
527-
528-
529-
class TestValidationWithPostMethod(TestValidationEndPoint):
530-
531-
method = 'post'

demo/tests/test_perfs_rec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_form_validate_perf_rec(self):
108108

109109
with self.record_performance(record_name='validate-form'):
110110
url = reverse('formidable:form_validation', args=(form_id,))
111-
self.client.get(url)
111+
self.client.post(url)
112112

113113
def _create_form(self):
114114
session = self.client.session

docs/source/_static/specs/formidable.js

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -512,28 +512,6 @@ var spec = {
512512
}
513513
},
514514
"/forms/{id}/validate/": {
515-
"get": {
516-
"parameters": [
517-
{
518-
"in": "path",
519-
"name": "id",
520-
"required": true,
521-
"type": "integer"
522-
}
523-
],
524-
"responses": {
525-
"204": {
526-
"description": "Validation OK"
527-
},
528-
"400": {
529-
"description": "Validation KO",
530-
"schema": {
531-
"$ref": "#/definitions/InputError"
532-
}
533-
}
534-
},
535-
"summary": "Validate a form (GET method). GET and POST are equivalent, but GET is deprecated."
536-
},
537515
"post": {
538516
"parameters": [
539517
{
@@ -554,7 +532,7 @@ var spec = {
554532
}
555533
}
556534
},
557-
"summary": "Validate a form (POST method). GET and POST are equivalent."
535+
"summary": "Validate user-data against a form schema."
558536
}
559537
}
560538
},

docs/source/deprecations.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
Deprecation timeline
33
====================
44

5+
From 1.3.0 to 1.4.0
6+
===================
7+
8+
Validation endpoint
9+
-------------------
10+
11+
.. deprecated:: 1.4.0
12+
13+
Validation endpoint for **user data** doesn't allow GET method anymore.
14+
515
From 0.15 to 1.0.0
616
==================
717

docs/swagger/formidable.yml

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,8 @@ paths:
132132
$ref: '#/definitions/BuilderForm'
133133

134134
/forms/{id}/validate/:
135-
get:
136-
summary: Validate a form (GET method). GET and POST are equivalent, but GET is deprecated.
137-
parameters:
138-
- name: id
139-
in: path
140-
type: integer
141-
required: true
142-
responses:
143-
204:
144-
description: Validation OK
145-
400:
146-
description: Validation KO
147-
schema:
148-
$ref: '#/definitions/InputError'
149135
post:
150-
summary: Validate a form (POST method). GET and POST are equivalent.
136+
summary: Validate user-data against a form schema.
151137
parameters:
152138
- name: id
153139
in: path

formidable/views.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import unicode_literals
44

55
import logging
6-
import warnings
76

87
from django.conf import settings
98
from django.core.exceptions import ImproperlyConfigured
@@ -253,16 +252,6 @@ def post(self, request, **kwargs):
253252
else:
254253
return self.form_invalid(form)
255254

256-
def get(self, request, **kwargs):
257-
"""
258-
GET method is deprecated in favor of POST
259-
260-
"""
261-
warnings.warn('GET method for form validation has been deprecated in '
262-
'favor of POST. Please use POST instead of GET.',
263-
category=DeprecationWarning)
264-
return self.post(request, **kwargs)
265-
266255
def get_form_class(self, formidable):
267256
return formidable.get_django_form_class(
268257
**self.get_form_class_kwargs()

0 commit comments

Comments
 (0)