Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ofrak_core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### Changed
- Remove test dependencies that are already in the global `requirements-dev.txt` ([#695](https://github.com/redballoonsecurity/ofrak/pull/695))
- Skip tests requiring root privileges when running as non-root user ([#704](https://github.com/redballoonsecurity/ofrak/pull/704))

### Fixed
- Fix `Resource.get_attributes` docstring to match implementation ([#692](https://github.com/redballoonsecurity/ofrak/pull/692))
Expand Down
3 changes: 3 additions & 0 deletions ofrak_core/tests/components/test_tar_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ async def verify(self, repacked_root_resource: Resource) -> None:
assert self.EXPECTED_DATA == f.read()


@pytest.mark.skipif(
os.geteuid() != 0, reason="Extracting device nodes from testtar.tar requires root"
)
class TestComplexTarWithSpecialFiles(FilesystemPackUnpackVerifyPattern):
"""
Test unpacking and repacking a tar archive containing special file types.
Expand Down
15 changes: 13 additions & 2 deletions ofrak_core/tests/unit/test_ofrak_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from dataclasses import fields

from ofrak.cli.command.gui import GUICommand
from ofrak.component.abstract import ComponentSubprocessError
from ofrak.ofrak_context import OFRAKContext

from .. import components
Expand Down Expand Up @@ -251,7 +252,14 @@ async def all_expected_hashes(ofrak_context: OFRAKContext):
expected_hashes = set()
file_path = os.path.join(os.path.dirname(components.__file__), "assets", filename)
res = await ofrak_context.create_root_resource_from_file(file_path)
await res.unpack()
try:
await res.unpack()
except ComponentSubprocessError:
# testtar.tar contains device nodes requiring root to extract
if filename == "testtar.tar" and os.geteuid() != 0:
all_expected_hashes[filename] = None
continue
raise
for child in await res.get_descendants():
if child.get_data_id() is not None:
data = await child.get_data()
Expand All @@ -272,6 +280,10 @@ def test_unpack(ofrak_cli_parser, capsys, filename, tmpdir, ofrak_context, all_e
- The unpack command generates correct hash values for extracted files
- The unpack command creates an info dump file with proper content
"""
expected_hashes = all_expected_hashes[filename]
if expected_hashes is None:
pytest.skip(f"Unpacking {filename} requires root")

file_path = os.path.join(os.path.dirname(components.__file__), "assets", filename)
ofrak_cli_parser.parse_and_run(["unpack", "-o", str(tmpdir), file_path])

Expand All @@ -284,7 +296,6 @@ def test_unpack(ofrak_cli_parser, capsys, filename, tmpdir, ofrak_context, all_e
path = os.path.join(dirpath, unpacked_file)
with open(path, "rb") as file:
unpacked_hashes.add(hashlib.sha256(file.read()).hexdigest())
expected_hashes = all_expected_hashes[filename]

assert unpacked_hashes == expected_hashes

Expand Down
2 changes: 1 addition & 1 deletion ofrak_core/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "3.4.0rc5"
VERSION = "3.4.0rc6"
Loading