Skip to content

Commit c693097

Browse files
committed
Add non-discoverable creds tests
1 parent d1a46d5 commit c693097

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

tests/device/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from fido2.hid import CtapHidDevice, list_descriptors, open_connection, open_device
2+
from fido2.cose import CoseKey
23
from fido2.ctap2 import Ctap2
34
from fido2.ctap2.pin import ClientPin, PinProtocolV1, PinProtocolV2
45
from fido2.ctap2.credman import CredentialManagement
@@ -265,6 +266,15 @@ def info(ctap2):
265266
return ctap2.get_info()
266267

267268

269+
@pytest.fixture(params=[CoseKey.for_alg(alg) for alg in CoseKey.supported_algorithms()])
270+
def algorithm(request, info):
271+
alg_cls = request.param
272+
alg = {"alg": alg_cls.ALGORITHM, "type": "public-key"}
273+
if alg not in info.algorithms:
274+
pytest.skip(f"Algorithm {alg_cls.__name__} not supported")
275+
return alg
276+
277+
268278
@pytest.fixture(params=[PinProtocolV1, PinProtocolV2])
269279
def pin_protocol(request, info):
270280
proto = request.param

tests/device/test_credentials.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from fido2.server import Fido2Server
2+
3+
4+
def test_make_assert(client, pin_protocol, algorithm):
5+
rp = {"id": "example.com", "name": "Example RP"}
6+
server = Fido2Server(rp)
7+
user = {"id": b"user_id", "name": "A. User"}
8+
9+
create_options, state = server.register_begin(user)
10+
11+
# Create a credential
12+
result = client.make_credential(
13+
{
14+
**create_options["publicKey"],
15+
"pubKeyCredParams": [algorithm],
16+
}
17+
)
18+
19+
auth_data = server.register_complete(state, result)
20+
cred = auth_data.credential_data
21+
assert cred.public_key[3] == algorithm["alg"]
22+
credentials = [cred]
23+
24+
# Get assertion
25+
request_options, state = server.authenticate_begin(credentials)
26+
27+
# Authenticate the credential
28+
result = client.get_assertion(request_options.public_key).get_response(0)
29+
cred_data = server.authenticate_complete(state, credentials, result)
30+
assert cred_data == cred

tests/device/test_credman.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from fido2.cose import CoseKey
21
from fido2.ctap import CtapError
32
from fido2.ctap2.pin import ClientPin
43
from fido2.ctap2.credman import CredentialManagement
@@ -14,15 +13,6 @@ def preconditions(dev_manager):
1413
pytest.skip("CredentialManagement not supported by authenticator")
1514

1615

17-
@pytest.fixture(params=[CoseKey.for_alg(alg) for alg in CoseKey.supported_algorithms()])
18-
def algorithm(request, info):
19-
alg_cls = request.param
20-
alg = {"alg": alg_cls.ALGORITHM, "type": "public-key"}
21-
if alg not in info.algorithms:
22-
pytest.skip(f"Algorithm {alg_cls.__name__} not supported")
23-
return alg
24-
25-
2616
def get_credman(ctap2, pin_protocol, permissions=ClientPin.PERMISSION.CREDENTIAL_MGMT):
2717
token = ClientPin(ctap2, pin_protocol).get_pin_token(TEST_PIN, permissions)
2818
return CredentialManagement(ctap2, pin_protocol, token)

0 commit comments

Comments
 (0)