mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-30 01:58:11 +00:00
tests(translations): always use client version for language blobs
and ignore what is written in the jsons
This commit is contained in:
parent
802958bc05
commit
00544312b5
tests
@ -100,7 +100,7 @@ def test_error_invalid_data_length(client: Client):
|
|||||||
# Invalid data length
|
# Invalid data length
|
||||||
# Sending more data than advertised in the header
|
# Sending more data than advertised in the header
|
||||||
with pytest.raises(exceptions.TrezorFailure, match="Invalid data length"), client:
|
with pytest.raises(exceptions.TrezorFailure, match="Invalid data length"), client:
|
||||||
good_data = build_and_sign_blob("cs", client.model)
|
good_data = build_and_sign_blob("cs", client)
|
||||||
bad_data = good_data + b"abcd"
|
bad_data = good_data + b"abcd"
|
||||||
device.change_language(client, language_data=bad_data)
|
device.change_language(client, language_data=bad_data)
|
||||||
assert client.features.language == "en-US"
|
assert client.features.language == "en-US"
|
||||||
@ -114,7 +114,7 @@ def test_error_invalid_header_magic(client: Client):
|
|||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
exceptions.TrezorFailure, match="Invalid translations data"
|
exceptions.TrezorFailure, match="Invalid translations data"
|
||||||
), client:
|
), client:
|
||||||
good_data = build_and_sign_blob("cs", client.model)
|
good_data = build_and_sign_blob("cs", client)
|
||||||
bad_data = 4 * b"a" + good_data[4:]
|
bad_data = 4 * b"a" + good_data[4:]
|
||||||
device.change_language(client, language_data=bad_data)
|
device.change_language(client, language_data=bad_data)
|
||||||
assert client.features.language == "en-US"
|
assert client.features.language == "en-US"
|
||||||
@ -128,7 +128,7 @@ def test_error_invalid_data_hash(client: Client):
|
|||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
exceptions.TrezorFailure, match="Translation data verification failed"
|
exceptions.TrezorFailure, match="Translation data verification failed"
|
||||||
), client:
|
), client:
|
||||||
good_data = build_and_sign_blob("cs", client.model)
|
good_data = build_and_sign_blob("cs", client)
|
||||||
bad_data = good_data[:-8] + 8 * b"a"
|
bad_data = good_data[:-8] + 8 * b"a"
|
||||||
device.change_language(
|
device.change_language(
|
||||||
client,
|
client,
|
||||||
@ -145,11 +145,10 @@ def test_error_version_mismatch(client: Client):
|
|||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
exceptions.TrezorFailure, match="Translations version mismatch"
|
exceptions.TrezorFailure, match="Translations version mismatch"
|
||||||
), client:
|
), client:
|
||||||
data = get_lang_json("cs")
|
blob = prepare_blob("cs", client.model, (3, 5, 4, 0))
|
||||||
data["header"]["version"] = "3.5.4"
|
|
||||||
device.change_language(
|
device.change_language(
|
||||||
client,
|
client,
|
||||||
language_data=build_and_sign_blob(data, client.model),
|
language_data=sign_blob(blob),
|
||||||
)
|
)
|
||||||
assert client.features.language == "en-US"
|
assert client.features.language == "en-US"
|
||||||
_check_ping_screen_texts(client, get_ping_title("en"), get_ping_button("en"))
|
_check_ping_screen_texts(client, get_ping_title("en"), get_ping_button("en"))
|
||||||
@ -221,7 +220,7 @@ def test_translations_renders_on_screen(client: Client):
|
|||||||
czech_data_copy["translations"]["words__confirm"] = new_czech_confirm
|
czech_data_copy["translations"]["words__confirm"] = new_czech_confirm
|
||||||
device.change_language(
|
device.change_language(
|
||||||
client,
|
client,
|
||||||
language_data=build_and_sign_blob(czech_data_copy, client.model),
|
language_data=build_and_sign_blob(czech_data_copy, client),
|
||||||
)
|
)
|
||||||
_check_ping_screen_texts(client, new_czech_confirm, get_ping_button("cs"))
|
_check_ping_screen_texts(client, new_czech_confirm, get_ping_button("cs"))
|
||||||
|
|
||||||
@ -230,7 +229,7 @@ def test_translations_renders_on_screen(client: Client):
|
|||||||
del czech_data_copy["translations"]["words__confirm"]
|
del czech_data_copy["translations"]["words__confirm"]
|
||||||
device.change_language(
|
device.change_language(
|
||||||
client,
|
client,
|
||||||
language_data=build_and_sign_blob(czech_data_copy, client.model),
|
language_data=build_and_sign_blob(czech_data_copy, client),
|
||||||
)
|
)
|
||||||
_check_ping_screen_texts(client, get_ping_title("en"), get_ping_button("cs"))
|
_check_ping_screen_texts(client, get_ping_title("en"), get_ping_button("cs"))
|
||||||
|
|
||||||
@ -238,7 +237,7 @@ def test_translations_renders_on_screen(client: Client):
|
|||||||
def test_reject_update(client: Client):
|
def test_reject_update(client: Client):
|
||||||
assert client.features.language == "en-US"
|
assert client.features.language == "en-US"
|
||||||
lang = "cs"
|
lang = "cs"
|
||||||
language_data = build_and_sign_blob(lang, client.model)
|
language_data = build_and_sign_blob(lang, client)
|
||||||
|
|
||||||
def input_flow_reject():
|
def input_flow_reject():
|
||||||
yield
|
yield
|
||||||
@ -256,7 +255,7 @@ def test_reject_update(client: Client):
|
|||||||
def _maybe_confirm_set_language(
|
def _maybe_confirm_set_language(
|
||||||
client: Client, lang: str, show_display: bool | None, is_displayed: bool
|
client: Client, lang: str, show_display: bool | None, is_displayed: bool
|
||||||
) -> None:
|
) -> None:
|
||||||
language_data = build_and_sign_blob(lang, client.model)
|
language_data = build_and_sign_blob(lang, client)
|
||||||
|
|
||||||
CHUNK_SIZE = 1024
|
CHUNK_SIZE = 1024
|
||||||
|
|
||||||
@ -356,7 +355,7 @@ def test_header_trailing_data(client: Client):
|
|||||||
"""
|
"""
|
||||||
assert client.features.language == "en-US"
|
assert client.features.language == "en-US"
|
||||||
lang = "cs"
|
lang = "cs"
|
||||||
blob = prepare_blob(lang, client.model)
|
blob = prepare_blob(lang, client.model, client.version)
|
||||||
blob.header_bytes += b"trailing dataa"
|
blob.header_bytes += b"trailing dataa"
|
||||||
assert len(blob.header_bytes) % 2 == 0, "Trailing data must keep the 2-alignment"
|
assert len(blob.header_bytes) % 2 == 0, "Trailing data must keep the 2-alignment"
|
||||||
language_data = sign_blob(blob)
|
language_data = sign_blob(blob)
|
||||||
|
@ -22,6 +22,7 @@ LANGUAGES = [file.stem for file in TRANSLATIONS.glob("??.json")]
|
|||||||
def prepare_blob(
|
def prepare_blob(
|
||||||
lang_or_def: translations.JsonDef | Path | str,
|
lang_or_def: translations.JsonDef | Path | str,
|
||||||
model: models.TrezorModel,
|
model: models.TrezorModel,
|
||||||
|
version: translations.VersionTuple | tuple[int, int, int] | None = None,
|
||||||
) -> translations.TranslationsBlob:
|
) -> translations.TranslationsBlob:
|
||||||
order = translations.order_from_json(json.loads(ORDER_FILE.read_text()))
|
order = translations.order_from_json(json.loads(ORDER_FILE.read_text()))
|
||||||
if isinstance(lang_or_def, str):
|
if isinstance(lang_or_def, str):
|
||||||
@ -30,7 +31,11 @@ def prepare_blob(
|
|||||||
lang_or_def = t.cast(translations.JsonDef, json.loads(lang_or_def.read_text()))
|
lang_or_def = t.cast(translations.JsonDef, json.loads(lang_or_def.read_text()))
|
||||||
|
|
||||||
# generate raw blob
|
# generate raw blob
|
||||||
|
if version is None:
|
||||||
version = translations.version_from_json(lang_or_def["header"]["version"])
|
version = translations.version_from_json(lang_or_def["header"]["version"])
|
||||||
|
elif len(version) == 3:
|
||||||
|
# version coming from client object does not have build item
|
||||||
|
version = *version, 0
|
||||||
return translations.blob_from_defs(lang_or_def, order, model, version, FONTS_DIR)
|
return translations.blob_from_defs(lang_or_def, order, model, version, FONTS_DIR)
|
||||||
|
|
||||||
|
|
||||||
@ -48,9 +53,9 @@ def sign_blob(blob: translations.TranslationsBlob) -> bytes:
|
|||||||
|
|
||||||
def build_and_sign_blob(
|
def build_and_sign_blob(
|
||||||
lang_or_def: translations.JsonDef | Path | str,
|
lang_or_def: translations.JsonDef | Path | str,
|
||||||
model: models.TrezorModel,
|
client: Client,
|
||||||
) -> bytes:
|
) -> bytes:
|
||||||
blob = prepare_blob(lang_or_def, model)
|
blob = prepare_blob(lang_or_def, client.model, client.version)
|
||||||
return sign_blob(blob)
|
return sign_blob(blob)
|
||||||
|
|
||||||
|
|
||||||
@ -58,7 +63,7 @@ def set_language(client: Client, lang: str):
|
|||||||
if lang.startswith("en"):
|
if lang.startswith("en"):
|
||||||
language_data = b""
|
language_data = b""
|
||||||
else:
|
else:
|
||||||
language_data = build_and_sign_blob(lang, client.model)
|
language_data = build_and_sign_blob(lang, client)
|
||||||
with client:
|
with client:
|
||||||
device.change_language(client, language_data) # type: ignore
|
device.change_language(client, language_data) # type: ignore
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user