From be5d8bc4c13f05496cd2a6267b25b3d0292dbd45 Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Tue, 6 Aug 2019 18:42:51 +0800 Subject: [PATCH] reorg --- tests/__init__.py | 142 ------------------ tests/{fido2/pin => standard}/__init__.py | 0 tests/{ => standard}/connect_test.py | 0 tests/{ => standard}/fido2/__init__.py | 0 .../fido2/pin}/__init__.py | 0 .../{ => standard}/fido2/pin/test_lockout.py | 0 tests/{ => standard}/fido2/pin/test_pin.py | 0 .../{ => standard}/fido2/pin/test_set_pin.py | 0 .../fido2/test_ctap1_interop.py | 0 .../fido2/test_get_assertion.py | 0 tests/{ => standard}/fido2/test_getinfo.py | 0 .../fido2/test_make_credential.py | 0 tests/{ => standard}/fido2/test_reset.py | 0 .../fido2/test_reset_credential.py | 0 .../{ => standard}/fido2/test_resident_key.py | 0 tests/{u2f => standard/transport}/__init__.py | 0 tests/{ => standard}/transport/test_hid.py | 0 tests/standard/u2f/__init__.py | 0 tests/{ => standard}/u2f/test_u2f.py | 0 19 files changed, 142 deletions(-) rename tests/{fido2/pin => standard}/__init__.py (100%) rename tests/{ => standard}/connect_test.py (100%) rename tests/{ => standard}/fido2/__init__.py (100%) rename tests/{transport => standard/fido2/pin}/__init__.py (100%) rename tests/{ => standard}/fido2/pin/test_lockout.py (100%) rename tests/{ => standard}/fido2/pin/test_pin.py (100%) rename tests/{ => standard}/fido2/pin/test_set_pin.py (100%) rename tests/{ => standard}/fido2/test_ctap1_interop.py (100%) rename tests/{ => standard}/fido2/test_get_assertion.py (100%) rename tests/{ => standard}/fido2/test_getinfo.py (100%) rename tests/{ => standard}/fido2/test_make_credential.py (100%) rename tests/{ => standard}/fido2/test_reset.py (100%) rename tests/{ => standard}/fido2/test_reset_credential.py (100%) rename tests/{ => standard}/fido2/test_resident_key.py (100%) rename tests/{u2f => standard/transport}/__init__.py (100%) rename tests/{ => standard}/transport/test_hid.py (100%) create mode 100644 tests/standard/u2f/__init__.py rename tests/{ => standard}/u2f/test_u2f.py (100%) diff --git a/tests/__init__.py b/tests/__init__.py index 04eb6d0..e69de29 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,142 +0,0 @@ -import struct, time - -import pytest - -from fido2.hid import CtapHidDevice -from fido2.client import Fido2Client -from fido2.utils import Timeout - -from solo.fido2 import force_udp_backend - -__device = None - -origin = "https://solokeys.com" - - -class Packet(object): - def __init__(self, data): - self.data = data - - def ToWireFormat(self,): - return self.data - - @staticmethod - def FromWireFormat(pkt_size, data): - return Packet(data) - - -def cid(): - return __device._dev.cid - - -def set_cid(cid): - if not isinstance(cid, (bytes, bytearray)): - cid = struct.pack("%dB" % len(cid), *[ord(x) for x in cid]) - __device._dev.cid = cid - - -def recv_raw(): - with Timeout(1.0): - cmd, payload = __device._dev.InternalRecv() - return cmd, payload - - -def send_data(cmd, data): - if not isinstance(data, bytes): - data = struct.pack("%dB" % len(data), *[ord(x) for x in data]) - with Timeout(1.0) as event: - return __device.call(cmd, data, event) - - -def send_raw(data, cid=None): - if cid is None: - cid = __device._dev.cid - elif not isinstance(cid, bytes): - cid = struct.pack("%dB" % len(cid), *[ord(x) for x in cid]) - if not isinstance(data, bytes): - data = struct.pack("%dB" % len(data), *[ord(x) for x in data]) - data = cid + data - l = len(data) - if l != 64: - pad = "\x00" * (64 - l) - pad = struct.pack("%dB" % len(pad), *[ord(x) for x in pad]) - data = data + pad - data = list(data) - assert len(data) == 64 - __device._dev.InternalSendPacket(Packet(data)) - - -def send_magic_reboot(): - """ - For use in simulation and testing. Random bytes that authentictor should detect - and then restart itself. - """ - magic_cmd = ( - b"\xac\x10\x52\xca\x95\xe5\x69\xde\x69\xe0\x2e\xbf" - + b"\xf3\x33\x48\x5f\x13\xf9\xb2\xda\x34\xc5\xa8\xa3" - + b"\x40\x52\x66\x97\xa9\xab\x2e\x0b\x39\x4d\x8d\x04" - + b"\x97\x3c\x13\x40\x05\xbe\x1a\x01\x40\xbf\xf6\x04" - + b"\x5b\xb2\x6e\xb7\x7a\x73\xea\xa4\x78\x13\xf6\xb4" - + b"\x9a\x72\x50\xdc" - ) - __device.dev._dev.InternalSendPacket(Packet(magic_cmd)) - - -def reboot(): - if is_simulation: - print("Sending restart command...") - self.send_magic_reboot() - Tester.delay(0.25) - else: - print("Please reboot authentictor and hit enter") - input() - self.find_device(self.nfc_interface_only) - - -def find_device(nfcInterfaceOnly=False): - print(is_simulation) - if is_simulation: - print("FORCE UDP") - force_udp_backend() - dev = None - nfcInterfaceOnly - if not nfcInterfaceOnly: - print("--- HID ---") - print(list(CtapHidDevice.list_devices())) - dev = next(CtapHidDevice.list_devices(), None) - - if not dev: - from fido2.pcsc import CtapPcscDevice - - print("--- NFC ---") - print(list(CtapPcscDevice.list_devices())) - dev = next(CtapPcscDevice.list_devices(), None) - - if not dev: - raise RuntimeError("No FIDO device found") - - return Fido2Client(dev, origin) - - -def set_device(dev): - __device = dev - - -def _get_device(refresh=False): - - print(0) - dev = find_device() - print(1, dev) - yield dev - - while True: - if refresh: - print("REFRESH") - dev = find_device() - print(2, dev) - yield dev - - -def get_device(*args): - time.sleep(0.5) - return next(_get_device(*args)) diff --git a/tests/fido2/pin/__init__.py b/tests/standard/__init__.py similarity index 100% rename from tests/fido2/pin/__init__.py rename to tests/standard/__init__.py diff --git a/tests/connect_test.py b/tests/standard/connect_test.py similarity index 100% rename from tests/connect_test.py rename to tests/standard/connect_test.py diff --git a/tests/fido2/__init__.py b/tests/standard/fido2/__init__.py similarity index 100% rename from tests/fido2/__init__.py rename to tests/standard/fido2/__init__.py diff --git a/tests/transport/__init__.py b/tests/standard/fido2/pin/__init__.py similarity index 100% rename from tests/transport/__init__.py rename to tests/standard/fido2/pin/__init__.py diff --git a/tests/fido2/pin/test_lockout.py b/tests/standard/fido2/pin/test_lockout.py similarity index 100% rename from tests/fido2/pin/test_lockout.py rename to tests/standard/fido2/pin/test_lockout.py diff --git a/tests/fido2/pin/test_pin.py b/tests/standard/fido2/pin/test_pin.py similarity index 100% rename from tests/fido2/pin/test_pin.py rename to tests/standard/fido2/pin/test_pin.py diff --git a/tests/fido2/pin/test_set_pin.py b/tests/standard/fido2/pin/test_set_pin.py similarity index 100% rename from tests/fido2/pin/test_set_pin.py rename to tests/standard/fido2/pin/test_set_pin.py diff --git a/tests/fido2/test_ctap1_interop.py b/tests/standard/fido2/test_ctap1_interop.py similarity index 100% rename from tests/fido2/test_ctap1_interop.py rename to tests/standard/fido2/test_ctap1_interop.py diff --git a/tests/fido2/test_get_assertion.py b/tests/standard/fido2/test_get_assertion.py similarity index 100% rename from tests/fido2/test_get_assertion.py rename to tests/standard/fido2/test_get_assertion.py diff --git a/tests/fido2/test_getinfo.py b/tests/standard/fido2/test_getinfo.py similarity index 100% rename from tests/fido2/test_getinfo.py rename to tests/standard/fido2/test_getinfo.py diff --git a/tests/fido2/test_make_credential.py b/tests/standard/fido2/test_make_credential.py similarity index 100% rename from tests/fido2/test_make_credential.py rename to tests/standard/fido2/test_make_credential.py diff --git a/tests/fido2/test_reset.py b/tests/standard/fido2/test_reset.py similarity index 100% rename from tests/fido2/test_reset.py rename to tests/standard/fido2/test_reset.py diff --git a/tests/fido2/test_reset_credential.py b/tests/standard/fido2/test_reset_credential.py similarity index 100% rename from tests/fido2/test_reset_credential.py rename to tests/standard/fido2/test_reset_credential.py diff --git a/tests/fido2/test_resident_key.py b/tests/standard/fido2/test_resident_key.py similarity index 100% rename from tests/fido2/test_resident_key.py rename to tests/standard/fido2/test_resident_key.py diff --git a/tests/u2f/__init__.py b/tests/standard/transport/__init__.py similarity index 100% rename from tests/u2f/__init__.py rename to tests/standard/transport/__init__.py diff --git a/tests/transport/test_hid.py b/tests/standard/transport/test_hid.py similarity index 100% rename from tests/transport/test_hid.py rename to tests/standard/transport/test_hid.py diff --git a/tests/standard/u2f/__init__.py b/tests/standard/u2f/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/u2f/test_u2f.py b/tests/standard/u2f/test_u2f.py similarity index 100% rename from tests/u2f/test_u2f.py rename to tests/standard/u2f/test_u2f.py