Skip to content

Commit 38fdb7d

Browse files
committed
Remove unnecessary sorting in SignedDataForm
The signature does not depend on a canonical representation of the data, so don't bother sorting it. Tweak the data for the tests as a consequence. However, note that the tests are still deterministic since as of version 3.7, Python guarantees dictionary order.
1 parent c03583a commit 38fdb7d

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

debug_toolbar/forms.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def verified_data(self):
4747

4848
@classmethod
4949
def sign(cls, data):
50-
items = sorted(data.items(), key=lambda item: item[0])
5150
return signing.Signer(salt=cls.salt).sign(
52-
json.dumps({key: force_str(value) for key, value in items})
51+
json.dumps({key: force_str(value) for key, value in data.items()})
5352
)

tests/test_forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
SIGNATURE = "-WiogJKyy4E8Om00CrFSy0T6XHObwBa6Zb46u-vmeYE"
99

10-
DATA = {"value": "foo", "date": datetime(2020, 1, 1, tzinfo=timezone.utc)}
10+
DATA = {"date": datetime(2020, 1, 1, tzinfo=timezone.utc), "value": "foo"}
1111
SIGNED_DATA = f'{{"date": "2020-01-01 00:00:00+00:00", "value": "foo"}}:{SIGNATURE}'
1212

1313

0 commit comments

Comments
 (0)