From 7ef0a1ed84a95bfdb3d367e28ca75c748b5a48c8 Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Fri, 28 Aug 2020 15:03:38 -0700 Subject: [PATCH] improve applicability of some tests --- tests/standard/fido2/test_make_credential.py | 4 +-- tests/standard/fido2/test_resident_key.py | 8 +++-- tests/standard/transport/test_hid.py | 31 +++++++++++++++----- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/tests/standard/fido2/test_make_credential.py b/tests/standard/fido2/test_make_credential.py index bf6abe8..d7e085f 100644 --- a/tests/standard/fido2/test_make_credential.py +++ b/tests/standard/fido2/test_make_credential.py @@ -154,7 +154,7 @@ class TestMakeCredential(object): with pytest.raises(CtapError) as e: device.sendMC(*req.toMC()) - assert e.value.code == CtapError.ERR.MISSING_PARAMETER + assert e.value.code in [CtapError.ERR.MISSING_PARAMETER, CtapError.ERR.UNSUPPORTED_ALGORITHM] def test_bad_type_pubKeyCredParams_alg(self, device, MCRes): req = FidoRequest(MCRes, key_params=[{"alg": "7", "type": "public-key"}]) @@ -213,7 +213,7 @@ class TestMakeCredential(object): with pytest.raises(CtapError) as e: device.sendMC(*req.toMC()) - def test_bad_type_exclude_list_type(self, device, MCRes, GARes): + def test_exclude_list_excluded(self, device, MCRes, GARes): req = FidoRequest(MCRes, exclude_list=GARes.request.allow_list) with pytest.raises(CtapError) as e: diff --git a/tests/standard/fido2/test_resident_key.py b/tests/standard/fido2/test_resident_key.py index e0957a0..4b043cb 100644 --- a/tests/standard/fido2/test_resident_key.py +++ b/tests/standard/fido2/test_resident_key.py @@ -188,11 +188,15 @@ class TestResidentKey(object): @pytest.mark.skipif('trezor' in sys.argv, reason="Trezor does not support get_next_assertion() because it has a display.") @pytest.mark.skipif('solokeys' in sys.argv, reason="Initial SoloKeys model truncates displayName") - def test_rk_maximum_list_capacity_per_rp_nodisplay(self, device, MC_RK_Res): + def test_rk_maximum_list_capacity_per_rp_nodisplay(self, info, device, MC_RK_Res): """ Test maximum returned capacity of the RK for the given RP """ - RK_CAPACITY_PER_RP = 19 + + # Try to determine from get_info, or default to 19. + RK_CAPACITY_PER_RP = info.max_creds_in_list + if not RK_CAPACITY_PER_RP: RK_CAPACITY_PER_RP = 19 + users = [] def get_user(): diff --git a/tests/standard/transport/test_hid.py b/tests/standard/transport/test_hid.py index c1bfd37..cb3371d 100644 --- a/tests/standard/transport/test_hid.py +++ b/tests/standard/transport/test_hid.py @@ -46,15 +46,32 @@ class TestHID(object): r = device.send_data(CTAPHID.WINK, "") def test_cbor_no_payload(self, device): - with pytest.raises(CtapError) as e: - r = device.send_data(CTAPHID.CBOR, "") - assert e.value.code == CtapError.ERR.INVALID_LENGTH + payload = b"\x11\x11\x11\x11\x11\x11\x11\x11" + r = device.send_data(CTAPHID.INIT, payload) + capabilities = r[16] + + + if (capabilities ^ 0x04) != 0: + print('Implements CBOR.') + with pytest.raises(CtapError) as e: + r = device.send_data(CTAPHID.CBOR, "") + assert e.value.code == CtapError.ERR.INVALID_LENGTH + else: + print('CBOR is not implemented.') def test_no_data_in_u2f_msg(self, device): - with pytest.raises(CtapError) as e: - r = device.send_data(CTAPHID.MSG, "") - print(hexlify(r)) - assert e.value.code == CtapError.ERR.INVALID_LENGTH + payload = b"\x11\x11\x11\x11\x11\x11\x11\x11" + r = device.send_data(CTAPHID.INIT, payload) + capabilities = r[16] + + if (capabilities ^ 0x08) == 0: + print("U2F implemented.") + with pytest.raises(CtapError) as e: + r = device.send_data(CTAPHID.MSG, "") + print(hexlify(r)) + assert e.value.code == CtapError.ERR.INVALID_LENGTH + else: + print("U2F not implemented.") def test_invalid_hid_cmd(self, device): r = device.send_data(CTAPHID.INIT, "\x11\x22\x33\x44\x55\x66\x77\x88")