mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2026-10-29 18:15:29 +00:00
Build and push containers / metadata (push) Canceled after 0s
Build and push containers / build-push-containers (push) Canceled after 0s
ChangeDetection.io Container Build Test / Build linux/amd64 (alpine) (push) Canceled after 0s
ChangeDetection.io Container Build Test / Build linux/arm64 (alpine) (push) Canceled after 0s
ChangeDetection.io Container Build Test / Build linux/amd64 (main) (push) Canceled after 0s
ChangeDetection.io Container Build Test / Build linux/arm/v7 (main) (push) Canceled after 0s
ChangeDetection.io Container Build Test / Build linux/arm/v8 (main) (push) Canceled after 0s
ChangeDetection.io Container Build Test / Build linux/arm64 (main) (push) Canceled after 0s
ChangeDetection.io App Test / lint-code (push) Canceled after 0s
ChangeDetection.io App Test / lint-translations (push) Canceled after 0s
ChangeDetection.io App Test / lint-template-i18n (push) Canceled after 0s
ChangeDetection.io App Test / test-application-3-11 (push) Canceled after 0s
ChangeDetection.io App Test / test-application-3-12 (push) Canceled after 0s
ChangeDetection.io App Test / test-application-3-13 (push) Canceled after 0s
ChangeDetection.io App Test / test-application-3-14 (push) Canceled after 0s
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Build distribution 📦 (push) Canceled after 0s
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Test the built package works basically. (push) Canceled after 0s
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Publish Python 🐍 distribution 📦 to PyPI (push) Canceled after 0s
* API - Reject broken Jinja2 in url, link_to_open, body and headers, shared validation with the edit form
The edit form validated Jinja2 templates on save but the API did not, so a broken body or
header template saved through the API only failed at fetch time, on every check.
- New jinja2_custom/validate.py: validate_jinja2_fields() renders each value that matches
JINJA2_MARKER_PATTERN and returns {field: translated error}
- The edit form uses it instead of four copies of the same try/except
- API create and update return 400 naming the field
Translations: messages moved to the new file (msgids unchanged); also translated the header
error for fr/it and fixed the cs/es wording.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* rebuild
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
|
|
# run from dir above changedetectionio/ dir
|
|
# python3 -m pytest changedetectionio/tests/unit/test_jinja2_validate.py
|
|
|
|
from changedetectionio.jinja2_custom.validate import validate_jinja2_fields
|
|
|
|
|
|
def test_valid_and_non_template_values_pass():
|
|
assert validate_jinja2_fields(
|
|
url="https://example.com/{{ 1+1 }}",
|
|
link_to_open="https://example.com/{% if true %}yes{% endif %}",
|
|
body='{"q": "{%22key%22:1}"}', # URL-encoded JSON, not Jinja2
|
|
headers={'x-plain': 'value', 'x-templated': '{{ 2*2 }}'},
|
|
) == {}
|
|
assert validate_jinja2_fields() == {}
|
|
|
|
|
|
def test_broken_templates_are_reported_per_field():
|
|
errors = validate_jinja2_fields(
|
|
url="https://example.com/{{ broken(",
|
|
link_to_open="https://example.com/{% if %}",
|
|
body="{{ unclosed",
|
|
headers={'x-ok': 'fine', 'x-bad': '{% endfor %}'},
|
|
)
|
|
assert set(errors) == {'url', 'link_to_open', 'body', 'headers'}
|
|
assert errors['body'].startswith('Invalid template syntax')
|
|
# The broken header is named so the user knows which one to fix
|
|
assert '"x-bad"' in errors['headers']
|
|
|
|
|
|
def test_non_string_values_are_ignored():
|
|
assert validate_jinja2_fields(url=None, body=None, headers={'x-num': 5}) == {}
|