def test_available_device_display(config_dir, alice): without_labels = AvailableDevice( key_file_path=get_default_key_file(config_dir, alice), organization_id=alice.organization_id, device_id=alice.device_id, human_handle=None, device_label=None, slug=alice.slug, type=DeviceFileType.PASSWORD, ) with_labels = AvailableDevice( key_file_path=get_default_key_file(config_dir, alice), organization_id=alice.organization_id, device_id=alice.device_id, human_handle=alice.human_handle, device_label=alice.device_label, slug=alice.slug, type=DeviceFileType.PASSWORD, ) assert without_labels.device_display == str(alice.device_name) assert without_labels.user_display == str(alice.user_id) assert with_labels.device_display == str(alice.device_label) assert with_labels.user_display == str(alice.human_handle)
def _to_available(device): return AvailableDevice( key_file_path=get_key_file(config_dir, device), organization_id=device.organization_id, device_id=device.device_id, human_handle=device.human_handle, device_label=device.device_label, )
def _to_available(device): return AvailableDevice( key_file_path=get_default_key_file(config_dir, device), organization_id=device.organization_id, device_id=device.device_id, human_handle=device.human_handle, device_label=device.device_label, slug=device.slug, type=DeviceFileType.PASSWORD, )
def test_available_device_display(config_dir, alice): without_labels = AvailableDevice( key_file_path=get_key_file(config_dir, alice), organization_id=alice.organization_id, device_id=alice.device_id, human_handle=None, device_label=None, ) with_labels = AvailableDevice( key_file_path=get_key_file(config_dir, alice), organization_id=alice.organization_id, device_id=alice.device_id, human_handle=alice.human_handle, device_label=alice.device_label, ) assert without_labels.device_display == alice.device_name assert without_labels.user_display == alice.user_id assert with_labels.device_display == alice.device_label assert with_labels.user_display == str(alice.human_handle)
def test_list_devices_support_legacy_file_with_meaningful_name(config_dir): # Legacy path might exceed the 256 characters limit in some cases (see issue #1356) # So we use the `\\?\` workaround: https://stackoverflow.com/a/57502760/2846140 if sys.platform == "win32": config_dir = Path("\\\\?\\" + str(config_dir.resolve())) # Device information user_id = uuid4().hex device_name = uuid4().hex organization_id = "Org" rvk_hash = (uuid4().hex)[:10] device_id = f"{user_id}@{device_name}" slug = f"{rvk_hash}#{organization_id}#{device_id}" human_label = "Billy Mc BillFace" human_email = "*****@*****.**" device_label = "My device" # Craft file data without the user_id, organization_id and slug fields key_file_data = packb({ "type": "password", "salt": b"12345", "ciphertext": b"whatever", "human_handle": (human_email.encode(), human_label.encode()), "device_label": device_label, }) key_file_path = get_devices_dir(config_dir) / slug / f"{slug}.keys" key_file_path.parent.mkdir(parents=True) key_file_path.write_bytes(key_file_data) devices = list_available_devices(config_dir) expected_device = AvailableDevice( key_file_path=key_file_path, organization_id=OrganizationID(organization_id), device_id=DeviceID(device_id), human_handle=HumanHandle(human_email, human_label), device_label=DeviceLabel(device_label), slug=slug, type=DeviceFileType.PASSWORD, ) assert devices == [expected_device] assert get_key_file(config_dir, expected_device) == key_file_path
def test_list_devices_support_legacy_file_without_labels(config_dir): # Craft file data without the labels fields key_file_data = packb({ "type": "password", "salt": b"12345", "ciphertext": b"whatever" }) slug = "9d84fbd57a#Org#Zack@PC1" key_file_path = get_devices_dir(config_dir) / slug / f"{slug}.keys" key_file_path.parent.mkdir(parents=True) key_file_path.write_bytes(key_file_data) devices = list_available_devices(config_dir) expected_device = AvailableDevice( key_file_path=key_file_path, organization_id=OrganizationID("Org"), device_id=DeviceID("Zack@PC1"), human_handle=None, device_label=None, ) assert devices == [expected_device]