summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2012-08-14 09:45:53 +0200
committerClaude Paroz <claude@2xlibre.net>2012-08-14 09:51:39 +0200
commit0df0cf70d43a642393d118523b7efdc04dae6105 (patch)
treeecded0dca47ddc708e6d85a942948eeba53e1795
parent363dbd920e9b77da83895598f0fc9f7f835df65d (diff)
Reverted pickle-json replacement form_hmac calculation
This reverts commit b109ff8062f4bb225181ec462d69c9dd79339567 and complement test cases. The change was too hasty, as some form values cannot be json-serialized as is.
-rw-r--r--django/contrib/formtools/tests/__init__.py19
-rw-r--r--django/contrib/formtools/tests/forms.py1
-rw-r--r--django/contrib/formtools/utils.py6
3 files changed, 15 insertions, 11 deletions
diff --git a/django/contrib/formtools/tests/__init__.py b/django/contrib/formtools/tests/__init__.py
index f3537f4afd..36c7a6d0a2 100644
--- a/django/contrib/formtools/tests/__init__.py
+++ b/django/contrib/formtools/tests/__init__.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
+import datetime
import os
import re
import warnings
@@ -80,7 +81,7 @@ class PreviewTests(TestCase):
"""
# Pass strings for form submittal and add stage variable to
# show we previously saw first stage of the form.
- self.test_data.update({'stage': 1})
+ self.test_data.update({'stage': 1, 'date1': datetime.date(2006, 10, 25)})
response = self.client.post('/preview/', self.test_data)
# Check to confirm stage is set to 2 in output form.
stage = self.input % 2
@@ -98,7 +99,7 @@ class PreviewTests(TestCase):
"""
# Pass strings for form submittal and add stage variable to
# show we previously saw first stage of the form.
- self.test_data.update({'stage':2})
+ self.test_data.update({'stage': 2, 'date1': datetime.date(2006, 10, 25)})
response = self.client.post('/preview/', self.test_data)
self.assertNotEqual(response.content, success_string_encoded)
hash = self.preview.security_hash(None, TestForm(self.test_data))
@@ -272,7 +273,7 @@ class WizardTests(TestCase):
"""
data = {"0-field": "test",
"1-field": "test2",
- "hash_0": "09a53d8de15fc155bad33423e1d2ee2d82484d8a",
+ "hash_0": "cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
"wizard_step": "1"}
response = self.client.post('/wizard1/', data)
self.assertEqual(2, response.context['step0'])
@@ -297,15 +298,15 @@ class WizardTests(TestCase):
wizard = WizardWithProcessStep([WizardPageOneForm])
data = {"0-field": "test",
"1-field": "test2",
- "hash_0": "09a53d8de15fc155bad33423e1d2ee2d82484d8a",
+ "hash_0": "cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
"wizard_step": "1"}
wizard(DummyRequest(POST=data))
self.assertTrue(reached[0])
data = {"0-field": "test",
"1-field": "test2",
- "hash_0": "09a53d8de15fc155bad33423e1d2ee2d82484d8a",
- "hash_1": "4c352938f08b0e6467bef3cda578a1d4a82edc66",
+ "hash_0": "cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
+ "hash_1": "1e6f6315da42e62f33a30640ec7e007ad3fbf1a1",
"wizard_step": "2"}
self.assertRaises(http.Http404, wizard, DummyRequest(POST=data))
@@ -327,7 +328,7 @@ class WizardTests(TestCase):
WizardPageThreeForm])
data = {"0-field": "test",
"1-field": "test2",
- "hash_0": "09a53d8de15fc155bad33423e1d2ee2d82484d8a",
+ "hash_0": "cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
"wizard_step": "1"}
wizard(DummyRequest(POST=data))
self.assertTrue(reached[0])
@@ -351,7 +352,7 @@ class WizardTests(TestCase):
data = {"0-field": "test",
"1-field": "test2",
- "hash_0": "09a53d8de15fc155bad33423e1d2ee2d82484d8a",
+ "hash_0": "cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
"wizard_step": "1"}
wizard(DummyRequest(POST=data))
self.assertTrue(reached[0])
@@ -377,7 +378,7 @@ class WizardTests(TestCase):
WizardPageThreeForm])
data = {"0-field": "test",
"1-field": "test2",
- "hash_0": "09a53d8de15fc155bad33423e1d2ee2d82484d8a",
+ "hash_0": "cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
"wizard_step": "1"}
wizard(DummyRequest(POST=data))
self.assertTrue(reached[0])
diff --git a/django/contrib/formtools/tests/forms.py b/django/contrib/formtools/tests/forms.py
index 9f6f596d3c..1ed2ab48bb 100644
--- a/django/contrib/formtools/tests/forms.py
+++ b/django/contrib/formtools/tests/forms.py
@@ -21,6 +21,7 @@ class TestForm(forms.Form):
field1 = forms.CharField()
field1_ = forms.CharField()
bool1 = forms.BooleanField(required=False)
+ date1 = forms.DateField(required=False)
class HashTestForm(forms.Form):
name = forms.CharField()
diff --git a/django/contrib/formtools/utils.py b/django/contrib/formtools/utils.py
index 8b37651ab7..76277c6b49 100644
--- a/django/contrib/formtools/utils.py
+++ b/django/contrib/formtools/utils.py
@@ -1,6 +1,7 @@
from __future__ import unicode_literals
-import json
+# Do not try cPickle here (see #18340)
+import pickle
from django.utils.crypto import salted_hmac
from django.utils import six
@@ -22,5 +23,6 @@ def form_hmac(form):
value = value.strip()
data.append((bf.name, value))
+ pickled = pickle.dumps(data, pickle.HIGHEST_PROTOCOL)
key_salt = 'django.contrib.formtools'
- return salted_hmac(key_salt, json.dumps(data)).hexdigest()
+ return salted_hmac(key_salt, pickled).hexdigest()