1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 01:18:28 +00:00

Test for protect_call

This commit is contained in:
slush 2013-01-14 17:05:38 +01:00
parent 1c78397c1b
commit 1e6588e28f

View File

@ -2,29 +2,58 @@ import unittest
import common import common
from bitkeylib import proto from bitkeylib import proto
from bitkeylib.client import CallException, PinException, OtpException
class TestProtectCall(common.BitkeyTest): class TestProtectCall(common.BitkeyTest):
def test_features(self): def _some_protected_call(self):
features = self.bitkey.call(proto.Initialize(session_id=self.bitkey.session_id)) # This method perform any call which have protection in the device
entropy_len = 10
entropy = self.bitkey.get_entropy(entropy_len)
self.assertEqual(len(entropy), entropy_len)
# Result is the same as reported by BitkeyClient class def test_no_protection(self):
self.assertEqual(features, self.bitkey.features) self.bitkey.load_device(seed='beyond neighbor scratch swirl embarrass doll cause also stick softly physical nice',
otp=False, pin='', spv=False)
def test_ping(self): self.assertEqual(self.bitkey.features.otp, False)
ping = self.bitkey.call(proto.Ping(message='ahoj!')) self.assertEqual(self.bitkey.features.pin, False)
self._some_protected_call()
# Ping results in Success(message='Ahoj!') def test_otp_only(self):
self.assertEqual(ping, proto.Success(message='ahoj!')) self.bitkey.load_device(seed='beyond neighbor scratch swirl embarrass doll cause also stick softly physical nice',
otp=True, pin='', spv=False)
def test_uuid(self): self.assertEqual(self.bitkey.features.otp, True)
uuid1 = self.bitkey.get_uuid() self.assertEqual(self.bitkey.features.pin, False)
uuid2 = self.bitkey.get_uuid() self._some_protected_call()
# UUID must be longer than 10 characters def test_pin_only(self):
self.assertGreater(len(uuid1), 10) self.bitkey.load_device(seed='beyond neighbor scratch swirl embarrass doll cause also stick softly physical nice',
otp=False, pin='2345', spv=False)
# Every resulf of UUID must be the same self.assertEqual(self.bitkey.features.otp, False)
self.assertEqual(uuid1, uuid2) self.assertEqual(self.bitkey.features.pin, True)
self._some_protected_call()
def test_both(self):
self.bitkey.load_device(seed='beyond neighbor scratch swirl embarrass doll cause also stick softly physical nice',
otp=True, pin='3456', spv=False)
self.assertEqual(self.bitkey.features.otp, True)
self.assertEqual(self.bitkey.features.pin, True)
self._some_protected_call()
def test_incorrect_pin(self):
self.bitkey.setup_debuglink(button=True, pin_correct=False, otp_correct=True)
self.assertRaises(PinException, self._some_protected_call)
def test_incorrect_otp(self):
self.bitkey.setup_debuglink(button=True, pin_correct=True, otp_correct=False)
self.assertRaises(OtpException, self._some_protected_call)
def test_incorrect_both(self):
self.bitkey.setup_debuglink(button=True, pin_correct=False, otp_correct=False)
self.assertRaises(CallException, self._some_protected_call)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()