mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-14 11:39:03 +00:00
Tests use new "set_expected_responses"
This commit is contained in:
parent
86a2a9f845
commit
5ed9fc8b1a
@ -20,8 +20,8 @@ TODO:
|
|||||||
x iny cointype ako 0
|
x iny cointype ako 0
|
||||||
|
|
||||||
- chceme v tomto release(?)
|
- chceme v tomto release(?)
|
||||||
* SignMessage workflow
|
x SignMessage workflow
|
||||||
* VerifyMessage workflow
|
x VerifyMessage workflow
|
||||||
|
|
||||||
* otestovat session handling (tento test bude zrejme failovat na RPi)
|
* otestovat session handling (tento test bude zrejme failovat na RPi)
|
||||||
* Failure_NotInitialized
|
* Failure_NotInitialized
|
||||||
@ -31,4 +31,6 @@ TODO:
|
|||||||
* Client requires PIN
|
* Client requires PIN
|
||||||
|
|
||||||
x Zero signature test
|
x Zero signature test
|
||||||
|
|
||||||
|
* test bip39, utf, passphrase
|
||||||
'''
|
'''
|
||||||
|
@ -2,8 +2,6 @@ import unittest
|
|||||||
import common
|
import common
|
||||||
import math
|
import math
|
||||||
|
|
||||||
from trezorlib import messages_pb2 as messages
|
|
||||||
|
|
||||||
def entropy(data):
|
def entropy(data):
|
||||||
counts = {}
|
counts = {}
|
||||||
for c in data:
|
for c in data:
|
||||||
@ -12,7 +10,7 @@ def entropy(data):
|
|||||||
else:
|
else:
|
||||||
counts[c] = 1
|
counts[c] = 1
|
||||||
e = 0
|
e = 0
|
||||||
for k,v in counts.iteritems():
|
for _, v in counts.iteritems():
|
||||||
p = 1.0 * v / len(data)
|
p = 1.0 * v / len(data)
|
||||||
e -= p * math.log(p, 256)
|
e -= p * math.log(p, 256)
|
||||||
return e
|
return e
|
||||||
|
@ -4,7 +4,7 @@ import common
|
|||||||
|
|
||||||
from trezorlib import messages_pb2 as proto
|
from trezorlib import messages_pb2 as proto
|
||||||
from trezorlib import types_pb2 as types
|
from trezorlib import types_pb2 as types
|
||||||
from trezorlib.client import PinException
|
from trezorlib.client import PinException, CallException
|
||||||
|
|
||||||
# FIXME TODO Add passphrase tests
|
# FIXME TODO Add passphrase tests
|
||||||
|
|
||||||
@ -17,6 +17,37 @@ class TestProtectCall(common.TrezorTest):
|
|||||||
passphrase_protection=passphrase)
|
passphrase_protection=passphrase)
|
||||||
self.assertEqual(res, 'random data')
|
self.assertEqual(res, 'random data')
|
||||||
|
|
||||||
|
def test_expected_responses(self):
|
||||||
|
# This is low-level test of set_expected_responses()
|
||||||
|
# feature of debugging client
|
||||||
|
|
||||||
|
# Scenario 1 - Received unexpected message
|
||||||
|
self.client.set_expected_responses([])
|
||||||
|
self.assertRaises(CallException, self._some_protected_call, True, True, True)
|
||||||
|
|
||||||
|
# Scenario 2 - Received other than expected message
|
||||||
|
self.client.set_expected_responses([proto.Success()])
|
||||||
|
self.assertRaises(CallException, self._some_protected_call, True, True, True)
|
||||||
|
|
||||||
|
# Scenario 3 - Not received expected message
|
||||||
|
self.client.set_expected_responses([proto.ButtonRequest(),
|
||||||
|
proto.Success(),
|
||||||
|
proto.Success()]) # This is expected, but not received
|
||||||
|
self.assertRaises(Exception, self._some_protected_call, True, False, False)
|
||||||
|
|
||||||
|
# Scenario 4 - Received what expected
|
||||||
|
self.client.set_expected_responses([proto.ButtonRequest(),
|
||||||
|
proto.PinMatrixRequest(),
|
||||||
|
# proto.PassphraseRequest(), # passhrase is already in session
|
||||||
|
proto.Success(message='random data')])
|
||||||
|
self._some_protected_call(True, True, True)
|
||||||
|
|
||||||
|
# Scenario 5 - Failed message by field filter
|
||||||
|
self.client.set_expected_responses([proto.ButtonRequest(),
|
||||||
|
proto.PinMatrixRequest(),
|
||||||
|
proto.Success(message='wrong data')])
|
||||||
|
self.assertRaises(CallException, self._some_protected_call, True, True, True)
|
||||||
|
|
||||||
def test_no_protection(self):
|
def test_no_protection(self):
|
||||||
self.client.wipe_device()
|
self.client.wipe_device()
|
||||||
self.client.load_device_by_mnemonic(
|
self.client.load_device_by_mnemonic(
|
||||||
@ -28,7 +59,7 @@ class TestProtectCall(common.TrezorTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(self.client.debug.read_pin()[0], '')
|
self.assertEqual(self.client.debug.read_pin()[0], '')
|
||||||
self.client.set_expected_buttonrequests([])
|
self.client.set_expected_responses([proto.Success()])
|
||||||
self._some_protected_call(False, True, True)
|
self._some_protected_call(False, True, True)
|
||||||
|
|
||||||
def test_pin(self):
|
def test_pin(self):
|
||||||
@ -41,7 +72,9 @@ class TestProtectCall(common.TrezorTest):
|
|||||||
|
|
||||||
self.assertEqual(self.client.debug.read_pin()[0], self.pin2)
|
self.assertEqual(self.client.debug.read_pin()[0], self.pin2)
|
||||||
self.client.setup_debuglink(button=True, pin_correct=True)
|
self.client.setup_debuglink(button=True, pin_correct=True)
|
||||||
self.client.set_expected_buttonrequests([types.ButtonRequest_Other])
|
self.client.set_expected_responses([proto.ButtonRequest(),
|
||||||
|
proto.PinMatrixRequest(),
|
||||||
|
proto.Success()])
|
||||||
self._some_protected_call(True, True, False)
|
self._some_protected_call(True, True, False)
|
||||||
|
|
||||||
def test_incorrect_pin(self):
|
def test_incorrect_pin(self):
|
||||||
@ -67,8 +100,7 @@ class TestProtectCall(common.TrezorTest):
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
self.assertRaises(PinException, self._some_protected_call, False, True, False)
|
self.assertRaises(PinException, self._some_protected_call, False, True, False)
|
||||||
test_backoff(attempt, start)
|
test_backoff(attempt, start)
|
||||||
|
'''
|
||||||
'''
|
|
||||||
# Unplug Trezor now
|
# Unplug Trezor now
|
||||||
self.client.debuglink.stop()
|
self.client.debuglink.stop()
|
||||||
self.client.close()
|
self.client.close()
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user