1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

core: do not clear cache on ClearSession

This commit is contained in:
Tomas Susanka 2020-02-03 15:28:08 +00:00 committed by Pavol Rusnak
parent da4743c234
commit 15ed5cd19e
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 9 additions and 40 deletions

View File

@ -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:

View File

@ -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()

View File

@ -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