2013-01-14 13:44:11 +00:00
|
|
|
import unittest
|
|
|
|
import common
|
|
|
|
|
2013-01-14 16:05:38 +00:00
|
|
|
from bitkeylib.client import CallException, PinException, OtpException
|
2013-04-15 17:57:36 +00:00
|
|
|
from bitkeylib import proto
|
2013-01-14 13:44:11 +00:00
|
|
|
|
|
|
|
class TestProtectCall(common.BitkeyTest):
|
2013-01-14 16:05:38 +00:00
|
|
|
def _some_protected_call(self):
|
|
|
|
# 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)
|
2013-01-14 13:44:11 +00:00
|
|
|
|
2013-01-14 16:05:38 +00:00
|
|
|
def test_no_protection(self):
|
2013-04-15 17:57:36 +00:00
|
|
|
self.bitkey.load_device(algo=proto.ELECTRUM,
|
|
|
|
seed='beyond neighbor scratch swirl embarrass doll cause also stick softly physical nice',
|
2013-01-14 16:05:38 +00:00
|
|
|
otp=False, pin='', spv=False)
|
2013-01-14 13:44:11 +00:00
|
|
|
|
2013-04-15 17:57:36 +00:00
|
|
|
self.assertEqual(self.bitkey.features.has_otp, False)
|
2013-01-14 16:05:38 +00:00
|
|
|
self.assertEqual(self.bitkey.features.pin, False)
|
|
|
|
self._some_protected_call()
|
|
|
|
|
|
|
|
def test_otp_only(self):
|
2013-04-15 17:57:36 +00:00
|
|
|
self.bitkey.load_device(algo=proto.ELECTRUM,
|
|
|
|
seed='beyond neighbor scratch swirl embarrass doll cause also stick softly physical nice',
|
2013-01-14 16:05:38 +00:00
|
|
|
otp=True, pin='', spv=False)
|
|
|
|
|
2013-04-15 17:57:36 +00:00
|
|
|
self.assertEqual(self.bitkey.features.has_otp, True)
|
2013-01-14 16:05:38 +00:00
|
|
|
self.assertEqual(self.bitkey.features.pin, False)
|
|
|
|
self._some_protected_call()
|
2013-01-14 13:44:11 +00:00
|
|
|
|
2013-01-14 16:05:38 +00:00
|
|
|
def test_pin_only(self):
|
2013-04-15 17:57:36 +00:00
|
|
|
self.bitkey.load_device(algo=proto.ELECTRUM,
|
|
|
|
seed='beyond neighbor scratch swirl embarrass doll cause also stick softly physical nice',
|
2013-01-14 16:05:38 +00:00
|
|
|
otp=False, pin='2345', spv=False)
|
|
|
|
|
2013-04-15 17:57:36 +00:00
|
|
|
self.assertEqual(self.bitkey.features.has_otp, False)
|
2013-01-14 16:05:38 +00:00
|
|
|
self.assertEqual(self.bitkey.features.pin, True)
|
|
|
|
self._some_protected_call()
|
2013-01-14 13:44:11 +00:00
|
|
|
|
2013-01-14 16:05:38 +00:00
|
|
|
def test_both(self):
|
2013-04-15 17:57:36 +00:00
|
|
|
self.bitkey.load_device(algo=proto.ELECTRUM,
|
|
|
|
seed='beyond neighbor scratch swirl embarrass doll cause also stick softly physical nice',
|
2013-01-14 16:05:38 +00:00
|
|
|
otp=True, pin='3456', spv=False)
|
2013-01-14 13:44:11 +00:00
|
|
|
|
2013-04-15 17:57:36 +00:00
|
|
|
self.assertEqual(self.bitkey.features.has_otp, True)
|
2013-01-14 16:05:38 +00:00
|
|
|
self.assertEqual(self.bitkey.features.pin, True)
|
|
|
|
self._some_protected_call()
|
2013-01-14 13:44:11 +00:00
|
|
|
|
2013-01-14 16:05:38 +00:00
|
|
|
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)
|
|
|
|
|
2013-01-14 13:44:11 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|