From 15ed5cd19eb53ee58b7f99b928c5fcaddc876b5a Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Mon, 3 Feb 2020 15:28:08 +0000 Subject: [PATCH] core: do not clear cache on ClearSession --- core/src/apps/homescreen/__init__.py | 8 +++++-- core/tests/test_storage.cache.py | 18 --------------- .../test_session_id_and_passphrase.py | 23 +++---------------- 3 files changed, 9 insertions(+), 40 deletions(-) diff --git a/core/src/apps/homescreen/__init__.py b/core/src/apps/homescreen/__init__.py index a7a8719da7..1eabc87191 100644 --- a/core/src/apps/homescreen/__init__.py +++ b/core/src/apps/homescreen/__init__.py @@ -92,8 +92,12 @@ async def handle_Cancel(ctx: wire.Context, msg: Cancel) -> NoReturn: async def handle_ClearSession(ctx: wire.Context, msg: ClearSession) -> Success: - cache.clear() - return Success(message="Session cleared") + """ + This is currently a no-op on T. This should be called LockSession/LockDevice + and lock the device. In other words the cache should stay but the PIN should + be forgotten and required again. + """ + return Success() async def handle_Ping(ctx: wire.Context, msg: Ping) -> Success: diff --git a/core/tests/test_storage.cache.py b/core/tests/test_storage.cache.py index af6c16a3d9..6a290c1c9f 100644 --- a/core/tests/test_storage.cache.py +++ b/core/tests/test_storage.cache.py @@ -76,24 +76,6 @@ class TestStorageCache(unittest.TestCase): call_Initialize(session_id=new_session_id) self.assertIsNone(cache.get(KEY)) - @mock_storage - def test_ClearSession(self): - def call_Initialize(**kwargs): - msg = Initialize(**kwargs) - return await_result(handle_Initialize(DUMMY_CONTEXT, msg)) - - def call_ClearSession(): - return await_result(handle_ClearSession(DUMMY_CONTEXT, ClearSession())) - - session_id = call_Initialize().session_id - cache.set(KEY, "hello") - self.assertEqual(cache.get(KEY), "hello") - - call_ClearSession() - self.assertIsNone(cache.get(KEY)) - new_session_id = cache.get_session_id() - self.assertNotEqual(session_id, new_session_id) - if __name__ == "__main__": unittest.main() diff --git a/tests/device_tests/test_session_id_and_passphrase.py b/tests/device_tests/test_session_id_and_passphrase.py index 60f733aa66..0ec35e44df 100644 --- a/tests/device_tests/test_session_id_and_passphrase.py +++ b/tests/device_tests/test_session_id_and_passphrase.py @@ -98,23 +98,6 @@ def test_session_enable_passphrase(client): assert _get_xpub(client, passphrase="A") == XPUB_PASSPHRASE_A -@pytest.mark.skip_ui -def test_clear_session(client): - session_id = _init_session(client) - - # session id remains the same - new_session_id = _init_session(client, session_id=session_id) - assert session_id == new_session_id - - # by clearing the session, the id is lost - response = client.call(messages.ClearSession()) - assert isinstance(response, messages.Success) - - # cannot resume the old session now - new_session_id = _init_session(client, session_id=session_id) - assert session_id != new_session_id - - @pytest.mark.skip_ui @pytest.mark.setup_client(passphrase=True) def test_clear_session_passphrase(client): @@ -124,9 +107,9 @@ def test_clear_session_passphrase(client): # now the passphrase is cached assert _get_xpub(client, passphrase=None) == XPUB_PASSPHRASE_A - # ClearSession will erase the cached passphrase - response = client.call(messages.ClearSession()) - assert isinstance(response, messages.Success) + # Erase the cached passphrase + response = client.call(messages.Initialize()) + assert isinstance(response, messages.Features) # we have to enter passphrase again assert _get_xpub(client, passphrase="A") == XPUB_PASSPHRASE_A