mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-14 03:30:02 +00:00
tests: update webauthn tests
[no changelog]
This commit is contained in:
parent
1a74b00ded
commit
546deea9f7
@ -17,7 +17,7 @@
|
||||
import pytest
|
||||
|
||||
from trezorlib import fido
|
||||
from trezorlib.debuglink import TrezorClientDebugLink as Client
|
||||
from trezorlib.debuglink import SessionDebugWrapper as Session
|
||||
from trezorlib.exceptions import Cancelled, TrezorFailure
|
||||
|
||||
from ...common import MNEMONIC12
|
||||
@ -29,19 +29,19 @@ RK_CAPACITY = 100
|
||||
@pytest.mark.skip_t1b1
|
||||
@pytest.mark.altcoin
|
||||
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
||||
def test_add_remove(client: Client):
|
||||
def test_add_remove(session: Session):
|
||||
# Remove index 0 should fail.
|
||||
with pytest.raises(TrezorFailure):
|
||||
fido.remove_credential(client, 0)
|
||||
fido.remove_credential(session, 0)
|
||||
|
||||
# List should be empty.
|
||||
assert fido.list_credentials(client) == []
|
||||
assert fido.list_credentials(session) == []
|
||||
|
||||
# Add valid credential #1.
|
||||
fido.add_credential(client, CRED1)
|
||||
fido.add_credential(session, CRED1)
|
||||
|
||||
# Check that the credential was added and parameters are correct.
|
||||
creds = fido.list_credentials(client)
|
||||
creds = fido.list_credentials(session)
|
||||
assert len(creds) == 1
|
||||
assert creds[0].rp_id == "example.com"
|
||||
assert creds[0].rp_name == "Example"
|
||||
@ -54,10 +54,10 @@ def test_add_remove(client: Client):
|
||||
assert creds[0].hmac_secret is True
|
||||
|
||||
# Add valid credential #2, which has same rpId and userId as credential #1.
|
||||
fido.add_credential(client, CRED2)
|
||||
fido.add_credential(session, CRED2)
|
||||
|
||||
# Check that the credential #2 replaced credential #1 and parameters are correct.
|
||||
creds = fido.list_credentials(client)
|
||||
creds = fido.list_credentials(session)
|
||||
assert len(creds) == 1
|
||||
assert creds[0].rp_id == "example.com"
|
||||
assert creds[0].rp_name is None
|
||||
@ -71,32 +71,32 @@ def test_add_remove(client: Client):
|
||||
|
||||
# Adding an invalid credential should appear as if user cancelled.
|
||||
with pytest.raises(Cancelled):
|
||||
fido.add_credential(client, CRED1[:-2])
|
||||
fido.add_credential(session, CRED1[:-2])
|
||||
|
||||
# Check that the invalid credential was not added.
|
||||
creds = fido.list_credentials(client)
|
||||
creds = fido.list_credentials(session)
|
||||
assert len(creds) == 1
|
||||
|
||||
# Add valid credential, which has same userId as #2, but different rpId.
|
||||
fido.add_credential(client, CRED3)
|
||||
fido.add_credential(session, CRED3)
|
||||
|
||||
# Check that the credential was added.
|
||||
creds = fido.list_credentials(client)
|
||||
creds = fido.list_credentials(session)
|
||||
assert len(creds) == 2
|
||||
|
||||
# Fill up the credential storage to maximum capacity.
|
||||
for cred in CREDS[: RK_CAPACITY - 2]:
|
||||
fido.add_credential(client, cred)
|
||||
fido.add_credential(session, cred)
|
||||
|
||||
# Adding one more valid credential to full storage should fail.
|
||||
with pytest.raises(TrezorFailure):
|
||||
fido.add_credential(client, CREDS[-1])
|
||||
fido.add_credential(session, CREDS[-1])
|
||||
|
||||
# Removing the index, which is one past the end, should fail.
|
||||
with pytest.raises(TrezorFailure):
|
||||
fido.remove_credential(client, RK_CAPACITY)
|
||||
fido.remove_credential(session, RK_CAPACITY)
|
||||
|
||||
# Remove index 2.
|
||||
fido.remove_credential(client, 2)
|
||||
fido.remove_credential(session, 2)
|
||||
# Adding another valid credential should succeed now.
|
||||
fido.add_credential(client, CREDS[-1])
|
||||
fido.add_credential(session, CREDS[-1])
|
||||
|
@ -17,15 +17,15 @@
|
||||
import pytest
|
||||
|
||||
from trezorlib import fido
|
||||
from trezorlib.debuglink import TrezorClientDebugLink as Client
|
||||
from trezorlib.debuglink import SessionDebugWrapper as Session
|
||||
|
||||
|
||||
@pytest.mark.altcoin
|
||||
def test_u2f_counter(client: Client):
|
||||
assert fido.get_next_counter(client) == 0
|
||||
assert fido.get_next_counter(client) == 1
|
||||
fido.set_counter(client, 111111)
|
||||
assert fido.get_next_counter(client) == 111112
|
||||
assert fido.get_next_counter(client) == 111113
|
||||
fido.set_counter(client, 0)
|
||||
assert fido.get_next_counter(client) == 1
|
||||
def test_u2f_counter(session: Session):
|
||||
assert fido.get_next_counter(session) == 0
|
||||
assert fido.get_next_counter(session) == 1
|
||||
fido.set_counter(session, 111111)
|
||||
assert fido.get_next_counter(session) == 111112
|
||||
assert fido.get_next_counter(session) == 111113
|
||||
fido.set_counter(session, 0)
|
||||
assert fido.get_next_counter(session) == 1
|
||||
|
Loading…
Reference in New Issue
Block a user