add ClearSession message with unit test

This commit is contained in:
Pavol Rusnak 2014-06-17 15:31:10 +02:00
parent a3d22dc56e
commit 260a4322a6
4 changed files with 200 additions and 117 deletions

View File

@ -108,6 +108,9 @@ class Commands(object):
def set_label(self, args):
return self.client.apply_settings(label=args.label)
def clear_session(self, args):
return self.client.clear_session()
def change_pin(self, args):
return self.client.change_pin(args.remove)
@ -187,6 +190,7 @@ class Commands(object):
get_features.help = 'Retrieve device features and settings'
get_public_node.help = 'Get public node of given path'
set_label.help = 'Set new wallet label'
clear_session.help = 'Clear session (remove cached PIN, passphrase, etc.)'
change_pin.help = 'Change new PIN or remove existing'
list_coins.help = 'List all supported coin types by the device'
wipe_device.help = 'Reset device to factory defaults and remove all private data.'

View File

@ -0,0 +1,39 @@
import time
import unittest
import common
from trezorlib import messages_pb2 as proto
from trezorlib import types_pb2 as proto_types
class TestMsgClearsession(common.TrezorTest):
def test_clearsession(self):
self.setup_mnemonic_pin_passphrase()
with self.client:
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ProtectCall), proto.PinMatrixRequest(), proto.PassphraseRequest(), proto.Success()])
res = self.client.ping('random data', button_protection=True, pin_protection=True, passphrase_protection=True)
self.assertEqual(res, 'random data')
with self.client:
# pin and passphrase are cached
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ProtectCall), proto.Success()])
res = self.client.ping('random data', button_protection=True, pin_protection=True, passphrase_protection=True)
self.assertEqual(res, 'random data')
self.client.clear_session()
# session cache is cleared
with self.client:
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ProtectCall), proto.PinMatrixRequest(), proto.PassphraseRequest(), proto.Success()])
res = self.client.ping('random data', button_protection=True, pin_protection=True, passphrase_protection=True)
self.assertEqual(res, 'random data')
with self.client:
# pin and passphrase are cached
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ProtectCall), proto.Success()])
res = self.client.ping('random data', button_protection=True, pin_protection=True, passphrase_protection=True)
self.assertEqual(res, 'random data')
if __name__ == '__main__':
unittest.main()

View File

@ -378,6 +378,11 @@ class ProtocolMixin(object):
self.init_device() # Reload Features
return out
@field('message')
@expect(proto.Success)
def clear_session(self):
return self.call(proto.ClearSession())
@field('message')
@expect(proto.Success)
def change_pin(self, remove=False):

File diff suppressed because one or more lines are too long