Skip to content

Commit

Permalink
Add non-discoverable creds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dainnilsson committed Jan 16, 2025
1 parent d1a46d5 commit c693097
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
10 changes: 10 additions & 0 deletions tests/device/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fido2.hid import CtapHidDevice, list_descriptors, open_connection, open_device
from fido2.cose import CoseKey
from fido2.ctap2 import Ctap2
from fido2.ctap2.pin import ClientPin, PinProtocolV1, PinProtocolV2
from fido2.ctap2.credman import CredentialManagement
Expand Down Expand Up @@ -265,6 +266,15 @@ def info(ctap2):
return ctap2.get_info()


@pytest.fixture(params=[CoseKey.for_alg(alg) for alg in CoseKey.supported_algorithms()])
def algorithm(request, info):
alg_cls = request.param
alg = {"alg": alg_cls.ALGORITHM, "type": "public-key"}
if alg not in info.algorithms:
pytest.skip(f"Algorithm {alg_cls.__name__} not supported")
return alg


@pytest.fixture(params=[PinProtocolV1, PinProtocolV2])
def pin_protocol(request, info):
proto = request.param
Expand Down
30 changes: 30 additions & 0 deletions tests/device/test_credentials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from fido2.server import Fido2Server


def test_make_assert(client, pin_protocol, algorithm):
rp = {"id": "example.com", "name": "Example RP"}
server = Fido2Server(rp)
user = {"id": b"user_id", "name": "A. User"}

create_options, state = server.register_begin(user)

# Create a credential
result = client.make_credential(
{
**create_options["publicKey"],
"pubKeyCredParams": [algorithm],
}
)

auth_data = server.register_complete(state, result)
cred = auth_data.credential_data
assert cred.public_key[3] == algorithm["alg"]
credentials = [cred]

# Get assertion
request_options, state = server.authenticate_begin(credentials)

# Authenticate the credential
result = client.get_assertion(request_options.public_key).get_response(0)
cred_data = server.authenticate_complete(state, credentials, result)
assert cred_data == cred
10 changes: 0 additions & 10 deletions tests/device/test_credman.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from fido2.cose import CoseKey
from fido2.ctap import CtapError
from fido2.ctap2.pin import ClientPin
from fido2.ctap2.credman import CredentialManagement
Expand All @@ -14,15 +13,6 @@ def preconditions(dev_manager):
pytest.skip("CredentialManagement not supported by authenticator")


@pytest.fixture(params=[CoseKey.for_alg(alg) for alg in CoseKey.supported_algorithms()])
def algorithm(request, info):
alg_cls = request.param
alg = {"alg": alg_cls.ALGORITHM, "type": "public-key"}
if alg not in info.algorithms:
pytest.skip(f"Algorithm {alg_cls.__name__} not supported")
return alg


def get_credman(ctap2, pin_protocol, permissions=ClientPin.PERMISSION.CREDENTIAL_MGMT):
token = ClientPin(ctap2, pin_protocol).get_pin_token(TEST_PIN, permissions)
return CredentialManagement(ctap2, pin_protocol, token)
Expand Down

0 comments on commit c693097

Please sign in to comment.