From 2aa49fda968c2060b6085744d1095e9190df5e23 Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Wed, 4 Dec 2019 14:23:54 +0000 Subject: [PATCH] storage/tests: test non-existing key --- storage/tests/python/src/storage.py | 10 +++++++--- storage/tests/tests/test_set_get.py | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/storage/tests/python/src/storage.py b/storage/tests/python/src/storage.py index cb42382475..744fe7043c 100644 --- a/storage/tests/python/src/storage.py +++ b/storage/tests/python/src/storage.py @@ -130,8 +130,12 @@ class Storage: # public fields can be read from an unlocked device raise RuntimeError("Storage locked") if consts.is_app_public(app): - return self.nc.get(key) - return self._get_encrypted(key) + value = self.nc.get(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: app = key >> 8 @@ -153,7 +157,7 @@ class Storage: app = key >> 8 self._check_lock(app) - current = self.get(key) + current = self.nc.get(key) if current is False: self.set_counter(key, 0) return 0 diff --git a/storage/tests/tests/test_set_get.py b/storage/tests/tests/test_set_get.py index 727bc20a27..cb313cf84c 100644 --- a/storage/tests/tests/test_set_get.py +++ b/storage/tests/tests/test_set_get.py @@ -83,6 +83,13 @@ def test_invalid_key(): 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(): sc, sp = common.init(unlock=True) for s in (sc, sp):