1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-03 12:00:59 +00:00

storage/tests: test non-existing key

This commit is contained in:
Tomas Susanka 2019-12-04 14:23:54 +00:00
parent 252d069a66
commit 2aa49fda96
2 changed files with 14 additions and 3 deletions

View File

@ -130,8 +130,12 @@ class Storage:
# public fields can be read from an unlocked device # public fields can be read from an unlocked device
raise RuntimeError("Storage locked") raise RuntimeError("Storage locked")
if consts.is_app_public(app): if consts.is_app_public(app):
return self.nc.get(key) value = self.nc.get(key)
return self._get_encrypted(key) else:
value = self._get_encrypted(key)
if value is False:
raise RuntimeError("Failed to find key in storage.")
return value
def set(self, key: int, val: bytes) -> bool: def set(self, key: int, val: bytes) -> bool:
app = key >> 8 app = key >> 8
@ -153,7 +157,7 @@ class Storage:
app = key >> 8 app = key >> 8
self._check_lock(app) self._check_lock(app)
current = self.get(key) current = self.nc.get(key)
if current is False: if current is False:
self.set_counter(key, 0) self.set_counter(key, 0)
return 0 return 0

View File

@ -83,6 +83,13 @@ def test_invalid_key():
s.set(0xFFFF, b"Hello") s.set(0xFFFF, b"Hello")
def test_non_existing_key():
sc, sp = common.init()
for s in (sc, sp):
with pytest.raises(RuntimeError):
s.get(0xABCD)
def test_chacha_strings(): def test_chacha_strings():
sc, sp = common.init(unlock=True) sc, sp = common.init(unlock=True)
for s in (sc, sp): for s in (sc, sp):