Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Horofic committed Jan 30, 2024
1 parent d809f76 commit 38ae64e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
17 changes: 11 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,35 @@
import pytest


def absolute_path(filename):
def absolute_path(filename: str) -> str:
return os.path.join(os.path.dirname(__file__), filename)


@pytest.fixture
def xp_modified_remote_lnk_file():
def xp_modified_remote_lnk_file() -> Path:
return Path(absolute_path("data/modified_remote.file.xp.lnk"))


@pytest.fixture
def xp_remote_lnk_file():
def xp_remote_lnk_file() -> Path:
return Path(absolute_path("data/remote.file.xp.lnk"))


@pytest.fixture
def xp_remote_lnk_dir():
def xp_remote_lnk_dir() -> Path:
return Path(absolute_path("data/remote.directory.xp.lnk"))


@pytest.fixture
def win7_local_lnk_dir():
def win7_local_lnk_dir() -> Path:
return Path(absolute_path("data/local.directory.seven.lnk"))


@pytest.fixture
def win81_downloads_lnk_dir():
def win81_downloads_lnk_dir() -> Path:
return Path(absolute_path("data/downloads.win81.lnk"))


@pytest.fixture
def vista_idlist_lnk_file() -> Path:
return Path(absolute_path("data/vista.idlist.lnk"))
Binary file added tests/data/vista.idlist.lnk
Binary file not shown.
24 changes: 18 additions & 6 deletions tests/test_lnk.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from pathlib import Path

from dissect.util.ts import uuid1timestamp

from dissect.shellitem.lnk import Lnk, c_lnk


def test_xp_custom_destination_remote_lnk_file(xp_modified_remote_lnk_file):
def test_xp_custom_destination_remote_lnk_file(xp_modified_remote_lnk_file: Path) -> None:
# The first 16 bytes contain the LNK GUID a to simulate a Jumplist CustomDestination file
fh = xp_modified_remote_lnk_file.open("rb")
fh.seek(16)
Expand All @@ -14,7 +16,7 @@ def test_xp_custom_destination_remote_lnk_file(xp_modified_remote_lnk_file):
assert str(lnk_file.clsid) == "00021401-0000-0000-c000-000000000046"


def test_xp_remote_lnk_file(xp_remote_lnk_file):
def test_xp_remote_lnk_file(xp_remote_lnk_file: Path) -> None:
fh = xp_remote_lnk_file.open("rb")
lnk_file = Lnk(fh)

Expand Down Expand Up @@ -68,7 +70,7 @@ def test_xp_remote_lnk_file(xp_remote_lnk_file):
assert uuid1timestamp(tracker_props.file_droid.time).ctime() == "Wed Feb 8 07:52:55 2006"


def test_xp_remote_lnk_dir(xp_remote_lnk_dir):
def test_xp_remote_lnk_dir(xp_remote_lnk_dir: Path) -> None:
fh = xp_remote_lnk_dir.open("rb")
lnk_file = Lnk(fh)

Expand All @@ -81,7 +83,7 @@ def test_xp_remote_lnk_dir(xp_remote_lnk_dir):
idlist = lnk_file.target_idlist.idlist
assert len(idlist.itemid_list) == 7
assert idlist.terminalid == b"\x00\x00"
assert all([entry.itemid_size == len(entry.dumps()) for entry in idlist.itemid_list])
assert all(entry.itemid_size == len(entry.dumps()) for entry in idlist.itemid_list)

assert flags & c_lnk.LINK_FLAGS.has_link_info
link_info = lnk_file.linkinfo.link_info
Expand Down Expand Up @@ -116,7 +118,7 @@ def test_xp_remote_lnk_dir(xp_remote_lnk_dir):
assert uuid1timestamp(tracker_props.file_droid.time).ctime() == "Tue Jul 21 07:31:44 2009"


def test_win7_local_lnk_dir(win7_local_lnk_dir):
def test_win7_local_lnk_dir(win7_local_lnk_dir: Path) -> None:
fh = win7_local_lnk_dir.open("rb")
lnk_file = Lnk(fh)

Expand Down Expand Up @@ -179,7 +181,7 @@ def test_win7_local_lnk_dir(win7_local_lnk_dir):
assert str(property_store_props.format_id) == "b725f130-47ef-101a-a5f1-02608c9eebac"


def test_common_path_suffix(win81_downloads_lnk_dir):
def test_common_path_suffix(win81_downloads_lnk_dir: Path) -> None:
fh = win81_downloads_lnk_dir.open("rb")
downloads = Lnk(fh)

Expand All @@ -190,3 +192,13 @@ def test_common_path_suffix(win81_downloads_lnk_dir):
assert link_info_flags & c_lnk.LINK_INFO_FLAGS.common_network_relative_link_and_pathsuffix == 0
assert link_info.common_path_suffix == b""
assert link_info.common_path_suffix.decode() == ""


def test_vista_and_above_idlist_lnk_props(vista_idlist_lnk_file: Path) -> None:
fh = vista_idlist_lnk_file.open("rb")
lnk_file = Lnk(fh)
vista_props = lnk_file.extradata.extradata["VISTA_AND_ABOVE_IDLIST_PROPS"]

assert vista_props.size == 0x62 # 98
assert vista_props.idlist.itemid_list[0].itemid_size == 0x60 # 96
assert len(vista_props.idlist.itemid_list[0].data) == 0x5E # 94

0 comments on commit 38ae64e

Please sign in to comment.