fix(frontend): #37 punti 1,4,5,6 - 502 backend giù, barcode quotato, apici Alpine, paginazione ricette
1. api_client.py: ConnectionError/Timeout restituisce status_code=502 invece
di 0 (nessuna route confrontava == 0, verificato); i proxy che inoltrano
resp.get("status_code", 500) ereditano il fix senza altre modifiche.
4. measure.py lookup_barcode: code non stringa -> 400 (prima 500 su
code.strip()); urllib.parse.quote(code, safe="") prima di comporre l'URL
verso il backend - un barcode con '/' o '../' non spezza più il path né
raggiunge altri GET con i permessi dell'utente.
5. Ogni "'{{ _(...) }}'" dentro un attributo Alpine (x-text, :title,
:placeholder, @click) sostituito con "{{ _(...)|tojson_attr }}": la
traduzione EN di admin/stations.html:105 ("Clear the station's recipes")
ha un apostrofo che l'IT non ha, e rompeva quel binding e basta - non è
un XSS, ma stessa classe di difetto di #10. File toccati: admin/stations,
admin/users, maker/recipe_list, maker/recipe_editor, maker/task_editor,
maker/task_drawing, components/caliper_status, measure/select_recipe.
Le occorrenze dentro <script>...</script> (non attributi) sono fuori
perimetro per questo punto.
6. statistics.py dashboard(): ciclo sulle pagine (per_page=100, il massimo
del backend) invece di un'unica chiamata che troncava la tendina ricette
alla centesima.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -472,3 +472,43 @@ class TestSaveMeasurement:
|
||||
assert resp.status_code == 400
|
||||
data = resp.get_json()
|
||||
assert data["error"] is True
|
||||
|
||||
|
||||
class TestLookupBarcode:
|
||||
"""POST /measure/lookup-barcode tests (#37.4)."""
|
||||
|
||||
def test_non_string_code_returns_400_not_500(self, logged_in_client, mock_api_client):
|
||||
"""{"code": 5} used to reach code.strip() on an int and crash to a 500."""
|
||||
resp = logged_in_client.post(
|
||||
"/measure/lookup-barcode", json={"code": 5},
|
||||
)
|
||||
assert resp.status_code == 400
|
||||
assert resp.get_json()["error"] is True
|
||||
mock_api_client.get.assert_not_called()
|
||||
|
||||
def test_code_with_slash_is_url_quoted(
|
||||
self, logged_in_client, mock_api_client, monkeypatch,
|
||||
):
|
||||
""""AB/123" must reach the backend as one path segment, not two."""
|
||||
monkeypatch.setattr("blueprints.measure.Config.STATION_CODE", "ST-TEST")
|
||||
mock_api_client.get_station_recipes.return_value = [{"id": 1}]
|
||||
mock_api_client.get.return_value = {"id": 1, "code": "AB/123"}
|
||||
|
||||
resp = logged_in_client.post(
|
||||
"/measure/lookup-barcode", json={"code": "AB/123"},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
endpoint = mock_api_client.get.call_args[0][0]
|
||||
assert endpoint == "/api/recipes/code/AB%2F123"
|
||||
|
||||
def test_code_with_path_traversal_is_quoted_not_walked(
|
||||
self, logged_in_client, mock_api_client,
|
||||
):
|
||||
mock_api_client.get.return_value = {"error": True, "status_code": 404}
|
||||
|
||||
resp = logged_in_client.post(
|
||||
"/measure/lookup-barcode", json={"code": "../users"},
|
||||
)
|
||||
assert resp.status_code == 404
|
||||
endpoint = mock_api_client.get.call_args[0][0]
|
||||
assert endpoint == "/api/recipes/code/..%2Fusers"
|
||||
|
||||
Reference in New Issue
Block a user