1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-13 19:18:56 +00:00

add one more test to test_msg_changepin

This commit is contained in:
Pavol Rusnak 2014-03-03 00:29:17 +01:00
parent ffa289967c
commit 006812a0b3

View File

@ -6,6 +6,7 @@ from trezorlib import messages_pb2 as proto
from trezorlib import types_pb2 as proto_types
class TestMsgChangepin(common.TrezorTest):
def test_set_pin(self):
self.setup_mnemonic_nopin_nopassphrase()
features = self.client.call_raw(proto.Initialize())
@ -41,6 +42,7 @@ class TestMsgChangepin(common.TrezorTest):
self.assertTrue(features.pin_protection)
ret = self.client.call_raw(proto.Ping(pin_protection=True))
self.assertIsInstance(ret, proto.PinMatrixRequest)
self.client.call_raw(proto.Cancel())
# Check that the PIN is correct
self.assertEqual(self.client.debug.read_pin()[0], self.pin6)
@ -94,7 +96,6 @@ class TestMsgChangepin(common.TrezorTest):
# Check that the PIN is correct
self.assertEqual(self.client.debug.read_pin()[0], self.pin6)
def test_remove_pin(self):
self.setup_mnemonic_pin_passphrase()
features = self.client.call_raw(proto.Initialize())
@ -126,7 +127,7 @@ class TestMsgChangepin(common.TrezorTest):
self.assertFalse(features.pin_protection)
ret = self.client.call_raw(proto.Ping(pin_protection=True))
self.assertIsInstance(ret, proto.Success)
def test_set_failed(self):
self.setup_mnemonic_nopin_nopassphrase()
features = self.client.call_raw(proto.Initialize())
@ -163,5 +164,41 @@ class TestMsgChangepin(common.TrezorTest):
ret = self.client.call_raw(proto.Ping(pin_protection=True))
self.assertIsInstance(ret, proto.Success)
def test_set_failed_2(self):
self.setup_mnemonic_pin_passphrase()
features = self.client.call_raw(proto.Initialize())
self.assertTrue(features.pin_protection)
# Let's set new PIN
ret = self.client.call_raw(proto.ChangePin())
self.assertIsInstance(ret, proto.ButtonRequest)
# Press button
self.client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck())
# Send current PIN
self.assertIsInstance(ret, proto.PinMatrixRequest)
pin_encoded = self.client.debug.read_pin_encoded()
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
# Send the PIN for first time
self.assertIsInstance(ret, proto.PinMatrixRequest)
pin_encoded = self.client.debug.encode_pin(self.pin6)
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
# Send the PIN for second time, but with typo
self.assertIsInstance(ret, proto.PinMatrixRequest)
pin_encoded = self.client.debug.encode_pin(self.pin6 + '3')
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
# Now it should fail, because pins are different
self.assertIsInstance(ret, proto.Failure)
# Check that there's still old PIN protection
features = self.client.call_raw(proto.Initialize())
self.assertTrue(features.pin_protection)
self.assertEqual(self.client.debug.read_pin()[0], self.pin4)
if __name__ == '__main__':
unittest.main()