mirror of
https://github.com/cryptoadvance/specter-desktop.git
synced 2026-08-13 12:33:29 +02:00
fix: guard spectrum_endpoint.wallets_get behind extension check (#2535)
Co-authored-by: Nazim <al-munazzim@users.noreply.github.com>
This commit is contained in:
parent
485bbbf5be
commit
31524e43b9
2 changed files with 63 additions and 0 deletions
|
|
@ -150,6 +150,7 @@
|
|||
</div>
|
||||
</text-explainer>
|
||||
|
||||
{% if "spectrum" in specter.service_manager.services %}
|
||||
<text-explainer class="p-3">
|
||||
<span slot="title" class="cursor-pointer">{{ _("Support Tools") }} </span>
|
||||
<div slot="content" class="mt-3">
|
||||
|
|
@ -158,6 +159,7 @@
|
|||
</a>
|
||||
</div>
|
||||
</text-explainer>
|
||||
{% endif %}
|
||||
|
||||
<div class="mt-8">
|
||||
<button type="submit" class="button bg-accent text-white" name="action" value="save">{{ _("Save") }}</button>
|
||||
|
|
|
|||
61
tests/test_general_settings_template.py
Normal file
61
tests/test_general_settings_template.py
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
"""Test that general_settings.jinja handles optional extensions safely.
|
||||
|
||||
Regression test for #2498: spectrum_endpoint.wallets_get crashes
|
||||
when the Spectrum extension is not installed.
|
||||
"""
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
TEMPLATE_PATH = Path(__file__).parent.parent / (
|
||||
"src/cryptoadvance/specter/templates/settings/general_settings.jinja"
|
||||
)
|
||||
|
||||
|
||||
def test_spectrum_wallets_get_is_guarded():
|
||||
"""The spectrum_endpoint.wallets_get url_for must be inside a conditional
|
||||
that checks whether the spectrum extension is loaded."""
|
||||
content = TEMPLATE_PATH.read_text()
|
||||
|
||||
# Find all occurrences of spectrum_endpoint
|
||||
matches = list(re.finditer(r"spectrum_endpoint", content))
|
||||
assert len(matches) > 0, "Template should reference spectrum_endpoint"
|
||||
|
||||
for match in matches:
|
||||
# Get the surrounding context (500 chars before the match)
|
||||
start = max(0, match.start() - 500)
|
||||
before = content[start : match.start()]
|
||||
|
||||
# There must be a guard check before the url_for call
|
||||
# Either {% if "spectrum" in ... %} or similar conditional
|
||||
assert re.search(
|
||||
r'{%[-\s]+if\s+.*spectrum.*service_manager', before
|
||||
), (
|
||||
f"spectrum_endpoint reference at position {match.start()} "
|
||||
f"is not guarded by a service_manager check. "
|
||||
f"This will crash when Spectrum extension is not installed."
|
||||
)
|
||||
|
||||
|
||||
def test_spectrum_guard_has_matching_endif():
|
||||
"""The spectrum conditional block must be properly closed."""
|
||||
content = TEMPLATE_PATH.read_text()
|
||||
|
||||
# Find the guard
|
||||
guard_match = re.search(
|
||||
r'{%[-\s]+if\s+"spectrum"\s+in\s+specter\.service_manager\.services\s*%}',
|
||||
content,
|
||||
)
|
||||
assert guard_match is not None, "Expected spectrum guard conditional"
|
||||
|
||||
# Find the matching endif after the guard
|
||||
after_guard = content[guard_match.end() :]
|
||||
assert "{% endif %}" in after_guard, "spectrum guard must have matching endif"
|
||||
|
||||
# The endif should come before the next major section
|
||||
endif_pos = after_guard.index("{% endif %}")
|
||||
# And the spectrum_endpoint reference should be between the if and endif
|
||||
assert "spectrum_endpoint" in after_guard[:endif_pos], (
|
||||
"spectrum_endpoint.wallets_get should be inside the guarded block"
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue