mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-06-30 11:52:34 +00:00
fix(tests): set_filter must be used in with-block
This makes sure filters are properly cleared when the with-block exits
This commit is contained in:
parent
45d377f5b8
commit
b3312d1ef7
@ -407,6 +407,9 @@ class TrezorClientDebugLink(TrezorClient):
|
|||||||
|
|
||||||
Useful for test scenarios with an active malicious actor on the wire.
|
Useful for test scenarios with an active malicious actor on the wire.
|
||||||
"""
|
"""
|
||||||
|
if not self.in_with_statement:
|
||||||
|
raise RuntimeError("Must be called inside 'with' statement")
|
||||||
|
|
||||||
self.filters[message_type] = callback
|
self.filters[message_type] = callback
|
||||||
|
|
||||||
def _filter_message(self, msg):
|
def _filter_message(self, msg):
|
||||||
@ -477,6 +480,7 @@ class TrezorClientDebugLink(TrezorClient):
|
|||||||
|
|
||||||
self.in_with_statement -= 1
|
self.in_with_statement -= 1
|
||||||
self.ui.clear()
|
self.ui.clear()
|
||||||
|
self.filters.clear()
|
||||||
self.watch_layout(False)
|
self.watch_layout(False)
|
||||||
|
|
||||||
if _type is not None:
|
if _type is not None:
|
||||||
|
@ -826,12 +826,12 @@ class TestMsgSigntx:
|
|||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
# Set up attack processors
|
with client, pytest.raises(
|
||||||
client.set_filter(messages.TxAck, attack_processor)
|
|
||||||
|
|
||||||
with pytest.raises(
|
|
||||||
TrezorFailure, match="Transaction has changed during signing"
|
TrezorFailure, match="Transaction has changed during signing"
|
||||||
):
|
):
|
||||||
|
# Set up attack processors
|
||||||
|
client.set_filter(messages.TxAck, attack_processor)
|
||||||
|
|
||||||
btc.sign_tx(
|
btc.sign_tx(
|
||||||
client,
|
client,
|
||||||
"Bitcoin",
|
"Bitcoin",
|
||||||
@ -879,12 +879,12 @@ class TestMsgSigntx:
|
|||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
# Set up attack processors
|
with client, pytest.raises(
|
||||||
client.set_filter(messages.TxAck, attack_processor)
|
|
||||||
|
|
||||||
with pytest.raises(
|
|
||||||
TrezorFailure, match="Transaction has changed during signing"
|
TrezorFailure, match="Transaction has changed during signing"
|
||||||
):
|
):
|
||||||
|
# Set up attack processors
|
||||||
|
client.set_filter(messages.TxAck, attack_processor)
|
||||||
|
|
||||||
btc.sign_tx(
|
btc.sign_tx(
|
||||||
client, "Testnet", [inp1], [out1, out2], prev_txes=TX_CACHE_TESTNET
|
client, "Testnet", [inp1], [out1, out2], prev_txes=TX_CACHE_TESTNET
|
||||||
)
|
)
|
||||||
@ -933,9 +933,9 @@ class TestMsgSigntx:
|
|||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
client.set_filter(messages.TxAck, attack_processor)
|
|
||||||
# Now run the attack, must trigger the exception
|
# Now run the attack, must trigger the exception
|
||||||
with client:
|
with client:
|
||||||
|
client.set_filter(messages.TxAck, attack_processor)
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[
|
[
|
||||||
request_input(0),
|
request_input(0),
|
||||||
|
@ -230,9 +230,8 @@ class TestMsgSigntxBch:
|
|||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
client.set_filter(proto.TxAck, attack_processor)
|
|
||||||
|
|
||||||
with client:
|
with client:
|
||||||
|
client.set_filter(proto.TxAck, attack_processor)
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[
|
[
|
||||||
request_input(0),
|
request_input(0),
|
||||||
|
@ -172,8 +172,8 @@ class TestMsgSigntxBitcoinGold:
|
|||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
client.set_filter(proto.TxAck, attack_processor)
|
|
||||||
with client:
|
with client:
|
||||||
|
client.set_filter(proto.TxAck, attack_processor)
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[
|
[
|
||||||
request_input(0),
|
request_input(0),
|
||||||
|
@ -319,8 +319,8 @@ class TestMsgSigntxSegwit:
|
|||||||
return msg
|
return msg
|
||||||
|
|
||||||
# Now run the attack, must trigger the exception
|
# Now run the attack, must trigger the exception
|
||||||
client.set_filter(proto.TxAck, attack_processor)
|
|
||||||
with client:
|
with client:
|
||||||
|
client.set_filter(proto.TxAck, attack_processor)
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[
|
[
|
||||||
request_input(0),
|
request_input(0),
|
||||||
|
@ -294,8 +294,8 @@ class TestMultisig:
|
|||||||
attack_count -= 1
|
attack_count -= 1
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
client.set_filter(proto.TxAck, attack_processor)
|
|
||||||
with client:
|
with client:
|
||||||
|
client.set_filter(proto.TxAck, attack_processor)
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[
|
[
|
||||||
request_input(0),
|
request_input(0),
|
||||||
|
Loading…
Reference in New Issue
Block a user