Skip to content

Commit c5b6e9b

Browse files
authored
Merge pull request #4 from Styria-Digital/feature/optional_checksum_check
Feature/optional checksum check
2 parents 9c31164 + 8535329 commit c5b6e9b

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Releasing as an installable package is planned only for a private repo for now,
1212

1313
Available additional settings that can be set to `UNICORN` dict in settings.py which are not part of official package.
1414

15-
- `USE_CSRF_TOKEN` - default: `True` - If set to `False`, unicorn does not check or send `csrf` token value so `{% csrf_token %}` is not mandatory in the templates. This is added due the fact to additional page caching system like `Varnish` does not operate effective if `Cookie` value is present in `Vary` header.
15+
- `USE_CSRF_TOKEN` - default: `True` - If set to `False`, unicorn does not check or send `csrf` token value so `{% csrf_token %}` is not mandatory in the templates. This is added due the fact to additional page caching system like `Varnish` does not operate effective if `Cookie` value is present in `Vary` header.
16+
- `CHECK_CHECKSUM_MATCH` - default: `True` - If set to `False`, `unicorn` does not perform data checksum check on each request.
1617

1718
## Deployment
1819

@@ -24,6 +25,10 @@ Available additional settings that can be set to `UNICORN` dict in settings.py w
2425

2526
## Customization changelog
2627

28+
### 0.58.1.2 - (2024-01-10)
29+
30+
- add optional `CHECK_CHECKSUM_MATCH` setting which is set by default to True. If turned off, `unicorn` does not perform data checksum check on each request.
31+
2732
### 0.58.1.1 - (2024-01-10)
2833

2934
- No customizations, just sync with main package.

django_unicorn/views/objects.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from django_unicorn.components import HashUpdate, LocationUpdate, PollUpdate
66
from django_unicorn.errors import UnicornViewError
77
from django_unicorn.serializer import JSONDecodeError, dumps, loads
8+
from django_unicorn.settings import get_setting
89
from django_unicorn.utils import generate_checksum, is_int
910

1011
logger = logging.getLogger(__name__)
@@ -88,6 +89,9 @@ def validate_checksum(self):
8889
"""
8990
Validates that the checksum in the request matches the data.
9091
92+
If `CHECK_CHECKSUM_MATCH` is set to False,
93+
checking of matching checksum is avoided.
94+
9195
Returns:
9296
Raises `AssertionError` if the checksums don't match.
9397
"""
@@ -97,11 +101,14 @@ def validate_checksum(self):
97101
# TODO: Raise specific exception
98102
raise AssertionError("Missing checksum")
99103

100-
generated_checksum = generate_checksum(self.data)
104+
check_checksum_match = get_setting("CHECK_CHECKSUM_MATCH", True)
101105

102-
if checksum != generated_checksum:
103-
# TODO: Raise specific exception
104-
raise AssertionError("Checksum does not match")
106+
if check_checksum_match:
107+
generated_checksum = generate_checksum(self.data)
108+
109+
if checksum != generated_checksum:
110+
# TODO: Raise specific exception
111+
raise AssertionError("Checksum does not match")
105112

106113

107114
class Return:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-unicorn-loosened"
3-
version = "0.58.1.1"
3+
version = "0.58.1.2"
44
description = "An alternate version of a magical full-stack framework for Django."
55
authors = ["Adam Hill <[email protected]>", "Styria Digital Development <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)